Jump to content

Alternative To cURL That Allows Access To $_SESSION Values


johnsmith153

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.