Здрасти. Вот такое дело. Хочу авторизироваться на сайте. Сайт выглядит так: | Код | <?php session_start(); // Loggin testen if(isset($_POST['name']) && isset($_POST['pass'])){ if($_POST['name'] == 'testName' && $_POST['pass'] == 'testPass'){ $_SESSION['login'] = true; }else{ echo "<b>Name or Password invalid</b><br>"; } } // Logout testen if(isset($_POST['logout'])){ $_SESSION['login'] = false; } // Andere actionen if(isset($_SESSION['login']) && $_SESSION['login'] == true){ // Send if(isset($_POST['send'])){ echo "<b><h1>SEND</h1></b>"; } }
if(isset($_SESSION['login']) && $_SESSION['login'] == true){ echo "<b>willkommen</b><br>"; echo "eingeloggt<br> <form action='schnittstelle.php' method='post'> <input name='logout' type='submit' value='ausloggen'/> </form> "; }else{ echo "Bitte einloggen<br> <form action='schnittstelle.php' method='post'> <input name='name' type='text'/><br> <input name='pass' type='password'/><br> <input name='login' type='submit' value='einloggen'/> </form> "; } echo "<br> <form action='schnittstelle.php' method='post'> <input name='send' type='submit' value='send'/> </form> "; ?> |
Смысал таков, что после авторизации кнопка "SEND" наченает работать. Иначи ничего не происходит. Вот так авторизируюсь. | Код | import java.io.BufferedReader; import java.io.InputStreamReader;
import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.http.HttpStatus; import org.apache.http.client.methods.HttpPost;
public class Start {
public static void main(String args[]) { try { HttpClient client = new HttpClient(); client.getParams().setParameter("http.useragent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.A.B.C Safari/525.13");
PostMethod method = new PostMethod( "http://127.0.0.1/MySQLSchnitt/schnittstelle.php"); method.addParameter("name", "testName"); method.addParameter("pass", "testPass"); BufferedReader br = null; try {
int returnCode = client.executeMethod(method);
if (returnCode == HttpStatus.SC_NOT_IMPLEMENTED) { System.err .println("The Post method is not implemented by this URI"); // still consume the response body method.getResponseBodyAsString(); } else { br = new BufferedReader(new InputStreamReader( method.getResponseBodyAsStream())); String readLine; while (((readLine = br.readLine()) != null)) { System.out.println(readLine); } /* // Header auslesen Header[] headers = method.getResponseHeaders(); for (int i = 0; i < headers.length; i++){ System.out.println(headers[i]); } */ Header header = method.getResponseHeader("Set-Cookie"); String sessionID = (header.getValue()).replace("PHPSESSID=", "").replace("; path=/", "").trim(); method.releaseConnection(); // Send second POST HttpPost send = new HttpPost( "http://127.0.0.1/MySQLSchnitt/schnittstelle.php"); send.setHeader("Set-Cookie", "PHPSESSID=" + sessionID ); send.setHeader("send", "send"); returnCode = client.executeMethod(method);
br = new BufferedReader(new InputStreamReader( method.getResponseBodyAsStream())); while (((readLine = br.readLine()) != null)) { System.out.println(readLine); } } } catch (Exception e) { System.err.println(e); } finally { method.releaseConnection(); if (br != null) try { br.close(); } catch (Exception fe) { } } } catch (Exception e) { e.printStackTrace(); } } }
|
Прблема в том, что авторизация якобы проходит, вижу приветствие, а вот отсылка метода SEND один фиг не реагирует. Как будьто сессия теряется! Как мне быть, вчём ошибка?
|