Jump to content

[SOLVED] session problem


simon551

Recommended Posts

Hi, I'm trying to work with a session variable from an include file in my page. I'm getting some unexpected results and I can't quite figure it out.

 

<?php 

//if there is no session and no get, then default
$cLId=-1;
//if there is a session then grab it
if(isset($_SESSION['cLId']))
{
$cLId = $_SESSION['cLId'];
}
//if this is the starting page, reset or create the session, plus the variable
if(isset($_GET['cLId']))
{
$cLId = $_GET['cLId'];
// create the session id to follow the cLId
$_SESSION['cLId']=$cLId;
}

 

If I do this:

echo $cLId;
echo $_SESSION['cLId'];

on a page with a "GET" of cLId = 25

 

it prints out 2525 which is great. But then if I do it on a page that includes the same variable function but doesn't have a 'GET' in it (just trying to utilize the SESSION)

This:

echo $cLId;
echo $_SESSION['cLId'];

Gives me -1

 

So it looks like the function I wrote doesn't take the session. Any idea what I'm doing wrong?

Link to comment
https://forums.phpfreaks.com/topic/56635-solved-session-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.