Session variable index error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fitchic77
Forum Commoner
Posts: 51
Joined: Thu Jul 20, 2006 11:57 pm

Session variable index error

Post by fitchic77 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


url would be
/localhost.com/index.php?action=TEST1

//index.php

Code: Select all

session_start();
if ($action  == "TEST1") { 
include("test1.php");						
} elseif ($action  == "TEST2") {  //edit user sales
include("test2.php");
}

//form test1.php
$_SESSION['logged'] = "logged";
echo $_SESSION['logged'] ;

//form test2.php
echo "here" . $_SESSION['logged'];

Code: Select all

RECEIVE error and my session is not defined
Notice: Undefined index: logged in C:\Program Files\Apache2\htdocs\test\test2.php on line 3



feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Last edited by fitchic77 on Sat Oct 16, 2010 11:33 am, edited 1 time in total.
User avatar
SpecialK
Forum Commoner
Posts: 96
Joined: Mon Sep 18, 2006 3:49 pm

Post by SpecialK »

in index.php $action isn't set.

test2.php doesn't set
$_SESSION['loggedTest'] = "Test";

while test1.php does set it.

Using isset() is the way to check this without getting any warning errors prior to using the index of loggedAndrea
fitchic77
Forum Commoner
Posts: 51
Joined: Thu Jul 20, 2006 11:57 pm

Post by fitchic77 »

Sorry I was cutting and pasting the code and left this out. The issue is the session variable not setting right.

Code: Select all

$action = $_REQUEST['action']

thanks.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

is there a session_start() in test2.php, too?
fitchic77
Forum Commoner
Posts: 51
Joined: Thu Jul 20, 2006 11:57 pm

Post by fitchic77 »

doesn't have to be because everything is ran through index.php which has it...

I have it working now...not sure what the hangup was...

thanks.
Post Reply