NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Cookies on file_get_contents or cURL?

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 03-05-2007, 09:24 AM THREAD STARTER               #1 (permalink)
tm
Senior Member
 
tm's Avatar
Join Date: Nov 2005
Location: on a oil rig just off Ireland
Posts: 1,408
tm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of light
 



Cookies on file_get_contents or cURL?


Hi,

I need to load up a page, but to view the page you need to be logged in (ie have cookies set).

How do I set cookies in a php script so when I use file_get_contents() or cURL (don't know much about cURL) it loads the logged-in page rather than the login page?

Hope I made myself clear.. please say if you don't understand.

Thanks

Colin
__________________
You design in photoshop, I code into valid XHTML/CSS.
Professional PSD, PNG or HTML to tableless XHTML/CSS designs.
For more info, send me a PM.
tm is offline  
Old 03-05-2007, 10:21 AM   #2 (permalink)
Senior Member
Join Date: Dec 2006
Location: England
Posts: 1,568
Matthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud of
 


Adoption Breast Cancer Breast Cancer Cancer Survivorship
I do not know much about cURL i confess, as i have not used it before. However with cURL you can virtually submit forms and return the data from that. Cookies will be stored in turn with that.

These may be more helpful than i can be right now:
http://www.wagerank.com/2007/how-to-...orms-with-php/
http://www.google.co.uk/search?hl=en...e+Search&meta=

Matt
Matthew. is offline  
Old 03-05-2007, 10:37 AM THREAD STARTER               #3 (permalink)
tm
Senior Member
 
tm's Avatar
Join Date: Nov 2005
Location: on a oil rig just off Ireland
Posts: 1,408
tm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of light
 



You think that'd work like that, would it store the cookies on the server?
__________________
You design in photoshop, I code into valid XHTML/CSS.
Professional PSD, PNG or HTML to tableless XHTML/CSS designs.
For more info, send me a PM.
tm is offline  
Old 03-05-2007, 10:41 AM   #4 (permalink)
Senior Member
Join Date: Dec 2006
Location: England
Posts: 1,568
Matthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud of
 


Adoption Breast Cancer Breast Cancer Cancer Survivorship
I would assume cookies are stored in "cookies.txt", seems logical.

But like i say i have never used cURL.

Matt
Matthew. is offline  
Old 03-05-2007, 10:51 AM THREAD STARTER               #5 (permalink)
tm
Senior Member
 
tm's Avatar
Join Date: Nov 2005
Location: on a oil rig just off Ireland
Posts: 1,408
tm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of light
 



So something like this should work?
PHP Code:
$url="http://url.com";
????: NamePros.com http://www.namepros.com/programming/301397-cookies-on-file_get_contents-or-curl.html
$ch curl_init();
curl_setopt($chCURLOPT_URL$url);
curl_setopt ($chCURLOPT_POST1);
curl_setopt ($chCURLOPT_POSTFIELDS"fieldname=fieldvalue&fieldname=fieldvalue&");
curl_setopt ($chCURLOPT_COOKIEJAR'cookie.txt');
curl_setopt ($chCURLOPT_RETURNTRANSFER1);
$store curl_exec ($ch);
$content curl_exec ($ch); # This returns HTML
curl_close ($ch); 
__________________
You design in photoshop, I code into valid XHTML/CSS.
Professional PSD, PNG or HTML to tableless XHTML/CSS designs.
For more info, send me a PM.
tm is offline  
Old 03-05-2007, 01:37 PM   #6 (permalink)
Domains my Dominion
 
sdsinc's Avatar
Join Date: Aug 2005
Location: Web 1.0
Posts: 9,552
sdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatness
 


Third World Education Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Animal Rescue Animal Cruelty AIDS/HIV Animal Rescue Wildlife Breast Cancer Animal Rescue Wildlife
Originally Posted by tm
How do I set cookies in a php script so when I use file_get_contents() or cURL (don't know much about cURL) it loads the logged-in page rather than the login page?
You definitely need curl. Curl can handle cookies for you.
__________________
NameNewsletter.com - free lists of available domain names
ZoneFiles.net (beta) - ccTLD and gTLD droplists
sdsinc is offline  
Old 03-05-2007, 01:59 PM   #7 (permalink)
Forum Moderator
 
enlytend's Avatar
Join Date: Aug 2006
Location: USA
Posts: 2,037
enlytend has a reputation beyond reputeenlytend has a reputation beyond reputeenlytend has a reputation beyond reputeenlytend has a reputation beyond reputeenlytend has a reputation beyond reputeenlytend has a reputation beyond reputeenlytend has a reputation beyond reputeenlytend has a reputation beyond reputeenlytend has a reputation beyond reputeenlytend has a reputation beyond reputeenlytend has a reputation beyond repute
 



Cancer Survivorship
CURLOPT_COOKIEJAR is used when you fetch a page that sets cookies. It declares a name of a file in which the cookies will be stored.
????: NamePros.com http://www.namepros.com/showthread.php?t=301397

Then you use that filename with CURLOPT_COOKIEFILE on subsequent requests to tell cURL to send the cookies in that file along with your request(s).

For security reasons, be really careful where you keep the cookiejar file - unless there's a reason to keep it, delete it when you're done!

If you just need to send a couple of cookies and you know what they are, you can use CURLOPT_COOKIE followed by a comma and a string (in single quotes) containing comma-delimited cookies and values. For example:
curl_setopt($c, CURLOPT_COOKIE, 'cookie1=value1, cookie2=value2, cookie3=value3');
enlytend is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 08:59 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger