Get page content that required authentication in PHP

前端 未结 1 1534
情歌与酒
情歌与酒 2021-01-29 07:45

I want to get the content of page which required authentication (username and password ) , i can only access this page using valid username and password , i want to access this

1条回答
  •  温柔的废话
    2021-01-29 08:15

    Try this:

    //CHANGE THIS
    $username='YOUR_USERNAME';
    $password='YOUR_PASSWORD';
    $location='http://YOUR_ADDRESS/YOUR_FILE.php';
    
    
    $ch = curl_init ();
    curl_setopt($ch,CURLOPT_URL,$location);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch,CURLOPT_USERPWD,"$username:$password");
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    
    $result = curl_exec ($ch); 
    

    0 讨论(0)
提交回复
热议问题