[PHP] Help with CURL please!

2007-05-11 Thread ray
I'm having a problem getting Curl to work properly...and I know its 
because of this unique situation, so I'm hoping a CURL expert can help 
me out.


I'm trying to access this URL (public search form) using CURL and grab 
the HTML contents

http://enterprisedirectory.ucr.edu/phone/tel_search.show

Now the problem is that in order to access that site, a Cookie must be 
set.  For the web browser if you attempt to access the site, it 
redirects you to http://enterprisedirectory.ucr.edu, sets the cookie 
then sends you back.  In PHP if I call curl on this site, instead of 
grabbing the contents it physically redirects the browser to 
http://enterprisedirectory.ucr.edu (thus leaving my script) and then 
back to the search page (still not in my script)


So im thinking the only way to do this is to use CURL, pass a cookie 
along with the CURL requests and then it will not do the redirect on me. 
 Well the problem with that is when I view my cookies I can see the 
cookie that was set, but in my cookies.txt (or Cookie folder in IE) 
there is no record of this cookie!!??


So i tried doing this and creating a cookie file with the contents
enterprisedirectory.ucr.edu TRUE/phone/ TRUE1181508361  
SearchID5851

Then in PHP use this
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT,120);
curl_setopt($ch, CURLOPT_COOKIEFILE, cookie.txt);
//curl_setopt($ch, CURLOPT_POST, 1);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

$results = curl_exec($ch);
curl_close($ch);

That did not work, but Im assuming I did it wrong.  Can someone please 
help me out with this, I really need to get this working.  After about 5 
hours of this im pulling my hair out and begging for help.

Thank you
-Ray

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Help with CURL please

2007-05-11 Thread ray
I'm having a problem getting Curl to work properly...and I know its 
because of this unique situation, so I'm hoping a CURL expert can help 
me out.


I'm trying to access this URL (public search form) using CURL and grab 
the HTML contents

http://enterprisedirectory.ucr.edu/phone/tel_search.show

Now the problem is that in order to access that site, a Cookie must be 
set.  For the web browser if you attempt to access the site, it 
redirects you to http://enterprisedirectory.ucr.edu, sets the cookie 
then sends you back.  In PHP if I call curl on this site, instead of 
grabbing the contents it physically redirects the browser to 
http://enterprisedirectory.ucr.edu (thus leaving my script) and then 
back to the search page (still not in my script)


So im thinking the only way to do this is to use CURL, pass a cookie 
along with the CURL requests and then it will not do the redirect on me. 
 Well the problem with that is when I view my cookies I can see the 
cookie that was set, but in my cookies.txt (or Cookie folder in IE) 
there is no record of this cookie!!??


So i tried doing this and creating a cookie file with the contents
enterprisedirectory.ucr.edu TRUE/phone/ TRUE1181508361  
SearchID5851

Then in PHP use this
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT,120);
curl_setopt($ch, CURLOPT_COOKIEFILE, cookie.txt);
//curl_setopt($ch, CURLOPT_POST, 1);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

$results = curl_exec($ch);
curl_close($ch);

That did not work, but Im assuming I did it wrong.  Can someone please 
help me out with this, I really need to get this working.  After about 5 
hours of this im pulling my hair out and begging for help.

Thank you
-Ray

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Help with CURL please

2007-05-11 Thread Greg Donald

On 5/11/07, ray [EMAIL PROTECTED] wrote:

I'm having a problem getting Curl to work properly...and I know its
because of this unique situation, so I'm hoping a CURL expert can help
me out.

I'm trying to access this URL (public search form) using CURL and grab
the HTML contents
http://enterprisedirectory.ucr.edu/phone/tel_search.show

Now the problem is that in order to access that site, a Cookie must be
set.  For the web browser if you attempt to access the site, it
redirects you to http://enterprisedirectory.ucr.edu, sets the cookie
then sends you back.  In PHP if I call curl on this site, instead of
grabbing the contents it physically redirects the browser to
http://enterprisedirectory.ucr.edu (thus leaving my script) and then
back to the search page (still not in my script)

So im thinking the only way to do this is to use CURL, pass a cookie
along with the CURL requests and then it will not do the redirect on me.
  Well the problem with that is when I view my cookies I can see the
cookie that was set, but in my cookies.txt (or Cookie folder in IE)
there is no record of this cookie!!??

So i tried doing this and creating a cookie file with the contents
enterprisedirectory.ucr.edu TRUE/phone/ TRUE1181508361  
SearchID5851

Then in PHP use this
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT,120);
curl_setopt($ch, CURLOPT_COOKIEFILE, cookie.txt);
//curl_setopt($ch, CURLOPT_POST, 1);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

$results = curl_exec($ch);
curl_close($ch);

That did not work, but Im assuming I did it wrong.  Can someone please
help me out with this, I really need to get this working.  After about 5
hours of this im pulling my hair out and begging for help.



You need CURLOPT_FOLLOWLOCATION to handle the redirects and
CURLOPT_COOKIEJAR to store the cookie in.



--
Greg Donald
http://destiney.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Help with CURL please!

2007-05-11 Thread Robert Cummings
On Fri, 2007-05-11 at 14:13 -0700, ray wrote:
 I'm having a problem getting Curl to work properly...and I know its 
 because of this unique situation, so I'm hoping a CURL expert can help 
 me out.

That's not very unique. More unique is when you have to rip out
JavaScript cookie stuff and process it manually.

 I'm trying to access this URL (public search form) using CURL and grab 
 the HTML contents
 http://enterprisedirectory.ucr.edu/phone/tel_search.show
 
 Now the problem is that in order to access that site, a Cookie must be 
 set.  For the web browser if you attempt to access the site, it 
 redirects you to http://enterprisedirectory.ucr.edu, sets the cookie 
 then sends you back.  In PHP if I call curl on this site, instead of 
 grabbing the contents it physically redirects the browser to 
 http://enterprisedirectory.ucr.edu (thus leaving my script) and then 
 back to the search page (still not in my script)
 
 So im thinking the only way to do this is to use CURL, pass a cookie 
 along with the CURL requests and then it will not do the redirect on me. 
   Well the problem with that is when I view my cookies I can see the 
 cookie that was set, but in my cookies.txt (or Cookie folder in IE) 
 there is no record of this cookie!!??
 
 So i tried doing this and creating a cookie file with the contents
 enterprisedirectory.ucr.edu   TRUE/phone/ TRUE1181508361  
 SearchID5851
 
 Then in PHP use this
 $ch = curl_init();
 
 curl_setopt($ch, CURLOPT_URL,$url);
 curl_setopt($ch, CURLOPT_HEADER, false);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($ch, CURLOPT_TIMEOUT,120);
 curl_setopt($ch, CURLOPT_COOKIEFILE, cookie.txt);

Try adding the following:

curl_setopt( $ch, CURLOPT_COOKIEJAR, cookie.txt );

 //curl_setopt($ch, CURLOPT_POST, 1);
 //curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
   
 $results = curl_exec($ch);
 curl_close($ch);
 
 That did not work, but Im assuming I did it wrong.  Can someone please 
 help me out with this, I really need to get this working.  After about 5 
 hours of this im pulling my hair out and begging for help.
 Thank you

You need cookies in both directions. You only gave it the file from
which it may load cookies. CURLOPT_COOKIEJAR tells it where to save any
cookies it receives. Chances are when you custom edited the cookie file
you didn't format it correctly, or you don't actually know where
'cookie.txt' is since you've used a relative path.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php