Jump to content

Recommended Posts

I have two really simple pages:

 

1. FIRST_PAGE

session_start();

$_SESSION['id'] = 23;

 

 

2.SECOND_PAGE

session_start();

file_get_contents(FIRST_PAGE);

echo $_SESSION['id'];

 

How come there is nothing stored in $_SESSION['id']  (and how can I set a session variable from another page)?

 

Thank you very much for your patience!

Link to comment
https://forums.phpfreaks.com/topic/199240-session-help/
Share on other sites

The name of the key is of no particular interest (neither the value), the strange thing is that I don't understand why there is no value there.

I tried even with cURL and still nothing

 

session_start();
define('POSTURL', FIRST_PAGE);
define('POSTVARS', MY_VARIABLES);

$ch = curl_init(POSTURL);
curl_setopt($ch, CURLOPT_POST      ,1);
curl_setopt($ch, CURLOPT_POSTFIELDS    ,POSTVARS);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION  ,1);
curl_setopt($ch, CURLOPT_HEADER      ,1);  //  RETURN HTTP HEADERS
curl_setopt($ch, CURLOPT_RETURNTRANSFER  ,1);  //RETURN THE CONTENTS OF THE CALL
$Rec_Data = curl_exec($ch);
curl_close($ch);

echo $_SESSION['id']."!*";

Link to comment
https://forums.phpfreaks.com/topic/199240-session-help/#findComment-1045670
Share on other sites

I'm not sure what you're trying to do. Are you saying the page is not within your accessabilty? Then you cannot capture the session ID like that.

 

If you are able to require it (which should be) then it'll pass the variables natively, Using file_get_contents or CURL will only be able to capture a SESSID cookie, Nothing more. You cannot get a workable session from that.

Link to comment
https://forums.phpfreaks.com/topic/199240-session-help/#findComment-1045699
Share on other sites

So, taking into consideration that both pages are on the same server how can I set session variables from one page in order to be seen in the orther, as well.

(the reason why I can't use include is because these pages are actually part of a large log in system which needs to be integrated into one log in system)

Link to comment
https://forums.phpfreaks.com/topic/199240-session-help/#findComment-1045710
Share on other sites

So, taking into consideration that both pages are on the same server how can I set session variables from one page in order to be seen in the orther, as well.

(the reason why I can't use include is because these pages are actually part of a large log in system which needs to be integrated into one log in system)

 

How do you expect one code to magically get the result of another code without directly interacting with it? I'm not sure what you're meaning about not being able to include it.

 

What is your need to get the session ID? I'm sure if you'd tell us we could find a better solution to the problem at hand.

Link to comment
https://forums.phpfreaks.com/topic/199240-session-help/#findComment-1045712
Share on other sites

Ok, this is the description :

 

I have multiple php pages (not functions) which take an username and password as input, through GET or POST (all pages are independent from each other) . Once a page gets its input it adds some info into $_SESSION.

 

I want to be able to create a top level page that can send the username and password to all of these pages (which in turn will work independently to add info to $_SESSION).

 

get_file_contents or cURL seemed perfect but they don't work

Link to comment
https://forums.phpfreaks.com/topic/199240-session-help/#findComment-1045719
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.