Ne.OnZ Posted May 31, 2008 Share Posted May 31, 2008 Hello again, I seem to be having a problem with !isset. In my login form, I check to make sure if the session or cookie is set then don't show the form. Problem is, when the session or cookie is set, it still shows it. <?php if($_SESSION['username'] || $_COOKIE['user']) { logged(); } if(!isset($_SESSION['username']) || !isset($_COOKIE['user'])) { echo "<form action='#' method='post'> <fieldset id='log'>"; if($err == "1") { echo "<legend style='color: #00C5CD'>$msg</legend>"; } else { echo "<legend> Welcome Guest! Please Login or <a href='index.php?page=Register'>Register! </a></legend>"; } echo "<label for='username' class='login'>Username:</label> <input type='text' name='username' id='username' tabindex='1' class='check' style='width: 70px' /> <br /> <label for='password' class='login'>Password: </label> <input type='password' name='password' id='password' tabindex='2' class='check' style='width: 69px' /> <p /> <div class='login'> <input type='checkbox' id='cookie' name='cookie' value='Cookie' tabindex='3' style='border: 0' />Remember Me </div> <input type='submit' value='Login' name='login' id='login' tabindex='4' class='user check' /> <input type='reset' value='Clear' tabindex='5' class='user check' /> </fieldset> </form>"; } ?> The function logged() just shows a welcome message. Any help would greatly be appreciated. Thank You! Link to comment https://forums.phpfreaks.com/topic/108168-solved-isset-problem/ Share on other sites More sharing options...
kbh43dz_u Posted May 31, 2008 Share Posted May 31, 2008 where do you set $_SESSION['username?'] and/or the cookie? <form action='#' method='post'> will not do anything. you have to enter "thisfilename.php" or "$_SERVER['PHP_SELF']" into action. Link to comment https://forums.phpfreaks.com/topic/108168-solved-isset-problem/#findComment-554483 Share on other sites More sharing options...
Ne.OnZ Posted May 31, 2008 Author Share Posted May 31, 2008 I have it on the same file, before the <html>. When you say it won't do anything, just a note, that the login does work. Just the form never goes away. <?php include("includes/Connect.php"); include("includes/functions.php"); $user = mysql_real_escape_string(stripslashes($_POST['username'])); $pass = md5(mysql_real_escape_string(stripslashes($_POST['password']))); session_start(); if($_POST['login']) { $sql = "SELECT * FROM users WHERE username = '$user' AND password = '$pass' AND rank > '1'"; $res= mysql_query($sql) OR die(mysql_error()); while($arrayid=mysql_fetch_array($res)) { $id = $arrayid['rank']; } if(mysql_num_rows($res) == 1 && isset($_POST['cookie'])) { setcookie("user", $user, time()+(60*60*24*365)); $_SESSION['id'] = $id; header("location: #"); } else if(mysql_num_rows($res) == 1 && !isset($_POST['cookie'])) { $_SESSION['username'] = $user; $_SESSION['id'] = $id; } else { $msg = "Invalid Username Or Password! <a href='index.php?page=Help'>Forgot Pass?</a>"; $err = "1"; } } if($_GET['page'] == "Logout") { session_destroy(); setcookie("user", $user, time()-(60*60*24*365)); header("location: index.php"); exit(); } ?> <html> Login codes a little after some html code I have. Everything in the above code works perfectly. Link to comment https://forums.phpfreaks.com/topic/108168-solved-isset-problem/#findComment-554487 Share on other sites More sharing options...
kbh43dz_u Posted May 31, 2008 Share Posted May 31, 2008 you are setting your cookie when the cookie already exists? <?php if(mysql_num_rows($res) == 1 && isset($_POST['cookie'])) { setcookie("user", $user, time()+(60*60*24*365)); $_SESSION['id'] = $id; header("location: #"); } ?> Link to comment https://forums.phpfreaks.com/topic/108168-solved-isset-problem/#findComment-554496 Share on other sites More sharing options...
Ne.OnZ Posted May 31, 2008 Author Share Posted May 31, 2008 No, $_POST['cookie'] is the id/name of the checkbox in the login form. I'm checking to make sure if the checkbox was checked. Link to comment https://forums.phpfreaks.com/topic/108168-solved-isset-problem/#findComment-554498 Share on other sites More sharing options...
marcus Posted May 31, 2008 Share Posted May 31, 2008 <?php if($_SESSION['username'] || $_COOKIE['user']) { logged(); }else { //show code } ?> if it's set show the logged in message, if either are, show the login form thing Link to comment https://forums.phpfreaks.com/topic/108168-solved-isset-problem/#findComment-554503 Share on other sites More sharing options...
Ne.OnZ Posted May 31, 2008 Author Share Posted May 31, 2008 Thank You! Such and easy fix. Link to comment https://forums.phpfreaks.com/topic/108168-solved-isset-problem/#findComment-554506 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.