Today, the first day to learn to use PHP, is to implement a remote login in PHP, a ASPX page, that is, PHP login password passed through the user name, directly to the ASPX interface login. The ASPX interface is also written by myself, so logic is well controlled. I'm a Java programmer, C # and PHP are all halfway decent for me, dealing with writing.
Because Java is by httpclient ready-made jar package, so Baidu PHP httpclient, sure enough to find one.
The official address of the download is: http://scripts.incutio.com/httpclient/index.php
Download the compressed package, extract a file HttpClient.class.php after decompression. Introduced into the project, write a test page to invoke. The official example is a lot of get, I want to use a post to obtain the cookie, in fact, the service is written by themselves, get is also the line, but originally planned to use post, on the post bar.
Read the HttpClient.class.php this file, although PHP syntax is basically Greek, but guess to come.
<span style= "FONT-SIZE:14PX;" >require_once (' HttpClient.class.php ');
$params = Array (' name ' => ' xxx ', ' password ' => ' 123 ');
$client = new HttpClient (' 172.18.8.23 ', ' 8888 ');
$client->setdebug (TRUE);//Open debug mode
$path = "/autologin.aspx";
if ($client->post ($path, $params)) {
Print_r ($client->getheaders ());
echo "<----------1----------->";
Print_r ($client->getcookies ());
echo "<--------2------------>";
Print_r ($client->getstatus ());
echo "<---------3----------->";
Print_r ($client->getcontent ());
echo "<---------4----------->";
}
Else
echo ' false ';</span>
After the page is executed, the rest can be returned, and the name of the header that is printed is seen in the cookie set, but the array of cookies is always empty and why.
Then look at the HttpClient.class.php code, found that there are the following statements
This cookie_host, the entire file is not set up an empty string, so the array is not worth it. Delete this condition, in execution, you can successfully get the cookie.
And then through the Setcookie to get the cookie set into the access page is already automatic login. Don't forget to set domain and path when setcookie.