Forum Moderators: coopster

Message Too Old, No Replies

Check for login status before presenting link

         

dave1236

1:16 am on Oct 7, 2006 (gmt 0)

10+ Year Member



All:

This is what I am trying to do:

I want to present all my content to my visitors to allow them to see what I have created. But, only users who have logged in can directly access these links. If a user has not logged in, they are presented with the login page and then sent to the appropriate page.

I serve the links from a php DB - I have a php script that checks for session ID and tells someone if they have logged in or not in the body of my page, but am confused/unaware of how to add this type of functionality to my page and DB.

Is there a way to put this authentication into my DB, with the piece that where session auth = no adds the link to the login page?

<?php

if (@$_SESSION['auth']!= "yes")
{
include("incfiles/logout.inc");

} else {
include("getloginfo.inc");

echo "<html><b>

<body>

Welcome Back $firstName $lastName </b> ¦ ";
include("incfiles/welcome.inc");
}
?>

Thanks! I hope that was clear!

eelixduppy

4:12 am on Oct 7, 2006 (gmt 0)



>>>but am confused/unaware of how to add this type of functionality to my page and DB.

Well your logic is mostly already there. It should look something like this:


if(isset($_SESSION['auth']) && ($_SESSION['auth'] == "yes")) {
//connect to db
//select links from db
//print links
} else {
echo 'You must be logged in to view this page';
include('login.html');
}

Good luck!