1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

cURL problems

Discussion in 'PHP' started by jjfletch, Oct 11, 2006.

  1. #1
    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:

    https://my.example.com/authentication.php?user=Username&pass=PW&destination=https://someurl.example.com/Something
    
    Code (markup):
    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:

        header("Location: https://my.example.com/authentication.php?user=Username&pass=PW&destination=https://someurl.example.com/Something");
    
    Code (markup):
    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.

    
    $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 (markup):
    Can anyone help?
     
    jjfletch, Oct 11, 2006 IP