Solved

What does "$_SESSION['index.php']" mean?

Posted on 2010-09-03
8
662 Views
Last Modified: 2012-08-14
Hello,

I have a bit of code I am trying to modify, and it references page names as sessions all over the place.  Take for example:
if ($_SESSION['index.php'] != '') {
.. }

I try to print the session to the screen so I can see it, but using echo, print, print_r doesn't display anything.  In general use what do these sessions store? How can I print its contents?

Thanks, Liz
0
Comment
Question by:maeve100
8 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 33600271
That's a 'session variable'.  http://www.php.net/manual/en/reserved.variables.session.php  They can be used like 'regular' variables except that they are preserved on the server so they can be set and retrieved from different pages.  If it doesn't display anything it doesn't contain anything... in Your session.  Session variables are available only to the session that created them.  Without looking at the files on the server, you can't see someone else's session variables.
0
 

Author Comment

by:maeve100
ID: 33600299
Sorry, should have been more clear - I understand that its a session variable - but what is the significance of the index.php?  I see a bunch that reference page names in the files.  Is there something special to that? Or is it just a variable name that happens to match a page name that is being used?
0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 167 total points
ID: 33600340
I wouldn't know, everybody gets to make up their own stuff.  It is "a variable name that happens to match a page name that is being used" but I don't know of any further significance.  If they're using it to track users on the site, you might see it used to put data in a database.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 17

Expert Comment

by:nanharbison
ID: 33600454
Can you echo it out so you can see what value it is holding? Is this in a CMS, so it is holding which template to use or something?
0
 
LVL 18

Assisted Solution

by:Matthew Kelly
Matthew Kelly earned 167 total points
ID: 33600661
It just a variable name that happens to match a page name that is being used. There is nothing special. To php, the 'index.php' is just characters, and if you changed every place SESSION["index.php"] was used to SESSION["user"], the code would function the same.

If printing it does nothing, it just means it wasn't initialized, which may or may not be an issue depending on what the code is supposed to do with it.
0
 
LVL 11

Expert Comment

by:Bruce Smith
ID: 33601962
You need to echo it at several points throughout the web-application to see exactly what it is being used for. Kind of looks like the session variable is for tracking site usage or something.
0
 
LVL 109

Assisted Solution

by:Ray Paseur
Ray Paseur earned 166 total points
ID: 33602902
Here is what I would do...

1. Make sure you understand how PHP sessions work.  There are only a few functions - read the man pages for all of them, starting here.
http://us.php.net/manual/en/function.session-start.php

2. Get a code scanner (most text editors have them - something like "find in files") and search the code library for case-sensitve instances of $_SESSION.  Keep this list of search results handy.

3. Make sure that every page you want to inspect has session_start() right at the top.  Add error_reporting(E_ALL); to these scripts.

4. Modify the footer of your test page to contain this PHP code at the very end of the page.

You will be able to see the contents of the session array with that.  Hopefully between knowing where the $_SESSION array is used in the code, and what it contains at the end of the page, you'll be able to sort out the author's original intent.

<?php
// DUMP THE SESSION VARIABLES
echo "<pre>" . PHP_EOL;
var_dump($_SESSION);

Open in new window

0
 

Author Closing Comment

by:maeve100
ID: 33620147
Thats what I get for having multiple coders passing on a jumble of a project to a low level front end coder, hehe.  Thanks for helping me understand!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question