Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP访问(非公共)Google站点页面_Php_Authentication_Google Sites - Fatal编程技术网

使用PHP访问(非公共)Google站点页面

使用PHP访问(非公共)Google站点页面,php,authentication,google-sites,Php,Authentication,Google Sites,我试图阅读一个非公开的谷歌网站页面的内容。我编写了php脚本来读取一个公共的Google站点页面,因此它使用了php的file_get_content() 有没有办法登录php脚本,使其能够访问非公开的Google站点页面?如果您想访问需要某种帖子、会话或其他内容的页面,我建议您使用CURL而不是file\u get\u contents。你可以在网上了解更多 如果它对谷歌的非公开页面有效,我不确定。不过,这可能会变成一个巨大的挑战:-)找到了一些做类似事情的旧代码。你应该开始了 /* Prep

我试图阅读一个非公开的谷歌网站页面的内容。我编写了php脚本来读取一个公共的Google站点页面,因此它使用了php的file_get_content()


有没有办法登录php脚本,使其能够访问非公开的Google站点页面?

如果您想访问需要某种帖子、会话或其他内容的页面,我建议您使用
CURL
而不是file\u get\u contents。你可以在网上了解更多


如果它对谷歌的非公开页面有效,我不确定。不过,这可能会变成一个巨大的挑战:-)

找到了一些做类似事情的旧代码。你应该开始了

/* Prepare cURL */
$ch = curl_init();  

// set these according to the login form
$login_query = http_build_query(
                    array('username'=> 'username',
                        'password' => 'your_password',
                        'login' => 'log in'));

/* Set options */
curl_setopt($ch, CURLOPT_URL, 'www.yourpage.com');
curl_setopt($ch, CURLOPT_REFERER, 'www.yourpage.com'); //set this to whatever the normal login does
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3'); //set to something resonable
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies/cookie.txt'); // make sure directory is writable
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies/cookie.txt');
curl_setopt($ch, CURLOPT_POSTFIELDS, $login_query);
curl_setopt($ch, CURLOPT_POST, 1);

$urlcontent = utf8_encode(curl_exec($ch));
$curl_info = curl_getinfo($ch);

// at this point you are logged in... get your page

/* Initiate cURL request */
curl_setopt($ch, CURLOPT_URL, 'www.yourpage.com/what-you-want');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3');
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_REFERER, 'www.yourpage.com');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies/cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies/cookie.txt');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

/* Send cURL request */
$result_data = utf8_encode(curl_exec($ch));
$curl_info = curl_getinfo($ch);

/* Close cURL */
curl_close($ch);

/* Handle result if any */
if ($this->curl_info['http_code'] == 200)
{
    // at this point your page is in $result_data
}

您可以使用cURL发布登录凭据,然后从cURL结果中获得所需的页面