Jump to content

[SOLVED] !isset Problem


Ne.OnZ

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.