-
-
class CURL - {
- var $cookie_file; //Set the cookie file saving path and file name
- var $loginurl; //Login address
- var $actionstr; / /Login parameters
- function __construct()
- {
- $this->cookie_file=tempnam("./TEMP","COOKIedsdsdsdsdsdwerwdszx454.txt");
- }
function vlogin()
- { //Simulated login by bbs.it-home.org
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL,$this->loginurl);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);// Whether to display data 0 means displaying 1 or not displaying
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $this->actionstr);
- curl_setopt($ch,CURLOPT_COOKIEJAR,$this-> cookie_file);
- $data = curl_exec($ch);
- curl_close($ch);
- }
function gethtml($url)
- { //Get web page content php simulated login
- $ curl = curl_init(); // Start a CURL session
- curl_setopt($curl, CURLOPT_URL, $url); // The address to be accessed
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // Check the source of the authentication certificate
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); // Check whether the SSL encryption algorithm exists from the certificate
- curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // Simulate the browser used by the user
- curl_setopt($ curl, CURLOPT_FOLLOWLOCATION, 1); // Use automatic redirect
- curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // Automatically set Referer
- curl_setopt($curl, CURLOPT_HTTPGET, 1); // Send a regular Post request
- curl_setopt ($curl, CURLOPT_COOKIEFILE, $this->cookie_file); // Read the cookie information stored above
- curl_setopt($curl, CURLOPT_TIMEOUT, 30); // Set timeout limit to prevent infinite loop
- curl_setopt($curl, CURLOPT_HEADER , 0); // Display the returned Header area content
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // The obtained information is returned in the form of a file stream
- $tmpInfo = curl_exec($curl); // Execute the operation
- if (curl_errno($curl)) {
- echo 'Errno'.curl_error($curl);
- }
- curl_close($curl); // Close CURL session
- return $tmpInfo; // Return data
-
- }
- }
- $ host="http://192.168.0.2";
- $mycurl=new CURL();
- $mycurl->actionstr="user_name=111&uspassword=111";
- $mycurl->loginurl=$host."/ admin/login.php";
- $mycurl->vlogin();//Log in
- $htmlcontent=$mycurl->gethtml($host."/user.php?id=123");//Get this The content of the page
- echo $htmlcontent;//Display the content of this page
- //Successfully obtained
-
Copy code
>>> More php simulation login articles, topic link: php simulation Log in to php curl simulated login tutorial
|