homepage Welcome to WebmasterWorld Guest from 54.166.128.254
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Cannot access $_SESSION varaibles on other pages
blacklisted

10+ Year Member



 
Msg#: 12031 posted 5:56 am on Mar 8, 2006 (gmt 0)

I am facing problem in accessing $_SESSION variables..
I have three page
1. HTML form page that accepts a usre name

2. a php page that checks the valid user name and if valid user sets a session vaiable and redirects to next page msg.php

<?php
if ($_POST['uname']=="Mad"){
session_start();
$_SESSION["uname"] =$_POST['uname'];
header('Location: msg.php');
}
else{
header('Location: login.html');
}
?>

3. and here is the third page msg.php where i am trying to print the value stored in the $_SESSION variable

<?php

echo "Hello Mr/Mrs ".$_SESSION['uname'];

?>
I cant make out whats wrong with this code..can any one help me out

 

dmmh

5+ Year Member



 
Msg#: 12031 posted 7:24 am on Mar 8, 2006 (gmt 0)

try this:

<?php
session_start();
if ($_POST['uname']=="Mad"){
$_SESSION["uname"] = addslashes($_POST['uname']);
header('Location: msg.php');
}
else{
header('Location: login.html');
}
?>

dreamcatcher

WebmasterWorld Senior Member dreamcatcher us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 12031 posted 8:07 am on Mar 8, 2006 (gmt 0)

session_start();

This needs to be at the top of every page you are calling session variables.

dc

DrDoc

WebmasterWorld Senior Member drdoc us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 12031 posted 9:19 am on Mar 8, 2006 (gmt 0)

And, you probably want to call session_write_close() before sending the header() call.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved