Hey,
I have a script that was written to login to a secure area, but I cannot get the script right that goes at the top of each page that checks to see if a session is valid before loading the page.
This is what someone else recommended, but it doesn't seem to be working and instead of a message from the PHP, I'd just like it to allow the page to be loaded. If a session is not valid, I'd like for it to have a message and show the login page.
<?
session_start();
if ( empty( $first_name ) ) {
?>
This page requires you to login before it can be viewed. Login <a href="index.htm">Here</a>.<?
} else {
echo "the pages content when logged in";
}
?>
I don't want it to show "the page content when logged in", just want the page to be visible.
Anywhere on the page, I should be able to include this to show the person's name, right?
<?
} else { include 'db.php'; echo "Welcome,
". $_SESSION['first_name'] ."";
?>
Finally, when the individual add's a news story, I'd like for his name to be inserted into the news database using his name in the session.
So, I assume this would work:
$result = mysql_query("INSERT INTO newss SET news_date = '$date', news_story = '$city', news_author = '. $_SESSION['first_name'] .'");
Is that right, or am I wrong?