Forum Moderators: coopster

Message Too Old, No Replies

Selected Hyperlinks Activate PHP script

         

shimeal

4:38 pm on Nov 16, 2004 (gmt 0)

10+ Year Member



Hello,

I have a site map page with approximately 20 different pages listed on it, 10 of which are password protected, 10 of which are not. I want the 10 non password protected page links on my site map page to execute the following PHP command when they are clicked:

<?
session_unregister("CustomerID");
session_unregister("UserID");
session_unregister("FirstName");
session_unregister("AccessLevel");
session_destroy();
?>

How do I integrate this PHP function into the following code so that, when one of these links is clicked, the PHP script above is executed:

<li class="content_text"><a href="index.php">Home Page</a> - The home page for #*$! </li>
<li class="content_text"><a href="login.php">Login Page</a> - The login page for #*$! </li>

However, I don't want the PHP script to execute when a user clicks one of these links:

<li class="content_text"><a href="index-loggedin.php">Home Page</a> - The home page of the Participant Area of xxx </li>
<li class="content_text"><a href="account_update.php">Account Information Page</a> - Update your all of your account information here </li>

All of these links are on the same site map page. How do I execute the PHP script above for only the top two hyperlinks and not for the bottom two hyperlinks?

I cannot put the PHP script in the head area of the different pages (i.e. index.php & login.php) for a variety of reasons. I need this code to be on the site map page and to execute when the hyperlink is clicked. Thanks!

uncle_bob

4:53 pm on Nov 16, 2004 (gmt 0)

10+ Year Member



If you can't add the code to the target page, then have you looked into using an interim page instead, that does the deregistering you want, and then forwards you (a 302 redirect) to the correct page (login or whatever)

shimeal

5:36 pm on Nov 16, 2004 (gmt 0)

10+ Year Member



Thanks for the quick reply.

A tried to create a 302 page (index.302.php) with the following code:

<?php
header("Location: index.php");
session_unregister("CustomerID");
session_unregister("UserID");
session_unregister("FirstName");
session_unregister("AccessLevel");
session_destroy();
?>

I then linked to this page (index.302.php) from my site map. However, it seems like the session variables aren't closing because I can still leave the password protected area via the site map for index.php and then return to the password protected area without a problem. I want to prevent people from being able to jump back and forth between the two. As a side note, the php header for index.php (which is not password protected) is this:

<? session_start();?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

The php header for a password protected page is this:

<? session_start();
if($_SESSION['CustomerID'] == "") { header("Location: login.php"); }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Any further suggestions would be greatly appreciated!

Salsa

5:53 pm on Nov 16, 2004 (gmt 0)

10+ Year Member



Building on what uncle_bob alluded to in the first part of his answer, you could put the session_unregister() functions into a unregister.inc.php file, and then include that file on pages where you wanted the functions to be called.

Or, if you are already using some kind of a top_html.inc.php to help maintain your pages and keep them uniform, you could define the conditions for calling the funtions there.

shimeal

6:04 pm on Nov 16, 2004 (gmt 0)

10+ Year Member



Could I put an if function in the unregister.inc.php page that would indicate to run the script only if the user is coming from sitemap.php? In case you can't tell, I am new at this but it would seem to me that it would cause a conflict if I put in a header code on all of my non-password protected pages (such as index.php) that said:

<?
$error = "";
include_once 'unregister.inc.php';
?>
<? session_start();?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Where unregister.inc.php would have this script:

<?php
session_unregister("CustomerID");
session_unregister("UserID");
session_unregister("FirstName");
session_unregister("AccessLevel");
session_destroy();
?>

In other words, can I put this in instead:

<?php
if (coming from sitemap.php)
then...
session_unregister("CustomerID");
session_unregister("UserID");
session_unregister("FirstName");
session_unregister("AccessLevel");
session_destroy();
?>

Thanks!

Salsa

8:04 pm on Nov 16, 2004 (gmt 0)

10+ Year Member



if ($_SERVER['HTTP_REFERER'] == "sitemap_url"){ 
session_unregister("CustomerID");
...
}

shimeal

7:01 am on Nov 18, 2004 (gmt 0)

10+ Year Member



Thanks a bunch - I got it figured out!