0

I don't get it. I try the code and it works when i log out it doesn't work when i log in again.

test.php

<?php
    session_start();
    
	var_dump ($_SESSION['username']);
    var_dump ($_SESSION['loggedin']);
	
    function is_logged()
    {
    if(isset($_SESSION['loggedin']))
    {
    return true;
    }else{
    return false;
    }
    }
     
    if(is_logged())
    {
    echo "Welcome, ". $_SESSION['username'] ."!";
    }else{
    echo "Welcome, Guest!";
    }

validapass.php

<?php
    session_start();
     
    include "db_connect.php";
    mysql_select_db($dbname, $connect);
     
    $username = $_POST['username'];
    $pass = $_POST['pass'];
     
    $sql="SELECT username, password FROM alunos WHERE username='". $username. "' AND '". $pass ."'";
    $resultado = mysql_query($sql, $connect) or die(mysql_error());
    if(mysql_affected_rows() == 1)
    {
	$_SESSION['username'] = $username;
    $_SESSION['loggedin'] = 1;
    
	header("Location: test.php");
    }else{
    header("Location: login_form.php");
    }
    mysql_close($con);
     
    ?>
0
<?php
    session_start();
    Session_destroy();
    header("Location: index.php");
?>
0

Just to clarify, it works, then when you sign out.. It redirects you the page that says "Welcome, Guest!" and then when you try and sign back in, does it say "Welcome [blank]" or does it redirect you back to the login form?

This is really, really weird.. It's working perfectly fine on my system :(

0

Yes, it worked. after i sign out i tried to sign in again and from now it goes to login_form.php

0

That sounds to me like it's not sessions, it's something to do with your database.. In "validpass.php" you check to see if the username/password is correct or not, if it's not correct then it will redirect you to the login form..

Are you sure your SQL query is right AND you're entering the correct details? :)

0

Change

$sql="SELECT username, password FROM alunos WHERE username='". $username. "' AND '". $pass ."'";

To:

$sql = "SELECT username, password FROM alunos WHERE username='$username' AND password='$pass'";

:)

Edited by phorce: n/a

0

I can't send you the .zip, i'm trying to see what's wrong. If i get something i'll tell ;)

0
<?php
session_start();

include "db_connect.php";

$username = $_POST['username'];
$pass = $_POST['pass'];

mysql_select_db($dbname, $connect);
$sql="SELECT username, password FROM alunos WHERE username='". $username. "'";

$resultado = mysql_query($sql, $connect) or die(mysql_error());

$num = mysql_fetch_assoc($resultado);

if ($username == $num['username'] AND $pass == $num['password']) {
        echo "Yes logged in :)";
        } else {
        echo "Could not log in :(";
        }
mysql_close($con);
?>

Please can you run this code, login and tell me if it says:

Yes logged in :)
OR
Could not log in :(

0
<?php
session_start();

include "db_connect.php";

$username = $_POST['username'];
$pass = $_POST['pass'];

mysql_select_db($dbname, $connect);
$sql="SELECT username, password FROM alunos WHERE username='". $username. "'";

$resultado = mysql_query($sql, $connect) or die(mysql_error());

$num = mysql_fetch_assoc($resultado);

if ($username == $num['username'] AND $pass == $num['password']) {
        $_SESSION['username'] = $username;
        header("Location: test.php"); // sorry xD
        } else {
        echo "Could not log in :(";
        }
mysql_close($con);
?>

Try that now =) I think there was a problem with the previous SQL statement!

Edited by phorce: n/a

0

It worked. :D

Now let's pray that log out and log back in to work.

0

F**K YEAH it works, logout login logout login :)

Thanks a lot man, thanks for being patient too.

0

haha woo :)! You're welcome, pleasure! If you ever need anything else, feel free to ask! I hope this project goes well for you. Take care =)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.