Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Include +Sessions

Status
Not open for further replies.

caffrinho

MIS
Mar 1, 2002
91
GB
Please help, this is driving me nuts!

Basically, i have an include file that checks for a value set in a session variable. But it will always return a blank value.

I can get it working if i copy everything out of the include file and paste it into the file i'm calling it from without a problem. But since i will need this script in every one of my pages, i hoped to use an include.

I've searced the web/google groups but not found anything relating to this issue that was resolved.

Any suggestions?

TIA

Caff

Index.php
Code:
<?php
session_start();

echo("season: ".$_SESSION['seas']);

?>
<br /><a href="main.php?s=1">1</a>
<br /><a href="main.php?s=2">2</a>

main.php
Code:
<?php
session_start();
$s = $_GET['s'];
$_SESSION['seas']=$s;

header("location: index.php");
?>

This works fine, if however i use the following as index.php, it returns a blank value for the session variable
Code:
<?php

include("include.php");

echo("season: ".$s);

?>
<br /><a href="main.php?s=1">1</a>
<br /><a href="main.php?s=2">2</a>

using include.php
Code:
<?php
session_start();

$s = $_SESSION['seas']);

?>

These files have been vastly simplified in my effort to get to the bottom of this problem.
 
The second version of your code, once I removed the spurious parenthesis in this line:

$s = $_SESSION['seas']);

worked for me.

What version of PHP are you running with which web server?


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Thanks for info...

I can't believe i missed that! It does work on my system if i remove the bracket.

Must mean i have another typo in my actual include somewhere, i'll just have to go through it character by character.

not that it matters now, but i'm running PHP 4.3.1 on Apache 2.0.45

Thanks again!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top