i just store session in my register page for use it in different files when someone get registration but i dont know y in other pages when i try to call my session,i get error that the variable are undefined.
my code at register.php

<?php

$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("registration", $con);
function protect($value){
$value=mysql_real_escape_string($value);
$value=stripslashes($value);
$value=strip_tags($value);
}
$action=$_GET;
protect($action);
if (!$action){
echo "<strong>you are required to fill all field</strong>";
}
if ($action=="register"){
$firstname=$_POST;
$lastname=$_POST;
$email=$_POST;
$password=$_POST;
$r_password=$_POST;
$gender=$_POST;
$birthday='$year&$month&$day';
$MM_redirectRegisterSuccess = "signup.php";
protect($firstname);
protect($lastname);
protect($email);
protect($password);
protect($r_password);
protect($gender);
protect($birthday);
if( isset($firstname) && isset($lastname) && isset($email) && isset($password) && isset($r_password) && isset($gender) && isset($birthday)){
if($gender=='Select Gender'){
echo"select your gender";}
else{
if(strlen($firstname)<2 || strlen($firstname)>64){
echo"firstname either too short or too long!";}
else{
if(strlen($lastname)<2 || strlen($lastname)>64){
echo"lastname either too short or too long!";}
else{
if(strlen($password)<3 || strlen($password)>30){
echo"password either too short or too long!";}
else{
if(strlen($email)<5 || strlen($email)>125){
echo"email either too short or too long!";}
else {
if( !preg_match( "/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $email)) {
echo "The e-mail you entered was not in the proper format!";}
else{
if ($password!=$r_password){
echo"your password do not matched!";}
else{
if(!isset($gender)){
echo "select your gender!";}
else{
if(!isset($birthday)){
echo "select your birthday!";}
else{
$sql="SELECT * FROM signup WHERE email='$email'";
$result=mysql_query($sql) or die (mysql_error());
if (mysql_fetch_array($result)>0){
echo "this email already exists!";}
else{
if(!$_POST || !$_POST || !$_POST || !$_POST || !$_POST || !$_POST || !$_POST ){
echo "You didn't fill in all required field!";}
else{
$sql="INSERT INTO signup (firstname,lastname,email,password,r_password,gender,birthday)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[email]','$_POST[password]','$_POST[r_password]','$_POST[gender]','$_POST[birthday]')";
?>
<?php
session_start();
$_SESSION='$firstname';
$_SESSION='$lastname';
$_SESSION='$email';
$_SESSION='$gender';
$_SESSION='$birthday';
?>
<?php
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}else{
header("Location: ". $MM_redirectRegisterSuccess );
}

}
}
}
}
}
}
}
}
}
}
}
}
}
mysql_close($con)
?>
i try to call my session in signup.php but i got error!please if i have mistake in my session code just correct me!
home.php page
code here under
<?php
session_start();
echo "welcome".$_SESSION." ".$_SESSION;
session_unset();
session_destroy();

?>

in the begining (or before using session variable) of all pages make sure you write

session_start();

the first code in ur script must be session_start();
to do this just copy my code and write it just at the beginning of ur code...

<?php
session_start();
?>

Hope ur problem might be solved....if any problem persist PM me....

whats new in your post totmato.pgn

i think so u have not read the policy n posting technique...go n read n then speak to me...
code must be within code tag....

i think so u have not read the policy n posting technique...go n read n then speak to me...
code must be within code tag....

ok!i got u!i did mistake!and now i put code like here under but session do not display in onother page

<?php
session_start();
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$email=$_POST['email'];
$gender=$_POST['gender'];
$birthday=$_POST['birthday'];
$_SESSION['firstname']='$firstname';
$_SESSION['lastname']='$lastname';
$_SESSION['email']='$email';
$_SESSION['gender']='$gender';
$_SESSION['birthday']='$birthday';
session_unset();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
</head>
<body>
<?php
$con = mysql_connect("localhost","root","kilombo7");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("registration", $con);
function protect($value){
$value=mysql_real_escape_string($value); 
$value=stripslashes($value);
$value=strip_tags($value);
}
$action=$_GET['act'];
protect($action);
if (!$action){
echo "<strong>you are required to fill all field</strong>";
}
if ($action=="register"){
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$email=$_POST['email'];
$password=$_POST['password'];
$r_password=$_POST['r_password'];
$gender=$_POST['gender'];
$birthday='$year&$month&$day';
$MM_redirectRegisterSuccess = "signup.php";
protect($firstname);
protect($lastname);
protect($email);
protect($password);
protect($r_password);
protect($gender);
protect($birthday);
if( isset($firstname) && isset($lastname) && isset($email) && isset($password) && isset($r_password) && isset($gender) && isset($birthday)){ 
if($gender=='Select Gender'){
echo"select your gender";}
else{
if(strlen($firstname)<2 || strlen($firstname)>64){
echo"firstname either too short or too long!";}
else{  
if(strlen($lastname)<2 || strlen($lastname)>64){
echo"lastname either too short or too long!";}
else{  
if(strlen($password)<3 || strlen($password)>30){
echo"password either too short or too long!";}
else{  
if(strlen($email)<5 || strlen($email)>125){
echo"email either too short or too long!";}
 else {
  if( !preg_match( "/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $email)) { 
  echo "The e-mail you entered was not in the proper format!";}
else{
 if ($password!=$r_password){
 echo"your password do not matched!";}
 else{
 if(!isset($gender)){
 echo "select your gender!";}
 else{
 if(!isset($birthday)){
 echo "select your birthday!";}
 else{
 $sql="SELECT * FROM signup WHERE email='$email'";
 $result=mysql_query($sql) or die (mysql_error());
 if (mysql_fetch_array($result)>0){
 echo "this email already exists!";}
 else{
 if(!$_POST['firstname'] || !$_POST['lastname'] || !$_POST['email'] || !$_POST['password'] || !$_POST['r_password'] || !$_POST['gender'] || !$_POST['birthday'] ){
  echo "You didn't fill in all required field!";}
else{
$sql="INSERT INTO signup (firstname,lastname,email,password,r_password,gender,birthday)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[email]','$_POST[password]','$_POST[r_password]','$_POST[gender]','$_POST[birthday]')";
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }else{
header("Location: ". $MM_redirectRegisterSuccess ); 
}

                                       }
                                   }
                               }
                          }
                      }
                 }
             }
         }
     }
   }
 }
}
} 
mysql_close($con)
?>

</body>
</html>
Member Avatar for diafol

Use the [ CODE ] tag man.

1. Hey Brother please use function functionName($argumentHere) OR class so that your code may look clean.
2. remove the session_unset() on the top because you now removing the session.
3. Set your session.
example: $SESSION = $variable;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.