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

Help seeing Session vars from Include scipts

P: n/a
I am new to php and need some help getting the session variables into
include files. (after-thought, Sorry for the drawn out post but I
really, really need help....;)

Here's what I'm doing..

I have a php request_form that I use 2 different ways: by itself (url
directly to the form) and as an include to be displayed in existing
php pages. This form uses POST to another php_script that performs
serverside validation and db write. If all go's well then a write to a
mySQL table and a redirect to a confirm page. I have been using this
form for months and it works great.

Here's what I'm having trouble with..(I'm now 'trying' to use Sessions
and query strings)

I am using _GET to retrieve query-string vars to set as _SESSION vars
to eventually be written to the db with the form data. When I use the
form by itself (direct url), everything works like a charm! The
session vars are available to the serverside script and are written
the db. If I use it as an include in an existing page, neither the
form or the serverside script can access the session vars, although
the 'existing page' and the confirm page can!

The session vars are there through out the whole process because the
confirm page is the last step and the session vars are there and
available. Why can't I use see the session vars when the form is used
as an include??

Any help or direction would be GREATLY appreciated. I have searched
and the boards for hours with no luck.

James

Setup:
FreeBSD 4.4
PHP 4.3.0
Register Globals - off
session.auto_start - off
session.save_handler - files
session.use_cookies - on
session.use_trans_sid - on

Code (when using form as an include absolute url is used with
require())
/////////////////////////////////////////////////////////////////////
Top of 'an existing' php page:
<?php
session_start();
$_SESSION['session_cmpid'] = $_GET['cmpid'];
$_SESSION['session_engid'] = $_GET['engid'];
$_SESSION['session_kwid'] = $_GET['kwid'];

$campaign=$_SESSION['session_cmpid']; 'I placed this here as a test.
echo 'Campaign is '.$campaign;
?>
///////////////////////////////////////////////////////////////////////
Top of form script:
<?php
session_start();
$_SESSION['session_cmpid'] = $_GET['cmpid'];
$_SESSION['session_engid'] = $_GET['engid'];
$_SESSION['session_kwid'] = $_GET['kwid'];

$campaign=$_SESSION['session_cmpid']; 'I placed this here as a test.
echo 'Campaign is '.$campaign;
?>
//////////////////////////////////////////////////////////////////////
Top of serverside script:
<?php
session_start();
if (!isset($_SESSION['session_cmpid']))
{
$campaign="100"; //Internet Request
}
else
{
$campaign=$_SESSION['session_cmpid']; //Session Campaign
}

$engid=$_SESSION['session_engid'];
$kwid=$_SESSION['session_kwid'];
//////////////////////////////////////////////////////////////////////
Top of confirm page:
<?php
session_start();
$campaign=$_SESSION['session_cmpid']; 'I placed this here as a test.
echo 'Campaign is '.$campaign;
////////////////////////////////////////////////////////////////////
Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.