daveeboi Posted July 16, 2008 Share Posted July 16, 2008 I have been trying to restrict a page opening to users that aren't logged into my site but I have tried loads of different alternatives but to no avail. I have recently tried : <? session_start(); if(!session_is_registered(myusername)){ header("Location: login.php"); } ?> and <? session_start(); if(!isset($_SESSIOIN['myusername'])){ header("Location:login.php"); } ?> But niether of them worked. Within my log in process I take in the username and password and pass it to checklogin.php where the session register part is done. session_register("myusername"); I really can't see where I am going wrong and have spent hours attempting to alter it. Any advice right now would be fantastic. Link to comment https://forums.phpfreaks.com/topic/114942-solved-php-sessions-help-required/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 16, 2008 Share Posted July 16, 2008 session_is_registered and session_register were depreciated long ago in php4.2 in the year 2002, when register_globals were turned off (they don't work unless register_globals are on.) If the code you posted is actual code, $_SESSIOIN is spelled incorrectly. You should be setting a value using code similar to this - <?php session_start(); // once at the start of any page using sessions $_SESSION['myusername'] = "whatever"; ?> and to reference a value on a different page - <?php session_start(); // once at the start of any page using sessions if(!isset($_SESSION['myusername'])){ header("Location: login.php"); } ?> Link to comment https://forums.phpfreaks.com/topic/114942-solved-php-sessions-help-required/#findComment-591156 Share on other sites More sharing options...
daveeboi Posted July 16, 2008 Author Share Posted July 16, 2008 Thanks for the advice. I had noticed the spelling mistake after my post. I had tried putting that different decleration in my checklogin.php in place of thr session register line and also altered the php at the top of my page as you had suggested but when testing it still just opens up the target page even though I am not logged in. Link to comment https://forums.phpfreaks.com/topic/114942-solved-php-sessions-help-required/#findComment-591160 Share on other sites More sharing options...
PFMaBiSmAd Posted July 16, 2008 Share Posted July 16, 2008 Add the following two lines of code after the first opening <?php tag in both files - ini_set ("display_errors", "1"); error_reporting(E_ALL); Link to comment https://forums.phpfreaks.com/topic/114942-solved-php-sessions-help-required/#findComment-591167 Share on other sites More sharing options...
daveeboi Posted July 16, 2008 Author Share Posted July 16, 2008 I think I must have not copied and pasted all of your previous suggestion. I just gave it another fresh try and it looks like it doing the trick. Thank you so much for your help. Link to comment https://forums.phpfreaks.com/topic/114942-solved-php-sessions-help-required/#findComment-591172 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.