Chezshire Posted August 5, 2009 Share Posted August 5, 2009 Hi Everyone, here's is the situation. 'login.php' lets a user login in and sets the cookie to the login name, and goes to welcome.php (which just has a 'Welcome User!' echo statement inside it). When the user comes back to the login page, it should say "Welcome back. Want to change users?". So far, so good. So, I enter a new user, and get the welcome user statement (new page). Also good. when I go back, I get the Welcome back for the FIRST user -- the cookie is never written over. No matter how many times I try to change users, no can do. I'm sure i have a dumb error - i'm dyslexic so... it's probably a typo i can't see or something like that. or maybe it's huge. Any help is always appreciated - code below. thanks! Welcome.php <?php $logged_on_before = false; /* * If user hit submit then display welcome message and * if they entered a name and a pet set the cookies accordingly */ if(isset($_REQUEST['submit'])) { $username = $_POST['userName']; if($username != null && $username != "") { setcookie('username', $_POST['userName'], time() + 60*60); echo("<h2>Welcome $username </h2>"); } } //Otherwise read in the cookies and display a welcome message else { //check if username has been entered before $username = ""; if(isset($_COOKIE['username'])) { $username = $_COOKIE['username']; echo("<h2>Welcome back $username </h2>"); $loggedOnBefore = true; } else { echo("<h3>Login:</h3>"); } //this is like a re-logon if($$logged_on_before) { echo("<h3>Would you like to choose another user?</h3>"); } } ?> <form action="login.php" method="post"> User name: <input type="text" name="userName" /> <input type="submit" name="submit" value="log on"/> </form> Login.php <html> <body> <?php echo("<h2>Welcome " . $_POST['userName'] . "</h2>"); ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/168998-it-doesnt-always-say-hello-the-way-i-want-it-to-help/ Share on other sites More sharing options...
dadamssg Posted August 5, 2009 Share Posted August 5, 2009 try unsetting the cookie then resetting it if it is indeed already set Link to comment https://forums.phpfreaks.com/topic/168998-it-doesnt-always-say-hello-the-way-i-want-it-to-help/#findComment-891646 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.