behrk2 Posted October 4, 2007 Share Posted October 4, 2007 Hey guys, So here is my question. I have a login.php, members.php and members.html. Right now, if you login successfully you are taken to members.php. I want to display the users name upon successful login. I can do this in members.php, however I want to display it in members.html (because in HTML pages I can make layout tables/cells). I store the users first name (f_name) and last name (l_name) in session variables with the following code (from login.php): while ($info = mysql_fetch_array($query)) { $f_name = stripslashes($info['f_name']); $l_name = stripslashes($info['l_name']); } if (mysql_num_rows($query)<1) { header("Location: failed.html"); } else { $_SESSION["username"]; $_SESSION["password"]; $_SESSION['auth'] = "yes"; $_SESSION['f_name'] = $f_name; $_SESSION['l_name'] = $l_name; header("Location: members.html"); } In members.php, I display the name with this code: print "Welcome, "; print $_SESSION['f_name']; print " "; print $_SESSION['l_name']; print "!"; Now, I want to do this in members.html. So i added the following line to my httpd.conf file for apache AddType application/x-httpd-php .html .php Now, when I login and go to members.html, I get the following result: "Welcome, !" How can I successfully show the name of the person logged in? Thanks! Quote Link to comment Share on other sites More sharing options...
trq Posted October 4, 2007 Share Posted October 4, 2007 I want to display it in members.html (because in HTML pages I can make layout tables/cells). Just as you can in php pages. Can we see your actual code for members.html? You need to make sure you call session_start() prior to using the $_SESSION array. Also, this... print "Welcome, "; print $_SESSION['f_name']; print " "; print $_SESSION['l_name']; print "!"; need only be as simple as.... print "Welcome, {$_SESSION['f_name']} {$_SESSION['l_name']}!"; Quote Link to comment Share on other sites More sharing options...
behrk2 Posted October 4, 2007 Author Share Posted October 4, 2007 Whenever I add the session_start(); to my members.html page, the name is displayed however I recieve the following error: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\RLMS\members.html:14) in C:\xampp\htdocs\RLMS\members.html on line 21 Welcome, Kevin Behr! Here is the code for my members.html: <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <div align="left"> <table width="100%" border="0" cellspacing="0" cellpadding="0" background="imx/RedGrey_blank.gif"> <tr> <td width="100%" nowrap><img src="images/banner_left.jpg" width="190" height="94"><img src="images/banner_middle.jpg" width="380" height="94"><img src="images/banner_right.JPG" width="190" height="94"></td> </tr> </table> <div align="center"></div> </div> <p align="left"><img src="images/title.jpg" width="450" height="50"><br> <?php session_start(); print "Welcome, "; print $_SESSION['f_name']; print " "; print $_SESSION['l_name']; print "!"; ?> <br> <br> </p> </body> </html> Here is the code for my members.php, where everything works fine: <?php session_start(); if (@$_SESSION['auth'] != "yes") { header("Location: index.html"); echo "Please Log-in!"; exit(); } ?> <style type="text/css"> <!-- .style1 { font-family: Geneva, Arial, Helvetica, sans-serif; font-weight: bold; font-size: 10px; } --> </style> <div align="left"> <table width="100%" border="0" cellspacing="0" cellpadding="0" background="imx/RedGrey_blank.gif"> <tr> <td width="100%" nowrap><img src="images/banner_left.jpg" width="190" height="94"><img src="images/banner_middle.jpg" width="380" height="94"><img src="images/banner_right.JPG" width="190" height="94"></td> </tr> </table> <div align="center"></div> </div> <p align="left"><img src="images/title.jpg" width="450" height="50"><br> <span class="style1"> <?php print "Welcome, "; print $_SESSION['f_name']; print " "; print $_SESSION['l_name']; print "!"; ?> </span></p> <p><br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> Leaving? <a href="logout.php">Logout.</a></p> Thanks! Quote Link to comment Share on other sites More sharing options...
trq Posted October 4, 2007 Share Posted October 4, 2007 session_start() needs to be before any output. Put this at the very top of the member.html page. <?php session_start(); ?> Quote Link to comment Share on other sites More sharing options...
behrk2 Posted October 4, 2007 Author Share Posted October 4, 2007 that did it, thanks so much! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.