Using Inline PHP with $_Session
Question by dpDesignz
I’m taking a crack at my PHP again but I’ve gotten stuck on some inline. I’m using a members script which I learnt at http://www.1stoptutorials.com/Membership_Course.html.
My table has the following fields: userid, first_name, last_name, email_address, username, password, dob, guardianid, user_level, signup_date, last_login, activated.
What I’m wanting to do is use data from my table when the user logs in, but for some reason all that I’m able to access for some reason is the first name and last name fields. None of the others are working.
This is my current PHP in the header
<?php
require_once ('verify.php');
// Start output buffering:
ob_start();
// Initialize a session:
session_start();
// If no first_name session variable exists, redirect the user:
if (!isset($_SESSION['first_name'])) {
$url = BASE_URL . ''; // Define the URL.
ob_end_clean(); // Delete the buffer.
header("Location: $url");
exit(); // Quit the script.
}
?>
and it’s being closed in the bottom. Now to login, they use their username and password, but I want to know why I can only use their first and last names? Also how do I embed inline? I’m using the following currently.
<p style="color:White;">
Welcome
<strong>
<a href="profile.php?id=<? echo $_SESSION['userid'] ?>" style="font-family:Arial, Helvetica, sans-serif;color:White;">
<? echo $_SESSION['first_name'] ." ". $_SESSION['last_name'] ?>
</a>
</strong>
- Home |
<a href="photo.php" class="link">Photos</a>
|
<a href="video.php" class="link">Videos</a>
|
<a href="logout.php" class="link">Log Out</a>
</p>
But of course only the names are coming up in my output page, not the id or any other fields.
Can anyone help or do I need to post some more info?
Or can anyone suggest a better login script?
Answer by Starx
Just because the script you learned from told you to only use first_name
does not mean you have to keep on using the same thing. You can use any field you used while storing the data. Most efficient will be storing user_id
.
About the inline part, it is debatable. Some prefer inline PHP, some inline HTML. Use what makes you more comfortable.