On Fri, Apr 17, 2009 at 7:58 AM, David <quick.webmaster@xxxxxxxxx> wrote: > On Fri, Apr 17, 2009 at 8:55 PM, Andrew Ballard <aballard@xxxxxxxxx> wrote: >> >> On Fri, Apr 17, 2009 at 12:41 AM, David <quick.webmaster@xxxxxxxxx> wrote: >> > On Thu, Apr 16, 2009 at 11:48 PM, haliphax <haliphax@xxxxxxxxx> wrote: >> > >> >> On Wed, Apr 15, 2009 at 9:17 PM, David <quick.webmaster@xxxxxxxxx> >> >> wrote: >> >> > Except I also need to POST data to the server to login. After I've >> >> > logged >> >> > in, I then need to use cookies to maintain a session. >> >> > >> >> > Doing that via file_get_contents() just isn't possible. >> >> > >> >> > >> >> > Thanks >> >> > >> >> > On Thu, Apr 16, 2009 at 2:30 AM, haliphax <haliphax@xxxxxxxxx> wrote: >> >> >> >> >> >> On Wed, Apr 15, 2009 at 10:36 AM, David <quick.webmaster@xxxxxxxxx> >> >> wrote: >> >> >> > I was wondering if anyone could please help me with this cURL >> >> >> > script >> >> >> > since I >> >> >> > keep getting error 400 from the web server: >> >> >> > >> >> >> > http://pastebin.ca/1392840 >> >> >> > >> >> >> > It worked until around a month ago which is when they presumably >> >> >> > made >> >> >> > changes to the site. Except I can't figure out what configuration >> >> option >> >> >> > in >> >> >> > the cURL PHP script needs to be changed. I can visit the site >> >> perfectly >> >> >> > in >> >> >> > Lynx, Firefox and IE. >> >> >> >> >> >> Are you just trying to get the contents of the page, or is there >> >> >> something special you're doing? If it's just the contents you're >> >> >> after, try file_get_contents() if allow_url_fopen is set to TRUE for >> >> >> your PHP installation. >> >> >> >> >> >> http://php.net/file_get_contents >> >> >> http://php.net/allow_url_fopen >> >> >> >> David, please refrain from top-posting. >> >> >> >> As for cURL login/session handling... I have an automated script that >> >> connects to a phpBB bulletin board, and here are the settings that >> >> have worked for me: >> >> >> >> curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); >> >> curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); >> >> curl_setopt($ch, CURLOPT_COOKIESESSION, true); >> >> curl_setopt($ch, CURLOPT_HEADER, false); >> >> curl_setopt($ch, CURLOPT_COOKIEFILE, "{$homedir}cookiefile"); >> >> curl_setopt($ch, CURLOPT_COOKIEJAR, "{$homedir}cookiefile"); >> >> curl_setopt($ch, CURLOPT_COOKIE, session_name() . '=' . session_id()); >> >> >> >> I would think CURLOPT_FOLLOWLOCATION and the CURLOPT_COOKIE* options >> >> are most important for resolving your issue. >> >> >> >> HTH, >> >> >> >> >> >> -- >> >> // Todd >> >> >> > >> >> > Hi, >> > >> > Sorry, that didn't work. The website is still returning error 400 with >> > CURLOPT_COOKIESESSION and CURLOPT_COOKIE enabled. >> > >> > I did some experimentation in Firefox by blocking and deleting all >> > cookies >> > from the site. When I then visited the site, I was able to reach the >> > logon >> > page without returning error 400 so I doubt it's cookies that is the >> > problem. >> > >> > I also tried changing the HTTP headers to: >> > >> > Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 >> > Connection: Keep-Alive >> > Content-Type: text/html; charset=UTF-8 >> > >> > Which didn't work either. >> > >> > >> > >> > >> > Thanks >> > >> >> Does the site require a valid HTTP_REFERER? I haven't seen >> CURLOPT_REFERER in any of your examples. (If I missed it somewhere, >> just ignore the noise.) Have you set your CURLOPT_COOKIEFILE properly? Also--you may need to unlink() it before you log-in using your cURL script to make sure that any invalid cookie values (i.e., expired session ID) are cleared out. unlink("{$homedir}cookiefile"); curl_setopt($ch, CURLOPT_COOKIESESSION, true); curl_setopt($ch, CURLOPT_COOKIEFILE, "{$homedir}cookiefile"); curl_setopt($ch, CURLOPT_COOKIEJAR, "{$homedir}cookiefile"); curl_setopt($ch, CURLOPT_COOKIE, session_name() . '=' . session_id()); ... (where $homedir is "/home/haliphax/" or some such value.) HTH, -- // Todd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php