-
-
- !extension_loaded('curl') && die('the curl extension is not loaded.');
-
- $baseurl = 'http://127.0.0.1';//Root address
- $login_url = $baseurl .'/login.php?act=login'; //Login page address
- $get_url = $baseurl .'/index.php'; //Page that needs to be collected
-
- $post_fields = array( );
-
- //The following two items need to be modified
- $post_fields['name'] = 'admin';
- $post_fields['pass'] = '123456';
-
- //Get the form formhash
- $ch = curl_init( $login_url);
- curl_setopt($ch, curlopt_header, 0);
- curl_setopt($ch, curlopt_returntransfer, 1);
- $contents = curl_exec($ch);
- curl_close($ch);
-
- //post data, Get cookies
- $cookie_file = dirname(__file__) . '/cookie.txt';
- $ch = curl_init($login_url);
- curl_setopt($ch, curlopt_header, 0);
- curl_setopt($ch, curlopt_returntransfer, 1);
- curl_setopt($ch, curlopt_post, 1);
- curl_setopt($ch, curlopt_postfields, $post_fields);
- curl_setopt($ch, curlopt_cookiejar, $cookie_file);
- curl_exec($ch);
- curl_close($ch);
-
- //The content of the page can only be viewed after logging in using the cookie obtained above
- $ch = curl_init($get_url);
- curl_setopt($ch, curlopt_header, 0);
- curl_setopt($ch, curlopt_returntransfer, 0);
- curl_setopt( $ch, curlopt_cookiefile, $cookie_file);
- $mycontents = curl_exec($ch);
- curl_close($ch);
-
- var_dump($mycontents);
Copy code
|