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 / muthu

Ravis answer is correct. But sessions wont be closed. It
will be active till the browser closes. OR if($row
['username']) fails that session variable wont be created.
Better you should assign like $_SESSION['name']=''.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do you execute a php script from the command line?

527


Why session is required?

526


How to download and install php for windows?

556


Php error constants and their descriptions

582


in PHP for pdf which library used?

560






What is the use of $_server and $_env?

575


What are php keywords?

538


What are the advantages of php?

541


What is strcmp?

526


Is php coding easy?

507


What is faster?

563


What is form validation in php?

530


Is multilevel inheritance possible in php?

506


What is the use of header() function in php?

551


How to include a file to a PHP page?

593