kadamsurekha Posted March 18, 2007 Share Posted March 18, 2007 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 More sharing options...
shaunrigby Posted March 18, 2007 Share Posted March 18, 2007 Place session_start() at the top of every page before anything Link to comment https://forums.phpfreaks.com/topic/43264-userid-on-all-pages/#findComment-210057 Share on other sites More sharing options...
DeathStar Posted March 18, 2007 Share Posted March 18, 2007 yes do that but you can also use sessions to store the username/id Link to comment https://forums.phpfreaks.com/topic/43264-userid-on-all-pages/#findComment-210061 Share on other sites More sharing options...
shaunrigby Posted March 18, 2007 Share Posted March 18, 2007 <?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 More sharing options...
DeathStar Posted March 18, 2007 Share Posted March 18, 2007 Try not to use the session liek that: $userid= $_SESSION['uid']; Link to comment https://forums.phpfreaks.com/topic/43264-userid-on-all-pages/#findComment-210103 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.