Jump to content

[SOLVED] Displaying PHP in HTML


behrk2

Recommended Posts

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!

Link to comment
Share on other sites

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']}!";

Link to comment
Share on other sites

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!

Link to comment
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.