i start a new session with : session_start();
then i set some session variable like this :
$_SESSION['name']=$_POST['name'];\
and some another variables.
at bottom of page i set header to diffrent page :
header('location: index.php');
exit();
now in new page (index.php i can't access to my session
variables, like $_SESSION['name'])
what's wrong ?
thanks.



here is my files :

a.php

========================================

session_start();

require ('config.inc.php');
if(isset($_POST))
foreach($_POST as $v=>$k)
{
$items[$v]=$k;
}

$sql="SELECT * FROM members WHERE
username='{$items['user']}' AND
pass=MD5('{$items['Password']}') ";
$res=mysql_query($sql);
$row=mysql_fetch_assoc($res);
if($row['username'])
{ $_SESSION['type']=$row['type'];
$_SESSION['name']=$row['name'];
$_SESSION['family']=$row['family'];
$_SESSION['username']=$row['username'];
$_SESSION['date']=$row['date'];

}

header('location: admin.php');
exit();

======================================

admin.php

=====================================

<?php
session_start();
if(!isset($_SESSION['admin']))
{
header('location: index.php');
exit();
}
require ('config.inc.php');

?>

.

.

.

=================================

Answer Posted / jose martini

I created 4 files:
start.php
admin.php
index.php
sessionend.php

Code:
====================
<?php
/* File: start.php
*/
session_start();

$_SESSION['name']= "Jose";
$_SESSION['lastname']= "Martini";

echo "Start:" . $_SESSION['name'];

header('location: admin.php');

exit();
?>
=================
<?php
session_start();

echo "Admin";
if (isset ($_SESSION['name'])) {
header('location: index.php?'.$_SESSION['name']);
}
else {
echo "Admin: No Session";
}
exit ();

?>
================
<?php
/*
*/
session_start();

if (isset ($_SESSION['name'])) {
echo $_SESSION["name"];
}
else {
echo "Index: no Session";
}

exit();
?>
=======
<?php
/*
*/
session_start();
session_destroy();

echo "End Session";

?>
================

I tried to reproduce the error, the only way that the
session is not available is if you miss to start the session
or to initialized the session variable.

the exit() does not affect the result.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a controller in php?

549


Is apache needed for php?

500


what is variable scope, which variables are accessible from where and what are "undefined variable" errors?

500


Does php 5 support exceptions?

674


Is php deprecated?

526






Explain me what is the use of 'print' in php?

522


What are the php functions?

540


What is the difference between array_pop() and array_push()?

623


How do http requests work?

494


what are the differences between php and perl

1603


How to read one character from a file?

536


What the difference between the 'bitwise and' operator and the 'logical and' operator?

516


How to call php function from javascript using ajax?

514


How does php and apache work?

528


What is the default session time in php?

525