Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.