Jump to content


Photo

curl and cookies in php


  • Please log in to reply
26 replies to this topic

#21 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,602 posts
  • LocationMississauga, Canada

Posted 23 December 2013 - 11:28 AM

Hey murfy,

sorry for the delay but there was a big ice storm in Toronto and GTA which left my city dealing with widespread power outages and transit problems for more than 15 hours.

So, your problem is, that the post form action doesn't execute any data to the remote URL destination, even though you have a set of cookies and proper header information, right?

I will try to test your script by myself, if I have the time today and I'll back with new reply if I got a success result. If it still doesn't work the easiest way is to use cURL of course :) 



#22 murfy

murfy

    Advanced Member

  • Members
  • PipPipPip
  • 48 posts

Posted 23 December 2013 - 11:54 AM

Hi jazzman1

I had a break from tomorrow up today, so maybe I miss something. The posted header was not the look as I would expected. I have seen host: localhost instead host:hidemyass.com. But I am not sure if php works with the cookies. I don't see there any cookie header in the context. But the server really needs cookies because it will not send the filtered results if I disable cookies and the options will reset. Maybe curl is only change, but then it will be twice so slower.



#23 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,602 posts
  • LocationMississauga, Canada

Posted 23 December 2013 - 12:32 PM

Twice slower?  I believe not. 

 

Take this one and test the speed, it's a part of my script

//$data = array('name'=>'userName','password'=>'userPass','Submit'=>'OK');

$curl_cookie = "cookies.txt";

//$fp = fopen("example_homepage.txt", "w");

// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, 'http://hidemyass.com/proxy-list/search-225892');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $curl_cookie); // Read cookie file
curl_setopt($ch, CURLOPT_COOKIEJAR,  $curl_cookie); // Write cookie file
//curl_setopt($ch, CURLOPT_POSTFIELDS, $data); // set the post data
//curl_setopt($ch, CURLOPT_FILE, $fp);  // write the data in external file
// grab URL and pass it to the browser
$output = curl_exec($ch);

$info = curl_getinfo($ch);

curl_close($ch);

//fclose($fp);

Edited by jazzman1, 23 December 2013 - 12:34 PM.


#24 murfy

murfy

    Advanced Member

  • Members
  • PipPipPip
  • 48 posts

Posted 23 December 2013 - 12:55 PM

two warnings:

curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set

curl_setopt() [function.curl-setopt]: Unable to access cookies.txt

 

Time is

1.11 - 1.25 for 50 items.

#25 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,602 posts
  • LocationMississauga, Canada

Posted 23 December 2013 - 01:01 PM

Check the permissions to this working directory. I'm on CentOS and Debian linux distros.



#26 murfy

murfy

    Advanced Member

  • Members
  • PipPipPip
  • 48 posts

Posted 23 December 2013 - 05:01 PM

Working directory... do you mean directory of the project, just where I run the script? This is read/write permission for all users.



#27 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,602 posts
  • LocationMississauga, Canada

Posted 23 December 2013 - 08:50 PM

I used the script above on my local Debian/CentOS machines with version of PHP 5.4 and one shared hosting by GoDaddy using CentOS 5.3/PHP5.3.3, so everything works fine. 

 

PS: Listen, this thread is getting too large, stretchable, unreadable and unhelpful for others members in this forum. Open a new one, describe the symptoms of your problem, bugs and errors, describe the environment in which it occurs (machine, OS, application, whatever), describe carefully and clearly the things in the very beginning of your post, what, exactly you are done and want to achive and so forth.

jazz.     


Edited by jazzman1, 23 December 2013 - 08:53 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com