Dark57 Posted April 7, 2010 Share Posted April 7, 2010 So I'm trying to make a login script, and when it detects that you've logged in correctly you are directed towards a page that has your personal information on it. I am trying to do this using a session, but whenever I get directed to the page it says that the variable is undefined. This is what I have for when they login correctly. <?php // Check if session is not registered , redirect back to main page. session_start(); if(!session_is_registered(myusername)) { header("location:main_login.php"); } ?> <html> <body> <?php $_SESSION['username']==$_POST['myusername']; header("location:index.php"); ?> </body> </html> Then this line of code right here should display their username if I'm not mistaken. <?php echo $_SESSION['username']; ?> Now I might not be catching a simple mistake but I've been staring at it for a while and tried reading up on it and from what I can see I don't see me doing anything wrong. Any help would be appreciated. Oh I forgot, this is the error message I am getting. Notice: Undefined variable: _SESSION in C:\wamp\www\Silent Night Online\Index.php on line 26 Link to comment https://forums.phpfreaks.com/topic/197944-session-variable-problem/ Share on other sites More sharing options...
trq Posted April 7, 2010 Share Posted April 7, 2010 Have you got session_start() on all pages that use sessions? Also, this.... if(!session_is_registered(myusername)) should be.... if(!isset($_SESSION['myusername'])) session_is_registered is deprecated and you where also trying to use an undefined constant myusername. Link to comment https://forums.phpfreaks.com/topic/197944-session-variable-problem/#findComment-1038677 Share on other sites More sharing options...
Dark57 Posted April 8, 2010 Author Share Posted April 8, 2010 I'm still getting the same problem. So I looked into my user login check script. If session_is_registered() is deprecated then will this also be deprecated? session_register("myusername"); session_register("mypassword"); Link to comment https://forums.phpfreaks.com/topic/197944-session-variable-problem/#findComment-1038680 Share on other sites More sharing options...
Dark57 Posted April 8, 2010 Author Share Posted April 8, 2010 Ok I tried changing that line of code to but I'm still getting the same error. $_SESSION['username']=$_POST['myusername']; $_SESSION['password']=$_POST['mypassword']; Link to comment https://forums.phpfreaks.com/topic/197944-session-variable-problem/#findComment-1038703 Share on other sites More sharing options...
trq Posted April 8, 2010 Share Posted April 8, 2010 I'm still getting the same problem. So I looked into my user login check script. If session_is_registered() is deprecated then will this also be deprecated? session_register("myusername"); session_register("mypassword"); Yes. Ok I tried changing that line of code to but I'm still getting the same error. $_SESSION['username']=$_POST['myusername']; $_SESSION['password']=$_POST['mypassword']; Again, have you got session_start() on all pages that use sessions? Link to comment https://forums.phpfreaks.com/topic/197944-session-variable-problem/#findComment-1038717 Share on other sites More sharing options...
Dark57 Posted April 8, 2010 Author Share Posted April 8, 2010 I feel retarded. Thank you for that though, now I will remember session_start(); from now on... I must have skipped that part of your previous post about the session_start();. My mistake. Link to comment https://forums.phpfreaks.com/topic/197944-session-variable-problem/#findComment-1038728 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.