amalosoul Posted April 21, 2010 Share Posted April 21, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/199240-session-help/ Share on other sites More sharing options...
swatisonee Posted April 21, 2010 Share Posted April 21, 2010 why is session id fixed at 23 ? consider codes as under : <?php session_start(); //session_register("session"); and then another <?php error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR); $_SESSION['id']=session_id(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/199240-session-help/#findComment-1045668 Share on other sites More sharing options...
amalosoul Posted April 21, 2010 Author Share Posted April 21, 2010 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']."!*"; Quote Link to comment https://forums.phpfreaks.com/topic/199240-session-help/#findComment-1045670 Share on other sites More sharing options...
swatisonee Posted April 21, 2010 Share Posted April 21, 2010 try what i sent . your page would have to then include "session.php" ; and after your $sql has run you'd have to include "newsession.php" - which is basically the 2nd php Quote Link to comment https://forums.phpfreaks.com/topic/199240-session-help/#findComment-1045675 Share on other sites More sharing options...
oni-kun Posted April 21, 2010 Share Posted April 21, 2010 Note you're calling the session on a file that is not included, Why would you expect it to be set? Quote Link to comment https://forums.phpfreaks.com/topic/199240-session-help/#findComment-1045686 Share on other sites More sharing options...
amalosoul Posted April 21, 2010 Author Share Posted April 21, 2010 I can't include that file it has to be something outside my page (I tried with session_id() and it doesn't work either). Thank you for your pacience! Quote Link to comment https://forums.phpfreaks.com/topic/199240-session-help/#findComment-1045693 Share on other sites More sharing options...
oni-kun Posted April 21, 2010 Share Posted April 21, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/199240-session-help/#findComment-1045699 Share on other sites More sharing options...
amalosoul Posted April 21, 2010 Author Share Posted April 21, 2010 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) Quote Link to comment https://forums.phpfreaks.com/topic/199240-session-help/#findComment-1045710 Share on other sites More sharing options...
oni-kun Posted April 21, 2010 Share Posted April 21, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/199240-session-help/#findComment-1045712 Share on other sites More sharing options...
amalosoul Posted April 21, 2010 Author Share Posted April 21, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/199240-session-help/#findComment-1045719 Share on other sites More sharing options...
swatisonee Posted April 22, 2010 Share Posted April 22, 2010 AAGH ! I posted and then saw the solved tag Quote Link to comment https://forums.phpfreaks.com/topic/199240-session-help/#findComment-1046495 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.