johnsmith153 Posted October 25, 2008 Share Posted October 25, 2008 Is there an alternative to using cURL which will allow me to access session values already set? I know cURL cant do this. Link to comment https://forums.phpfreaks.com/topic/130032-alternative-to-curl-that-allows-access-to-_session-values/ Share on other sites More sharing options...
MasterACE14 Posted October 25, 2008 Share Posted October 25, 2008 you want to access $_SESSION vars using something like cURL? why not just do... <?php echo $_SESSION['var']; ?> ? Link to comment https://forums.phpfreaks.com/topic/130032-alternative-to-curl-that-allows-access-to-_session-values/#findComment-674189 Share on other sites More sharing options...
johnsmith153 Posted October 25, 2008 Author Share Posted October 25, 2008 If you use cURL, then you can't access session variables - it doesn't work - something to do with starting a new http request/session. Test it. Is there an alternative, so I can create a http request from within a PHP page (ie like cURL) - but allows me to access the session variables already stored? Link to comment https://forums.phpfreaks.com/topic/130032-alternative-to-curl-that-allows-access-to-_session-values/#findComment-674193 Share on other sites More sharing options...
MasterACE14 Posted October 25, 2008 Share Posted October 25, 2008 hmmm, I'm not sure. never worked with cURL, or much to do with http requests in the way of sessions. Link to comment https://forums.phpfreaks.com/topic/130032-alternative-to-curl-that-allows-access-to-_session-values/#findComment-674194 Share on other sites More sharing options...
corbin Posted October 25, 2008 Share Posted October 25, 2008 If you use cURL, then you can't access session variables - it doesn't work - something to do with starting a new http request/session. Test it. Is there an alternative, so I can create a http request from within a PHP page (ie like cURL) - but allows me to access the session variables already stored? Set up cURL to use cookies and your sessions will persist. Link to comment https://forums.phpfreaks.com/topic/130032-alternative-to-curl-that-allows-access-to-_session-values/#findComment-674199 Share on other sites More sharing options...
johnsmith153 Posted October 25, 2008 Author Share Posted October 25, 2008 How would I do this? If I had: $post_fields="var1=1&var2=5&var3="; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://www.site.com/page.php'); curl_setopt ($ch, CURLOPT_POST, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, $post_fields); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response_string = curl_exec($ch); curl_close($ch); What would I change? Link to comment https://forums.phpfreaks.com/topic/130032-alternative-to-curl-that-allows-access-to-_session-values/#findComment-674202 Share on other sites More sharing options...
xtopolis Posted October 25, 2008 Share Posted October 25, 2008 If you read the comments I posted a link to in your other thread, you would already know. http://www.phpfreaks.com/forums/index.php/topic,222719.0.html Link to comment https://forums.phpfreaks.com/topic/130032-alternative-to-curl-that-allows-access-to-_session-values/#findComment-674203 Share on other sites More sharing options...
johnsmith153 Posted October 25, 2008 Author Share Posted October 25, 2008 Is there anybody who can help with this? How would I change this to maintain the $_SESSION values when using cURL? Xtopolis, you can't know as you wanted to see some code when I originally asked why cURL did not maintain the session values. Luckily someone else educated us. $post_fields="var1=1&var2=5&var3="; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://www.site.com/page.php'); curl_setopt ($ch, CURLOPT_POST, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, $post_fields); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response_string = curl_exec($ch); curl_close($ch); Link to comment https://forums.phpfreaks.com/topic/130032-alternative-to-curl-that-allows-access-to-_session-values/#findComment-674204 Share on other sites More sharing options...
xtopolis Posted October 25, 2008 Share Posted October 25, 2008 That's a very big assumption about me. You STILL have not edited your code to account for COOKIEs that are usually used for Sessions. Your answers can STILL be found on the comments I posted, to get you started. Doesn't mean it will work either, but corbin told you what to try, so why not? Link to comment https://forums.phpfreaks.com/topic/130032-alternative-to-curl-that-allows-access-to-_session-values/#findComment-674214 Share on other sites More sharing options...
corbin Posted October 25, 2008 Share Posted October 25, 2008 http://php.net/curl-setopt Look at the cookie related stuff. Link to comment https://forums.phpfreaks.com/topic/130032-alternative-to-curl-that-allows-access-to-_session-values/#findComment-674215 Share on other sites More sharing options...
DarkWater Posted October 25, 2008 Share Posted October 25, 2008 http://php.net/curl-setopt Look at the cookie related stuff. Specifically CURL_COOKIEFILE. Link to comment https://forums.phpfreaks.com/topic/130032-alternative-to-curl-that-allows-access-to-_session-values/#findComment-674429 Share on other sites More sharing options...
johnsmith153 Posted October 25, 2008 Author Share Posted October 25, 2008 I am afraid you are all wrong. Darkwater. Thanks for coming in on this. You have given the nearest answer. I eventually got the answer from http://www.sitepoint.com/forums/showthread.php?t=572402 who told me that you need to first close the session on the main page (session_write_close() Not one single link anybody posted mentioned session_write_close. Quote From Xtopolis - "If you read the comments I posted a link to in your other thread, you would already know." Xtopolis, you where adament how the answer was so obvious and how I should have read your earlier links (which was when we were talking about SSL). You were wrong, and you wasted a lot of my time. You never mentioned session_write_close. Whilst all help is free and I appreciate it, you mocked me here, when clearly you had no right. Page 1: session_start(); set sessions etc. session_write_close(); Do cURL Page 2: session_start() echo $_SESSION Link to comment https://forums.phpfreaks.com/topic/130032-alternative-to-curl-that-allows-access-to-_session-values/#findComment-674436 Share on other sites More sharing options...
DarkWater Posted October 25, 2008 Share Posted October 25, 2008 The session writing closes automatically at the end of a request; I've never felt a need to use that function. Try using your code without the function and see if it still works with the proper COOKIEFILE parameter. Link to comment https://forums.phpfreaks.com/topic/130032-alternative-to-curl-that-allows-access-to-_session-values/#findComment-674441 Share on other sites More sharing options...
johnsmith153 Posted October 25, 2008 Author Share Posted October 25, 2008 It does close automatically at end of request. Whilst using cURL you are basically using 2 http requests/sessions. (so the inital request hasn't closed.) Tried without and it just locks up, resulting in 500 error. Link to comment https://forums.phpfreaks.com/topic/130032-alternative-to-curl-that-allows-access-to-_session-values/#findComment-674443 Share on other sites More sharing options...
DarkWater Posted October 25, 2008 Share Posted October 25, 2008 Wait, the page you're trying to get resides on the same server? Link to comment https://forums.phpfreaks.com/topic/130032-alternative-to-curl-that-allows-access-to-_session-values/#findComment-674444 Share on other sites More sharing options...
johnsmith153 Posted October 25, 2008 Author Share Posted October 25, 2008 Yes, same server. My previous post was initially about why cURL would not work - where I didnt even consider session problems. In that I posted: "Is there an alternative to cURL where I can get the session values? Everything is all on my same server. " which everyone else would have seen (including Xtopolis). I suppose you didn't see all that DarkWater as you have just joined things. Also, everyone kept mentioning various things to add, but the only thing on top of a normal cURL response is: curl_setopt($ch, CURLOPT_COOKIE, session_name() . '=' . session_id()); (As well as session_write_close) Link to comment https://forums.phpfreaks.com/topic/130032-alternative-to-curl-that-allows-access-to-_session-values/#findComment-674448 Share on other sites More sharing options...
johnsmith153 Posted October 25, 2008 Author Share Posted October 25, 2008 Xtopolis responds: Link to comment https://forums.phpfreaks.com/topic/130032-alternative-to-curl-that-allows-access-to-_session-values/#findComment-674450 Share on other sites More sharing options...
DarkWater Posted October 25, 2008 Share Posted October 25, 2008 Oh, I get it. You were trying to use the person who is accessing the page's session on another page on your site accessed by cURL. I misunderstood a bit at first, but now I've got it. Link to comment https://forums.phpfreaks.com/topic/130032-alternative-to-curl-that-allows-access-to-_session-values/#findComment-674453 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.