我的问题与服务器Javascript windows.location返回的php文件中的curl卷曲有关,我无法成功绕过该行为
实际上,我已经编写了一个脚本,该脚本使用用户身份验证表单连接到网站。该脚本在其全局性方面运行完美:
问题:我总是通过服务器答案中的javascript函数通过windows.location = XXXX进行重定向
有关信息,我使用WampServer版本2.5 / PHP 5.5.12
我的脚本通过一个带有以下内容的网络浏览器调用:http://localhost/glpiv2/rechercheDerniersSuivisV2.php
function createCookie (){
global $proxy;
global $proxyauth;
global $cookies_file;
global $timeout;
$url='https://xxx.xxxx.xxx.xxx/glpi/index.php';
$ch = curl_init();
// Proxy Authentication, keep cool with security
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, true);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_POST , false);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch,CURLOPT_HTTPHEADER,array('User-Agent: Mozilla/6.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko','DNT: 1','Connection: Keep-Alive'));
// => WRITE A NEW COOKIE FILE
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies_file);
// => ESTABLISH A NEW SESSION
curl_setopt ($ch, CURLOPT_COOKIESESSION, true);
$file_contents = curl_exec($ch);
// If Error
if(curl_errno($ch)){
// Le message d'erreur correspondant est affiché
echo "ERREUR curl_exec : ".curl_error($ch);
}
curl_close($ch);
}
第一个请求的服务器响应头
Server: Apache
Set-Cookie: PHPSESSID=3c5939450c6811b8df981f83c9539f64; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, precheck=0
Pragma: no-cache
Content-Length: 253
Connection: close
Content-Type: text/html
正在使用PHPSESSID创建Cookie:确定
function authenticateSession(){
echo "Lancement de authenticateSession";
global $proxy;
global $proxyauth;
global $cookies_file;
global $timeout;
global $authenticationGLPIPost;
$url='https://xxx.xxx.xxx.xxx/glpi/login.php';
$ch1 = curl_init();
// Proxy SSL and other stuff
curl_setopt($ch1, CURLOPT_HTTPPROXYTUNNEL, TRUE);
curl_setopt($ch1, CURLOPT_PROXY, $proxy);
curl_setopt($ch1, CURLOPT_PROXYUSERPWD, $proxyauth);
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch1, CURLOPT_SSL_VERIFYHOST, 0);
// Post preparation
curl_setopt ($ch1, CURLOPT_URL, $url);
curl_setopt($ch1, CURLOPT_HEADER, FALSE);
curl_setopt($ch1, CURLOPT_POST , TRUE);
// POST DATA with variable containing user / password
curl_setopt($ch1, CURLOPT_POSTFIELDS, $authenticationGLPIPost);
curl_setopt($ch1, CURLOPT_COOKIEFILE, $cookies_file);
curl_setopt ($ch1, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch1);
curl_close($ch1);
}
第二个请求的服务器响应标头
Server: Apache
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, precheck=0
Pragma: no-cache
Content-Length: 269
Connection: close
Content-Type: text/html
<script language=javascript>
NomNav = navigator.appName;
if (NomNav=='Konqueror'){
window.location="/glpi/front/central.php?tokonq=fsrb7s";
} else {
window.location="/glpi/front/central.php";
}
</script>
=>响应中的javascript windows.location重定向问题,将我重定向到http://localhost/glpi/front/central.php
服务器响应将显示在Web浏览器中。
我怀疑Web浏览器确实执行了返回的Javascript,并重定向了我。我使用代理拦截器验证并更改了服务器响应,即我抑制Javascript bloc时的意思,或者如果我更改了windows.location的参数,则重定向会修改其行为。
我尝试不将这些选项中的每一个都成功重定向,但是没有一个有效
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt ($ch, CURLOPT_MAXREDIRS, 0);
这意味着我第一次运行该脚本,这两个函数被称为“我”,总是在身份验证成功的网站页面上重定向,这表示相对路径/glpi/front/central.php。
当我设置好一切时,一切可能工作得很好
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句