[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

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


Closed Thread
 
LinkBack Thread Tools
Old 03-05-2007, 08:24 AM   #1 (permalink)
tm
Senior Member
 
tm's Avatar
 
Join Date: Nov 2005
Location: on a oil rig just off Ireland
Posts: 1,409
374.65 NP$ (Donate)

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, 09:21 AM   #2 (permalink)
Stud Sausage
 
Join Date: Dec 2006
Location: England
Posts: 1,546
34.41 NP$ (Donate)

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
__________________
My NamePros Tools
(firefox plugin, google gadget etc)
Matthew. is offline  
Old 03-05-2007, 09:37 AM   #3 (permalink)
tm
Senior Member
 
tm's Avatar
 
Join Date: Nov 2005
Location: on a oil rig just off Ireland
Posts: 1,409
374.65 NP$ (Donate)

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, 09:41 AM   #4 (permalink)
Stud Sausage
 
Join Date: Dec 2006
Location: England
Posts: 1,546
34.41 NP$ (Donate)

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
__________________
My NamePros Tools
(firefox plugin, google gadget etc)
Matthew. is offline  
Old 03-05-2007, 09:51 AM   #5 (permalink)
tm
Senior Member
 
tm's Avatar
 
Join Date: Nov 2005
Location: on a oil rig just off Ireland
Posts: 1,409
374.65 NP$ (Donate)

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";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, "fieldname=fieldvalue&fieldname=fieldvalue&");
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$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, 12:37 PM   #6 (permalink)
Domains my Dominion
 
sdsinc's Avatar
 
Join Date: Aug 2005
Location: Web 1.0
Posts: 6,284
1,095.94 NP$ (Donate)

sdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond repute

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
Quote:
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.
__________________
Buy now - MassDeveloper.com $500
sdsinc is offline  
Old 03-05-2007, 12:59 PM   #7 (permalink)
NamePros Regular
 
Join Date: Aug 2006
Location: USA
Posts: 725
212.90 NP$ (Donate)

enlytend is a name known to allenlytend is a name known to allenlytend is a name known to allenlytend is a name known to allenlytend is a name known to allenlytend is a name known to all


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.

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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 10:54 PM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85