简体   繁体   中英

PHP CURL Redirects

I have a web application that I enter an IP Address, username and password into, I then click submit. 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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