Hi,

I took this right off the curl.haxx.se website.

This is the exact page, with nothing changed:

An example of using curl in php to log into on one page and then get another page passing all cookies from the first page along with you.
<?php
/
This script is an example of using curl in php to log into on one page and
then get another page passing all cookies from the first page along with you.
If this script was a bit more advanced it might trick the server into
thinking its netscape and even pass a fake referer, yo look like it surfed
from a local page.
/

$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookieFileName");
curl_setopt($ch, CURLOPT_URL,"http://www.myterminal.com/checkpwd.asp");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "UserID=username&password=passwd");

ob_start(); // prevent any output
curl_exec ($ch); // execute the curl command
ob_end_clean(); // stop preventing output

curl_close ($ch);
unset($ch);
}

setcookies();

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/cookieFileName");
curl_setopt($ch, CURLOPT_URL,"http://www.myterminal.com/list.asp");

$buf2 = curl_exec ($ch);

curl_close ($ch);

echo "<PRE>".htmlentities($buf2);
?>

I of course changed the URL's and postfields that I needed, and the cookie location, but that's ALL I changed.

I'm getting the following error:

Fatal error: Call to undefined function: setcookies()

When taking the function out of the code of course I'm getting an error on the page that I'm trying to get "You must have cookies enabled in your browser"

I've been trying to figure this one out for weeks now, but I'm just feeling hopeless about it now.

Any ideas? 😕

    You're missing something here....
    right after unset, you have a closing bracket

    unset($ch); 
    }

    Though, it appears to not be closing anything. My guess is that the first line in that is missing, and it probably looked like this:

    function setcookies() {

      Yes, I thought that too, but that is exactly how it was written on the site. I did try it as function setcookies()

      but still get the same error. The cookies just aren't being passed back and I can't figure out why. Any ideas?

      How many posts do you have to make before you're not a junior member anymore? :rolleyes:

        Well, you're missing the setcookies function, yet you're calling it. That's your whole entire problem.

        I think 50 to become "Member", 100 for "Senior Member", but you can change it in your CP anyway

          Write a Reply...