-
Function write_cookie ($ cookie, $ db)
- {
- $ Fp = fopen ('/tmp/cookie.txt', 'w ');
- Fwrite ($ fp, $ cookie );
- Fclose ($ fp );
- }
-
Function get_cookie ($ db)
- {
-
$ Handle = @ fopen ("/tmp/cookie.txt", "r ");
- If ($ handle ){
- While ($ buffer = fgets ($ handle, 4096 ))! = False ){
- $ Cookie = trim ($ buffer );
- }
- Fclose ($ handle );
- }
-
Return $ cookie;
- }
-
Function openhttp ($ url, $ post = ", $ cookie =", $ agent = ", $ referfer =", $ origin = "", $ host = "", $ content_type = "", $ is_header = 1 ){
- $ Ch = curl_init ();
- Curl_setopt ($ ch, CURLOPT_URL, $ url );
-
$ Header = array ();
- If (! Empty ($ host )){
- $ Header [] = "Host: zzip.ip518.com: 900 ″;
- }
-
If (! Empty ($ origin )){
- $ Header [] = "Origin: http://zzip.ip518.com: 900 ″;
- }
- If (! Empty ($ content_type )){
- $ Header [] = "Content-Type: application/x-www-form-urlencoded ";
- }
-
If (count ($ header )){
- Curl_setopt ($ ch, CURLOPT_HTTPHEADER, $ header );
- }
-
If (! Empty ($ cookie) curl_setopt ($ ch, CURLOPT_COOKIE, $ cookie );
- // Curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 1 );
- If (! Empty ($ referfer) curl_setopt ($ ch, CURLOPT_REFERER, $ referfer );
- Curl_setopt ($ ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31 ″);
- If (! Empty ($ post) curl_setopt ($ ch, CURLOPT_POST, 1 );
- Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
- If (! Empty ($ post) curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post );
- If ($ is_header) curl_setopt ($ ch, CURLOPT_HEADER, 1 );
-
$ Return = curl_exec ($ ch );
- Curl_close ($ ch );
- Return $ return;
- }
-
Function login ($ username, $ password, $ login_url = "http://zzip.ip518.com: 900/login. asp ")
- {
- $ Content = ";
- $ Cookies = ";
- $ Content = openhttp ("http://zzip.ip518.com: 900/login. asp", "name = $ username & pass = $ password & enter = ");
- $ Cookies = get_items ($ content, array ("Set-Cookie:"), array (";");
-
$ Cookie = implode (";", $ cookies );
- Write_cookie ($ cookie );
-
Return $ cookie;
- }
-
Login ("account", "password ");
Note: after successful logon, the cookie information is written to the/tmp/cookie.txt file. The next time you directly read this file, you can perform operations on this cookie file to log on.
>>> More php simulated logon articles. topic links: php simulated logon php curl simulated logon tutorials |