Solved

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

Posted on 2010-09-03
8
653 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 82

Expert Comment

by:Dave Baldwin
Comment Utility
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
Comment Utility
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 82

Accepted Solution

by:
Dave Baldwin earned 167 total points
Comment Utility
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
 
LVL 17

Expert Comment

by:nanharbison
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 18

Assisted Solution

by:Matthew Kelly
Matthew Kelly earned 167 total points
Comment Utility
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:patsmitty
Comment Utility
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 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 166 total points
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now