Jump to content

cURL problems


jjfletch

Recommended Posts

Basically, there is a secured site, which I can log into and then add data via a form once I'm logged in.  I can pass the login information in the URL, and I can get it to work if, for example, I type the address into my browser bar, like so:

    [code=php:0]https://my.example.com/authentication.php?user=Username&pass=PW&destination=https://someurl.example.com/Something
[/code]
This will bring me to the page I want to post form data to.  Which is great, except that if I use this url in my code, it doesn't work.  It just brings me back to the initial login page.  I should also say that if I use:

[code=php:0]    header("Location: https://my.example.com/authentication.php?user=Username&pass=PW&destination=https://someurl.example.com/Something");
[/code]
I will be brought to the form that I want to post data to.  The problem is that I don't want to actually redirect to the page, I just want to get to the form that I need to post information to.

If I attempt to call this URL in my code, it doesn't work.  There are multiple redirects that occur if I type it in the address bar, and I've used FOLLOWLOCATION, 1, but that doesn't seem to help. 

The latest iteration of code attempts to request the page that sets the cookies, and then make subsequent requests that include the cookies, but it still winds up kicking me back to the first page.

[code=php:0]
$cookie_jar = tempnam('/tmp','cookie');

$c = curl_init('https://my.example.com/authentication.php?user=Username&pass=PW');
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($c, CURLOPT_COOKIEJAR, $cookie_jar);
$page = curl_exec($c);
curl_close($c);


$c = curl_init('https://someurl.example.com/Something');
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_POSTFIELDS, 'field=value');
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_COOKIEFILE, $cookie_jar);
$page = curl_exec($c);
curl_close($c);
[/code]

Can anyone help?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.