0

Hello, I try to call a header A if a user is logged in, and a header B if a user is not logged in on some pages

I haven't managed to do so, I've tried to create a php function, but didn't manage to make it work. Then, I setup a connection to the mySql database just to check if 0 users are connected (or 1), but it didn't work. This just includes the header in the if clause

 $result = mysql_query("SELECT * FROM members
                       WHERE username = '$username'");
if (mysql_num_rows($result) == 0)
{
    include ("header.php");
}
else 
    include ("loginHeader.php");

?>

can anyone help me with this? Is it easier to solve as above with mySql or is it easier to create a php function and then call it on the respective page?

4
Contributors
7
Replies
8
Views
5 Years
Discussion Span
Last Post by rogerg
0

Ove way to do this would be.

You should set a session_start(); at the beginning of your script.
If mysql_num_rows() returns > 0 then set a $_SESSION, then if your Session isset() then you can load the desired header.

1

Do you still need help? i created one of these and it took me sometime to figure it out. Let me know if you still need help.

Votes + Comments
Hello aflor, yes I still need help. I hadn't been looking into it for a few days
0

thanks for the input. I'm still struggling a bit
I've tried it this way

<?PHP session_start();

$username = $_SESSION['username'];

 // Connects to your Database 
     mysql_connect(...) or die(mysql_error()) ; 
     mysql_select_db("...") or die(mysql_error()) ; 

 $result = mysql_query("SELECT * FROM members
                       WHERE username = '$username'");
if (mysql_num_rows($result) > 0)
    $_SESSION['username'] = true;
{

    if ((isset($_GET['header'])) AND $_SESSION[''] = true AND file_exists($_GET['header'].'.php'))

    {   
        include $_GET['header'].'.php';
    }
    else
    {

        include 'loginHeader.php';
    }
?>

with this I get a Parse error: syntax error, unexpected $end in

what am I doing wrong?

1

well you have to pass your form value into a variable to pass it to a session $username = $_GET['username'] and then use the $_SESSION['username'] = $username; or $_GET['username'] = $_SESSION['username'];

Edited by Szabi Zsoldos

0

thanks for your answers - I maybe have to check the variables stored as I always end up with the header in the if clause and never get the one in the else clause

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.