简体   繁体   English

PHP CURL重定向

[英]PHP CURL Redirects

I have a web application that I enter an IP Address, username and password into, I then click submit. 我有一个Web应用程序,我在其中输入了IP地址,用户名和密码,然后单击“提交”。 The page submits this data and redirects to a done page. 该页面提交此数据并重定向到完成页面。

The done page finalises the update. 完成页面完成更新。

I have to login to access this page and my issue seems to be when I get redirected to the done page my login credentials are not being passed across. 我必须登录才能访问此页面,我的问题似乎是当我重定向到完成的页面时,我的登录凭据没有被传递出去。

This is the code I'm using : 这是我正在使用的代码:

$ch = curl_init();
$url = "http://127.0.0.1/test/test.cgi?ip=127.0.0.1&user=USERNAME&password=PASSWORD&submit=Update";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, "$LOGIN:$PASSWORD");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, 1);
$result=curl_exec($ch);
var_dump($result);

Can anyone advise if I'm missing something or why this may not work ? 谁能告诉我我是否缺少某些东西,或者为什么这可能行不通?

Thanks 谢谢

This works for me: 这对我有用:

<?php
$login = 'login';
$password = 'password';
$url = 'http://your.url';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$login:$password");
$result = curl_exec($ch);
curl_close($ch);  
echo($result);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM