Forum Moderators: coopster
with the following code:
<?
if
($_SESSION['CustomerID'] == "")
{
echo "<a href='faqs.php'>Frequently Asked Questions Page</a>";
}
else
{
echo "<a href='faqs.php'>Frequently Asked Questions Page</a>";
}{
session_unregister("CustomerID");
session_unregister("UserID");
session_unregister("FirstName");
session_unregister("AccessLevel");
session_destroy();
}
?>
MY PROBLEM IS THIS: I DO NOT WANT TO DESTROY THIS SESSION VARIABLE UNLESS THE USER CLICKS ON THE <A HREF='FAQS.PHP'> LINK. IF THE USER DOES NOT CLICK ON THIS LINK, I WANT THE SESSION TO CONTINUE. ANY SUGGGESTIONS?
To determine whether the session has been created:
if (isset($_SESSION['CustomerID'])) { Add a tag to your FAQ link code to identify whether the session had been established, at that point:
<a href="faq.php?sid=1">FAQ</a> or <a href="faq.php?sid=0">FAQ</a> Then, put the "session_destroy" code on the FAQ page, instead of the page with the FAQ link. Since PHP has no idea what happens after the page has left the server, it has no way of determining whether the link will be clicked or not.
1 - User arrives at current page
2 - Check for session, and write appropriate FAQ page link
3 - User clicks FAQ link:
3a: On FAQ page,
if ($sid) { destroy } So, on the first page in this example:
<? if (isset($_SESSION['CustomerID'])) { echo "<a href='faqs.php?sid=1'>Frequently Asked Questions Page</a>"; } else { echo "<a href='faqs.php?sid=0'>Frequently Asked Questions Page</a>"; } ?> On the FAQ page:
<? if ($sid) { session_destroy ... etc. } ?>
<?
if (isset($_SESSION['CustomerID']))
{
echo "<a href='faqs.php?sid=1'>Frequently Asked Questions Page</a>";
}
else {
echo "<a href='faqs.php?sid=0'>Frequently Asked Questions Page</a>";
}
?>
AND on the FAQS.php page, I have this code in the heading:
<?
if ($sid) {
session_unregister("CustomerID");
session_unregister("UserID");
session_unregister("FirstName");
session_unregister("AccessLevel");
session_destroy();
}
?>
<? session_start();?>
The page is not destroying the session. Any ideas? PLEASE NOTE: I need to have the session_start code on the page because I have an email_submit piece of php code that uses it.