Jump to content

userid on all pages


kadamsurekha

Recommended Posts

hi friends!

i m designing a website wherein user first login to the site.

once he login he can access the other pages.

i want the username to be displayed on all the pages till he logouts.

 

but i m getting the username displayed only on the second page.

 

my code is as follows:

 

<?

$emailID=$_POST['username'];//username

$passwd=$_POST['passwd'];//password

include("config.php");//set the connection

include("opendbs.php");//selects the database

 

include("getuser.php");//validates the user

if($flag)

    include("secondpage.php");//second page opens

else

                  include("notexistpage.php");

                  //msg not existing user gets displayed

?>

 

 

i get the emailID displayed only on the second.php page n not on later pages.

wht should i do to get this work?

 

thx n regards

 

Link to comment
https://forums.phpfreaks.com/topic/43264-userid-on-all-pages/
Share on other sites

<?php //don't use quick tags
   $emailID=$_POST['username'];//username
   $passwd=$_POST['passwd'];//password
   include("config.php");//set the connection
   include("opendbs.php");//selects the database
   
   include("getuser.php");//validates the user
   if($flag)
        include("secondpage.php");//second page opens
   else
                  include("notexistpage.php");
                  //msg not existing user gets displayed
?>

 

in ur getuser.php page upon successful validation use

$_SESSION['uid'] = $userid

 

Then on everypage that you want the userid to appear on start the page with

session_start()

and where you want the username to appear type

print "Welcome, " . $_SESSION['uid']; 

however you will need to use an if statement to determine if the session variable has been set eg;

 

if(isset($_SESSION['username'])){
     print "Welcome, " . $_SESSION['uid']; 
} else {
    print "Welcome to foobar.com, please <a href=\"login.php\">Login</a> or <a href=\"register.php\">Register</a>";
}

Link to comment
https://forums.phpfreaks.com/topic/43264-userid-on-all-pages/#findComment-210072
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.