Jump to content

Logged_In Display


DeanWhitehouse

Recommended Posts

<?php
if ($_SESSION['is_valid'] == true){
if ($_SESSION['user_level'] == 2){
mysql_query("SELECT * from `$user` WHERE user_name");
echo "<table class='logged_in'><tr><td>
Welcome $user_name,<br>
<a href=''>User Profile</a><br>
<a href=''>Settings</a>
<a href='logout.php'>Logout</a>
</td></tr><tr><td><font color='white'>Logged In</font></td></tr></table>";
}
if ($_SESSION['user_level'] == 1){
mysql_query("SELECT * from `$user` WHERE user_name");
echo "<table class='logged_in'><tr><td>
Welcome $user_name,<br>
<a href=''>User Profile</a><br>
<a href=''>Settings</a>
<a href='logout.php'>Logout</a>
</td></tr><tr><td><font color='white'>Logged In</font></td></tr></table>";
}
else
{
include_once'login.php';
}
}
?>

 

this code is ment to display a login form if the user is not logged in, but it doesn't, and i dunno why

Link to comment
https://forums.phpfreaks.com/topic/102076-logged_in-display/
Share on other sites

I see the problem.

The last lines look like this:

else

{

include_once'login.php';

}

}

 

Should be:

}

else

{

include_once ('login.php');

}

 

So that the else statement applies to the if ($_SESSION['is_valid'] == true){ conditional. =)

And the include should be:

include_once ('login.php');

Not:

include_once'login.php';

 

Link to comment
https://forums.phpfreaks.com/topic/102076-logged_in-display/#findComment-522572
Share on other sites

Do you mean this?

 

<?php session_start();

if ($_SESSION['is_valid'] == true){

if ( ($_SESSION['user_level'] == 1) || ($_SESSION['user_level2'] == 2) ){

	mysql_query("SELECT * from `$user` WHERE user_name='$user_name'");

	echo "<table class='logged_in'><tr><td>
Welcome $user_name,<br>
<a href=''>User Profile</a><br>
<a href=''>Settings</a>
<a href='logout.php'>Logout</a>
</td></tr><tr><td><font color='white'>Logged In</font></td></tr></table>";

}else{

include_once'login.php';
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/102076-logged_in-display/#findComment-522577
Share on other sites

when i remove the curly bracket i get this error

Parse error: syntax error, unexpected $end in /home/www/deanwhitehouse.awardspace.co.uk/logged_in.php on line 26

and you can write includes and requires without the brackets

 

You missed what I said.  Move the last } to right above the else block. >_>  Copy and paste exactly what I put. =/

Link to comment
https://forums.phpfreaks.com/topic/102076-logged_in-display/#findComment-522580
Share on other sites

ok, thanks,

this is now my working code

<?php
require_once 'includes/config_table.inc.php';
require_once 'includes/db_connect.php';
mysql_query("SELECT * from `$user` WHERE user_name='$user_name'");
if ($_SESSION['is_valid'] == true){
if ($_SESSION['user_level'] == 2){
echo "<table class='logged_in'><tr><td>
Welcome $user_name,<br>
<a href=''>User Profile</a><br>
<a href=''>Settings</a>
<a href='logout.php'>Logout</a>
</td></tr><tr><td><font color='white'>Logged In</font></td></tr></table>";
}
if ($_SESSION['user_level'] == 1){

echo "<table class='logged_in'><tr><td>
Welcome $user_name,<br>
<a href=''>User Profile</a><br>
<a href=''>Settings</a>
<a href='logout.php'>Logout</a>
</td></tr><tr><td><font color='white'>Logged In</font></td></tr></table>";
}
}
else
{
include_once ('login.php');
}
?>

how can i display the user name of the user, i am using sessions and cookies

Link to comment
https://forums.phpfreaks.com/topic/102076-logged_in-display/#findComment-522585
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.