Hi everyone,

i am trying to develop a website in php by reading the discussion and tutorials available on the internet and i have completed it almost, its working well we can register and data base working well,

but problem is that i want to display user name on all the pages after login..

and i have placed a div in header.php page contained welcome message for the user.

here is code i have write in header.php page

<div id="before_login"> Hi Guest! <a href="register.php">Regiter Here</a></div>
<div id="after_login">Welcome UserName <a href="logout.php">logout</a></div>

and for the new users(new to the website) i want to display <div id="before_login"> message ,, and after login <div id="after_login"> message...

can anyone help me in this topic ...and please in simple terms ...i am new to php so please in simple terms witch i can under stand easily...


thanks.

Recommended Answers

All 4 Replies

Yes you have to use a session and post the username in the session and then to echo that sesion using somethingloke this
$_SESSION_User=POST;
<h1><?php echo $_SESSION_User;?><h1/>//put this in you pages and include the page with the session in those pages with include"something.php";
Hope it helps
HAve a nice day

commented: Useful post +7

also you can go

session_start();

$s_username = $_SESSION;

hello <?php echo $s_username; ?>

1st set session upon log-in, ex.

$_SESSION['id'] = $id // id come from database

then when you are redirected to the inner pages then query the username of the logged in user, the query whould be

mysql_query("SELECT username FROM users WHERE id=".$_SESSION['id']);

then in your page

<div id="after_login">Welcome <?php $row['username'];  ?> <a href="logout.php">logout</a></div>

1st set session upon log-in, ex.

$_SESSION['id'] = $id // id come from database

then when you are redirected to the inner pages then query the username of the logged in user, the query whould be

mysql_query("SELECT username FROM users WHERE id=".$_SESSION['id']);

then in your page

<div id="after_login">Welcome <?php $row['username'];  ?> <a href="logout.php">logout</a></div>

Hi thanks for the reply,,
that means i have to write the code

<div id="after_login">Welcome <?php $row; ?> <a href="logout.php">logout</a></div>

in all the pages of the website .

and have to hide the <div id="before_login"> Hi Guest! <a href="register.php">Regiter Here</a></div> from all the pages .. so how can i do it , please write the complete code if possible because i am new to php..

thanks again..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.