Hey there, I'm trying to execute a login to http://www.nitto1320.com/community/usedcarlot.asp

before running file_get_contents on the page so that I'll get the car list instead of the login page, thus rendering my script useless.

I was reading the manual on curl and came across a suggested way to connect. It seems to work however my session doesn't seem to be alive when the script gets to the file_get_contents part.

Just wondering if anyone can suggest a way to resolve this or another method to post the login and keep the session alive so i can run the file_get_contents on the page?

This is what i've got so far ~

http://zerovektor.com/pastebin/pastebin.php?show=109

    if you use curl, be sure to use the CURLOPT_COOKIEFILE and CURLOPT_COOKIEJAR options so the cookie data is stored across multiple sessions.

    edit...
    i just looked at the code you have. file_get_contents wont work in conjunction with curl (at least the previous curl cookies wont be used), so you will have to use multiple curl_exec's for all the requests you want to make in order to keep the cookie data.

      Hey mate i updated the script with the suggestion you made, also i updated the cookie location to absolute rather than relative and now the cookie.txt file is actually populated with a bit of data.

      http://zerovektor.com/pastebin/pastebin.php?show=113

      The latter part of my script still isn't bringing up any data. I'm not sure if i did the cookiefile setting right though ~ curl_setopt ($ch, CURLOPT_COOKIEFILE, 1);

      edit: just changed it to: curl_setopt ($ch, CURLOPT_COOKIEFILE, 'C:\xampp\htdocs\nittotest\cookie.txt');

      still not sure if it's correct :S

        curl_setopt ($ch, CURLOPT_COOKIEFILE, 'C:\xampp\htdocs\nittotest\cookie.txt');
        should be like
        curl_setopt ($ch, CURLOPT_COOKIEFILE, 'C:\xampp\htdocs\nittotest\cookie.txt');

        since the \ is the escape character it will mess up the path.

        i think you will want to do the post to login, then immediately after, a get to grab the page with the car list.

          theres no way to tell file_get_contents to use cookies, so you will have to use curl for both requests.

            Ok i've updated it again so now the preg_match_all is running off the $store curl

            http://zerovektor.com/pastebin/pastebin.php?show=122

            Just not getting any results in the second part of the script now. Have done var_dump on $store and it does have the page stored but it just isn't coming up in the second part :/

              Write a Reply...