Jump to content

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

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.