• 3

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

PHP Session variable not getting set

In one page of our site, I have this code:

$_SESSION['returnURL'] = "/store/checkout/onepage";

and further down, this button control:

<button type="button" title="Register Today" class="button" onclick="window.location = '/register/';" id="BecomeMember"><span><span>Become a Member Today</span></span></button>

Now, in the register template, I have this code:

<input type="hidden" name="returnURL" id="returnURL" value="<?php if(isset($_SESSION['returnURL'])) { echo $_SESSION['returnURL']; } else { echo '/'; } ?>" />

But it only shows the value as /.

What could be going on that is causing this?

    • Is te register template being included with the above page an or is the variable being properly passes? What is your code for the template
      • 1
    • Various possibilities: The session is getting closed. The variable is being unset. The template is applied before session_start() is called. We would need to see more code to determine the real source of the problem.
      • 2
    • The page where I'm setting the variable is a Magento onepage checkout screen. The register template is an ExpressionEngine template. Could it be that because of the disparity of these two frameworks that they have their own sessions? How can I setup one that will be used for both>?


$_SESSION['returnURL'] = "/store/checkout/onepage";
echo '<a href="second.php">Pass session to another page</a>';


echo 'returnURL = ' . $_SESSION['returnURL'];

So you need to write session_start() in both your files

  • 12
Reply Report
      • 2
    • You need to describe the structure of your scripts more detailed: which file session starts, how you move to another file and so on. The code I writed is just general approach.
      • 2
    • Having session_start(); at the start of BOTH of my files was my issue. I had session_start(); at the beginning of my login page, but not the next page! Thanks!

To solve this problem, you will need to:

1) Ensure that session_start() is called at the beginning of the script, before anything else.

2) Nothing is unsetting $_SESSION or $_SESSION['returnURL'].

  • 2
Reply Report

What I ended up doing was sending a post variable to the page. The difference in the sessions between ExpressionEngine and Magento makes this prohibitive using session variables as well as cookies.

  • 0
Reply Report

I just fund i had the same kind of issue, sessions working fine in firefox but not chrome, i created a test script that would just create a session and then print out the session_id() in order to see if it was getting created or not, after running this script i noticed that the session_id() would change on every page load and that php was throwing a warning about the date/time not being set. I then added


to the start of the script this stoped a new session_id() from getting generated on every page load and fixed the problem. (it might be worth noting that my issue only seemed to show up on my sub domain and not the top level domain)

  • 0
Reply Report

the server I was working on was full and thus session didn't work as there was no space to store values. Make sure your server has space.

  • 0
Reply Report

I've seen many CMSes and frameworks having a different way of handling regular sessions. If the basic two-liner described above does not work (because it interferes with the current software), you can still use cookies for the same functionality. Remember, that cookies do not get deleted on closing the browser, so you need to tell it explicitly when to free up the variable (using unset).

$_COOKIE["something"] = 'value';
echo $_COOKIE["something"];
  • 0
Reply Report

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions