Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cURL and Sessions

Status
Not open for further replies.

skiflyer

Programmer
Sep 24, 2002
2,213
US
I have a script which uses cURL, and I'm using it to set POST values, that's working fine and dandy. Now I want to set some Session values, does anyone know if this is possible and if so how you'd go about it?

Or is this one of those security issues, hence I best start work on the workaround?

-Rob
 
You don't set a session value with cURL.

You use cURL to connect to a server. The server will set some session values and pass back to the browser in a cookie a lookup index for the session store.

When you connect, set the cURL option CURLOPT_COOKIEJAR, which tells cURL where to store cookies, which will include the session cookie: curl_setopt (CURLOPT_COOKIEJAR, '<somefilename>&quot;);

Then in later connections, set CURLOPT_COOKIEFILE, which tells cURL a filename to use which contains a set of cookies to send to the server: curl_setopt (CURLOPT_COOKIEFILE, &quot;<that same file from the previous paragraph>&quot;);

You should be able to set both options every time the script is run. Want the best answers? Ask the best questions: TANSTAAFL!
 
And the cookiefile is going to look just like the session files stored in my session directory?

I think I get it, I'll type it in after I find some food and see how it works.

Thanks,
Rob
 
I think your picture of what is going on is backward.

cURL is a web client, not a web server.

The web server (or more specifically PHP running on a web server) maintains the actual session store. The web client maintains it's copy of the index to that store, and that is all.
Want the best answers? Ask the best questions: TANSTAAFL!
 
No, I think I have the right picture of clientURL's ;), but you're right in that I didn't read your first post closely enough.

But at the same time, I want to push up those values, in the place of the $_SESSION array. I was hoping there was a way to spoof this information up there... as is you can send posts to a webform processing form rather than bothering to go through the form, and I was hoping in the same vein I could do the same to sessions.

I've come to realize that there's just a much simpler workaround to all of this which I'll implement. Namely, set a flag in a post variable and pass the data up as a post, then in the receiving script if that flag is set I'll tear out the values and put them in the session array there. Obviouslly a strange use of sessions, but the idea is to change as few scripts as possible while adding in this cURL script.

Thanks for explaining how cookies work with cURL.

-Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top