By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,009 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

creating a session variable on every page

P: n/a
Hi,

I'm using PHP 4.4.4 with Apache 2.2. What I want is that if a
customer visits any page of the top level directory of my site with
this string passed in the URL's query string, "RID=xxx", I would like
a session variable called "RID" with the value "xxx" to be created.
However, I would like to avoid putting this code

session_start();
if (!empty($_REQUEST['RID'])) {
$_SESSION['RID'] = trim(strtoupper($_REQUEST['RID']));
} // if

on every page in my top level directory. Does anyone know a more
efficient way?

Thanks, - Dave

May 23 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Wed, 23 May 2007 14:43:24 -0700, la***********@zipmail.com wrote:
Hi,

I'm using PHP 4.4.4 with Apache 2.2. What I want is that if a customer
visits any page of the top level directory of my site with this string
passed in the URL's query string, "RID=xxx", I would like a session
variable called "RID" with the value "xxx" to be created. However, I
would like to avoid putting this code

session_start();
if (!empty($_REQUEST['RID'])) {
$_SESSION['RID'] = trim(strtoupper($_REQUEST['RID']));
} // if

on every page in my top level directory. Does anyone know a more
efficient way?

Thanks, - Dave
Read up on require_once.
May 23 '07 #2

P: n/a
la***********@zipmail.com wrote:
Hi,

I'm using PHP 4.4.4 with Apache 2.2. What I want is that if a
customer visits any page of the top level directory of my site with
this string passed in the URL's query string, "RID=xxx", I would like
a session variable called "RID" with the value "xxx" to be created.
However, I would like to avoid putting this code

session_start();
if (!empty($_REQUEST['RID'])) {
$_SESSION['RID'] = trim(strtoupper($_REQUEST['RID']));
} // if

on every page in my top level directory. Does anyone know a more
efficient way?

Thanks, - Dave

Two things:

1. There is an Apache auto_prepend directive you can put in htaccess (or
httpd.conf).

2. Use mod_rewrite to redirect certain?/all? files to a script that does
your session check and then includes the requested file

--
*****************************
Chuck Anderson Boulder, CO
http://www.CycleTourist.com
*****************************
May 23 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.