Reaper0167 Posted January 13, 2009 Share Posted January 13, 2009 Well, something went wrong with my script and I am back to the same problem as before. My error message for my login displays on the same page as my form. Which is good,,, but it also throws the error message up in the url box on my browser. the code for my login script is below. <?php[code] // display log in error or success if($count==1) { session_start(); $_SESSION['auth'] = "yes"; $message = "Welcome $username"; header("location: home.php?error=" . urlencode($message)); } else { $message = "$username is not a registered username."; header("location: index.php?error=" . urlencode($message)); } ?> here is the code that echos the error message <? echo $_GET['error'];?> and this is what is in my url box on my browser. http://----------.com/index.php?error=fdsaf+is+not+a+registered+username. i guess my question is,, why is it displaying this in the url box of my browser? Quote Link to comment https://forums.phpfreaks.com/topic/140602-i-looked-everywhere-i-could-but-couldnt-find-the-answer-to-this/ Share on other sites More sharing options...
premiso Posted January 13, 2009 Share Posted January 13, 2009 Because it is using get and you are adding it onto the url with the ?error= part. Store it in session and just redirect to the index.php usng $_SESSION instead of $_GET Quote Link to comment https://forums.phpfreaks.com/topic/140602-i-looked-everywhere-i-could-but-couldnt-find-the-answer-to-this/#findComment-735773 Share on other sites More sharing options...
trq Posted January 13, 2009 Share Posted January 13, 2009 Because your telling it too by passing the error through the url. Store your error messages within the $_SESSION array if you want to pass them from page to page. Quote Link to comment https://forums.phpfreaks.com/topic/140602-i-looked-everywhere-i-could-but-couldnt-find-the-answer-to-this/#findComment-735774 Share on other sites More sharing options...
Reaper0167 Posted January 13, 2009 Author Share Posted January 13, 2009 Well,,, were getting there... If the name entered is not valid then the $_SESSION['error'] is displayed properly... as for when the name entered and it is a valid username... I am using $_SESSION['auth'] to check that the user is logged in so they can go to the members only page.... So for the success message, what should i use instead of $_SESSION. Quote Link to comment https://forums.phpfreaks.com/topic/140602-i-looked-everywhere-i-could-but-couldnt-find-the-answer-to-this/#findComment-735836 Share on other sites More sharing options...
Reaper0167 Posted January 13, 2009 Author Share Posted January 13, 2009 Nevermind,,, now I am confused. This is what I thought would work. <?php // display log in error or success if($count==1) { session_start(); $_SESSION['auth'] = "yes"; header("location: home.php"); $_SESSION['success'] = "Welcome $username"; } else { session_start(); header("location: index.php"); $_SESSION['error'] = "$username is not a registered username."; } ?> and then for my success or error message <?php <?php echo $_SESSION['success'];?> //this is located on the members page <?php echo $_SESSION['error'];?> //located on the page with the form ?> Quote Link to comment https://forums.phpfreaks.com/topic/140602-i-looked-everywhere-i-could-but-couldnt-find-the-answer-to-this/#findComment-735840 Share on other sites More sharing options...
dawsba Posted January 13, 2009 Share Posted January 13, 2009 <?php session_start(); // display log in error or success if($count==1) { $_SESSION['auth'] = TRUE; $_SESSION['message'] = "Welcome ".$username; echo "<script>window.location='home.php'</script>";/* you can use header i just prefer JS */ } else { $_SESSION['auth'] = FALSE; $_SESSION['message'] = $username." is not a registered username."; echo "<script>window.location='index.php'</script>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/140602-i-looked-everywhere-i-could-but-couldnt-find-the-answer-to-this/#findComment-735842 Share on other sites More sharing options...
dawsba Posted January 13, 2009 Share Posted January 13, 2009 If your still troubling post the scripts i'll look over them 4 u. Quote Link to comment https://forums.phpfreaks.com/topic/140602-i-looked-everywhere-i-could-but-couldnt-find-the-answer-to-this/#findComment-735843 Share on other sites More sharing options...
Reaper0167 Posted January 13, 2009 Author Share Posted January 13, 2009 ok,,, so should this... <?php echo $_SESSION['message'];?> still go on my pages where i want the message to appear? I'll try it. Quote Link to comment https://forums.phpfreaks.com/topic/140602-i-looked-everywhere-i-could-but-couldnt-find-the-answer-to-this/#findComment-735851 Share on other sites More sharing options...
dawsba Posted January 13, 2009 Share Posted January 13, 2009 It wouldnt hurt, i personally prefer to use <?php if(isset($_SESSION['message'])){echo $_SESSION['message'];} ?> Quote Link to comment https://forums.phpfreaks.com/topic/140602-i-looked-everywhere-i-could-but-couldnt-find-the-answer-to-this/#findComment-735873 Share on other sites More sharing options...
Reaper0167 Posted January 13, 2009 Author Share Posted January 13, 2009 Alright,, the error messages now display properly... Thank you everyone... Here is what ended up working for me.. <?php //login if($count==1) { session_start(); $_SESSION['auth'] = "yes"; $_SESSION['message'] = "Welcome ".$username; header("location: http://www.-------------.com/home.php"); } else { session_start(); $_SESSION['message'] = $username." is not a registered username."; header("location: http://www.-----------.com"); session_destroy(); } ?> Would something like session_unset['message'] on refresh work? and then the code that goes where you want the message to appear. <?php if(isset($_SESSION['message'])){echo $_SESSION['message'];} ?> Everything works good except one small thing..... If someone enters an invalid username the message appears on the page,, which is good... When I hit the refresh button on my browser the message stays there... What should I do to get rid of the session error message when the browser is refreshed???? Quote Link to comment https://forums.phpfreaks.com/topic/140602-i-looked-everywhere-i-could-but-couldnt-find-the-answer-to-this/#findComment-736292 Share on other sites More sharing options...
dawsba Posted January 13, 2009 Share Posted January 13, 2009 <?php if(isset($_SESSION['message'])){echo $_SESSION['message'];unset($_SESSION['message'];} ?> Quote Link to comment https://forums.phpfreaks.com/topic/140602-i-looked-everywhere-i-could-but-couldnt-find-the-answer-to-this/#findComment-736317 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.