harsh00008 Posted August 1, 2008 Share Posted August 1, 2008 Hey I after logging in in my login page i want a session to start so that it caries value through all the pages... that means if the session is set then only someone can view a topic else he'll need to login any suggestions? I tried the session thing but it doesn't carry value to the other page any simple explanation/help would be great Quote Link to comment https://forums.phpfreaks.com/topic/117766-solved-little-help-on-sessions-p/ Share on other sites More sharing options...
DarkWater Posted August 1, 2008 Share Posted August 1, 2008 You need session_start() on the top of every page that requires session use. Quote Link to comment https://forums.phpfreaks.com/topic/117766-solved-little-help-on-sessions-p/#findComment-605705 Share on other sites More sharing options...
harsh00008 Posted August 1, 2008 Author Share Posted August 1, 2008 You need session_start() on the top of every page that requires session use. That means wen i login.. for eg in my case...wen i input the login variables and hit the login button i get directed to the login.php page where it checks for the inputs and echoes that u r logged in.. so at that time i shall put session_start(); $_SESSION["logged"]=1 in the login.php if the account is verfied and on all restricted page session_start(); if($_SESSION==1) { blah blah codes } Else { Echo "you need to login to view this page"; }; ??? and then session_start() on every page where i want the permission?? ??? and on logout.php put the session_destroy() code? :-? Quote Link to comment https://forums.phpfreaks.com/topic/117766-solved-little-help-on-sessions-p/#findComment-605710 Share on other sites More sharing options...
.josh Posted August 1, 2008 Share Posted August 1, 2008 yes. Quote Link to comment https://forums.phpfreaks.com/topic/117766-solved-little-help-on-sessions-p/#findComment-605711 Share on other sites More sharing options...
harsh00008 Posted August 1, 2008 Author Share Posted August 1, 2008 It isn't working still the $_SESSION["logged"] value is not getting carried to the restricted page... it remains 0 there not 1 on logging in Quote Link to comment https://forums.phpfreaks.com/topic/117766-solved-little-help-on-sessions-p/#findComment-605720 Share on other sites More sharing options...
.josh Posted August 1, 2008 Share Posted August 1, 2008 well that code you kinda sorta posted you did if($_SESSION==1) it's supposed to be if($_SESSION["logged"]==1) I just assumed you were showing some pseudo-code to get your point across but if that's what you really did.. Quote Link to comment https://forums.phpfreaks.com/topic/117766-solved-little-help-on-sessions-p/#findComment-605735 Share on other sites More sharing options...
harsh00008 Posted August 1, 2008 Author Share Posted August 1, 2008 well that code you kinda sorta posted you did if($_SESSION==1) it's supposed to be if($_SESSION["logged"]==1) I just assumed you were showing some pseudo-code to get your point across but if that's what you really did.. yeah..forgot to type["logged"] there but in the codes its ["logged"] any reason or method to carry the $_SESSION["logged"] value to all the pages? ??? Quote Link to comment https://forums.phpfreaks.com/topic/117766-solved-little-help-on-sessions-p/#findComment-605740 Share on other sites More sharing options...
.josh Posted August 1, 2008 Share Posted August 1, 2008 It's really simple: page1.php <?php // must have this before any output and before you want to use session vars // must even be on the page where the session var is first set session_start(); // example session var $_SESSION['logged'] = 1; // example to get to next page. can use header() or whatever who cares echo "<a href = 'page2.php'>page2</a>"; ?> page2.php <?php session_start(); // is there a session var called 'logged' and does it equal 1? if ($_SESSION['logged'] == 1) { echo "yay!"; } else { echo "nay!"; } ?> If that's the basic format you have and you're sure everything is spelled right etc.. then perhaps you have cookies turned off in your browser? Quote Link to comment https://forums.phpfreaks.com/topic/117766-solved-little-help-on-sessions-p/#findComment-605743 Share on other sites More sharing options...
ShaunO Posted August 1, 2008 Share Posted August 1, 2008 If that doesn't work then sessions aren't turned on. Or the web server doesn't have permission to write to the tmp directory in the php.ini (or it is pointing to an invalid path) Quote Link to comment https://forums.phpfreaks.com/topic/117766-solved-little-help-on-sessions-p/#findComment-605746 Share on other sites More sharing options...
harsh00008 Posted August 1, 2008 Author Share Posted August 1, 2008 It Echoes "nay" in both the cases even after u goto page2 via the a href function ,i.e., via page1> :( I'm testing this project on my localhost is it something related to this...that the browser cookies or the session function don't always work well on a local server ??? Quote Link to comment https://forums.phpfreaks.com/topic/117766-solved-little-help-on-sessions-p/#findComment-605749 Share on other sites More sharing options...
DeanWhitehouse Posted August 1, 2008 Share Posted August 1, 2008 make a page with phpinfo(); on it , and check if sessions are on Quote Link to comment https://forums.phpfreaks.com/topic/117766-solved-little-help-on-sessions-p/#findComment-605751 Share on other sites More sharing options...
harsh00008 Posted August 1, 2008 Author Share Posted August 1, 2008 Hey buddy is it off? if yes how do i configure this stuff to make my sessions codes working? ??? Quote Link to comment https://forums.phpfreaks.com/topic/117766-solved-little-help-on-sessions-p/#findComment-605754 Share on other sites More sharing options...
DeanWhitehouse Posted August 1, 2008 Share Posted August 1, 2008 As far as i can tell they are. Show the two pages code where the problem is Quote Link to comment https://forums.phpfreaks.com/topic/117766-solved-little-help-on-sessions-p/#findComment-605756 Share on other sites More sharing options...
harsh00008 Posted August 1, 2008 Author Share Posted August 1, 2008 As far as i can tell they are. Show the two pages code where the problem is Hey buddy I tested these simple session codes to test if something was wrong in my codes Where page1.php is <?php session_start(); $_SESSION["logged"]=1; Echo "<a href=page2.php>Page2</a>"; ?> and page2.php is <?php session_start(); if($_SESSION["logged"]==1) { Echo "working"; } Else { Echo "not working"; }; ?> and wen i access the page2 via the page1 link it still echoes not working!!! Quote Link to comment https://forums.phpfreaks.com/topic/117766-solved-little-help-on-sessions-p/#findComment-605760 Share on other sites More sharing options...
ShaunO Posted August 1, 2008 Share Posted August 1, 2008 My guess is that it can't write the session files to the folder session.save_path Is PHP installed into C:\php? If so, there should be a sessions folder in there If you change the session save path in the php.ini to the C:\php\sessions If you are using IIS as the web server you will also need to add the IUSR user to have permissions on that directory Quote Link to comment https://forums.phpfreaks.com/topic/117766-solved-little-help-on-sessions-p/#findComment-605762 Share on other sites More sharing options...
harsh00008 Posted August 1, 2008 Author Share Posted August 1, 2008 hey buddy I'm using Easy php..and testing the project on localhost I checked this line on the php.ini file ;session.save_path = /tmp and i checked the tmp folder... and the session files are present there Quote Link to comment https://forums.phpfreaks.com/topic/117766-solved-little-help-on-sessions-p/#findComment-605767 Share on other sites More sharing options...
.josh Posted August 1, 2008 Share Posted August 1, 2008 so...does that folder have appropriate permissions? just for shits and grins, try this: <?php session_start(); echo session_id(); ?> does something echo? Quote Link to comment https://forums.phpfreaks.com/topic/117766-solved-little-help-on-sessions-p/#findComment-605770 Share on other sites More sharing options...
harsh00008 Posted August 1, 2008 Author Share Posted August 1, 2008 so...does that folder have appropriate permissions? just for shits and grins, try this: <?php session_start(); echo session_id(); ?> does something echo? yeah it echoes a hash like some md5 encryption 62467318e5d1474cea48c7274fb090af Well i think if some session files are present there then i guess it must be having proper permissions but even if so...how do i change the permission on'em?..like for the web hosting i CHMOD them via ftp manager.. I'm really confused y this thing isn't working Quote Link to comment https://forums.phpfreaks.com/topic/117766-solved-little-help-on-sessions-p/#findComment-605772 Share on other sites More sharing options...
ShaunO Posted August 1, 2008 Share Posted August 1, 2008 Add echo session_id(); Just below session_start(); on each of those test pages Then go to each one and check if they stay the same Quote Link to comment https://forums.phpfreaks.com/topic/117766-solved-little-help-on-sessions-p/#findComment-605777 Share on other sites More sharing options...
PFMaBiSmAd Posted August 1, 2008 Share Posted August 1, 2008 Get php to help by turning on full php error reporting. Add the following two lines immediately after the first opening <?php tag on both pages - ini_set ("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/117766-solved-little-help-on-sessions-p/#findComment-605778 Share on other sites More sharing options...
harsh00008 Posted August 1, 2008 Author Share Posted August 1, 2008 Add echo session_id(); Just below session_start(); on each of those test pages Then go to each one and check if they stay the same Yeah they do echo the same session id Quote Link to comment https://forums.phpfreaks.com/topic/117766-solved-little-help-on-sessions-p/#findComment-605781 Share on other sites More sharing options...
harsh00008 Posted August 1, 2008 Author Share Posted August 1, 2008 Get php to help by turning on full php error reporting. Add the following two lines immediately after the first opening <?php tag on both pages - ini_set ("display_errors", "1"); error_reporting(E_ALL); i got these three error lines on page1.php Warning: session_start(): open(C:\DOCUME~1\Harsh\LOCALS~1\Temp\php\session\sess_62467318e5d1474cea48c7274fb090af, O_RDWR) failed: No such file or directory (2) in c:\program files\easyphp1-8\www\page1.php on line 6 Warning: Unknown(): open(C:\DOCUME~1\Harsh\LOCALS~1\Temp\php\session\sess_62467318e5d1474cea48c7274fb090af, O_RDWR) failed: No such file or directory (2) in Unknown on line 0 Warning: Unknown(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (C:\DOCUME~1\Harsh\LOCALS~1\Temp\php\session) in Unknown on line 0 AND these error line on page2.php Warning: session_start(): open(C:\DOCUME~1\Harsh\LOCALS~1\Temp\php\session\sess_62467318e5d1474cea48c7274fb090af, O_RDWR) failed: No such file or directory (2) in c:\program files\easyphp1-8\www\page2.php on line 4 Notice: Undefined index: logged in c:\program files\easyphp1-8\www\page2.php on line 8 nay! Warning: Unknown(): open(C:\DOCUME~1\Harsh\LOCALS~1\Temp\php\session\sess_62467318e5d1474cea48c7274fb090af, O_RDWR) failed: No such file or directory (2) in Unknown on line 0 Warning: Unknown(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (C:\DOCUME~1\Harsh\LOCALS~1\Temp\php\session) in Unknown on line 0 Quote Link to comment https://forums.phpfreaks.com/topic/117766-solved-little-help-on-sessions-p/#findComment-605783 Share on other sites More sharing options...
ShaunO Posted August 1, 2008 Share Posted August 1, 2008 Much better, as I first thought you need to change the directory it saves session files to Instead of /tmp try C:/php/sessions Quote Link to comment https://forums.phpfreaks.com/topic/117766-solved-little-help-on-sessions-p/#findComment-605784 Share on other sites More sharing options...
harsh00008 Posted August 1, 2008 Author Share Posted August 1, 2008 Much better, as I first thought you need to change the directory it saves session files to Instead of /tmp try C:/php/sessions u mean i change this line ;session.save_path = /tmp to ;session.save_path = C:/php/session ??? but i don't have a folder existing as c:\php I have easyphp installed for the localhost and the path of php is C:\Program Files\EasyPHP1-8\php Quote Link to comment https://forums.phpfreaks.com/topic/117766-solved-little-help-on-sessions-p/#findComment-605788 Share on other sites More sharing options...
JasonLewis Posted August 1, 2008 Share Posted August 1, 2008 Can I just recommend that you get WAMP Server. I used EasyPHP for a while but found WAMP Server far better. Quote Link to comment https://forums.phpfreaks.com/topic/117766-solved-little-help-on-sessions-p/#findComment-605791 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.