Jump to content

isset


pranshu82202

Recommended Posts

i Have two page login.php and verify.php

 

In login.php user is entering Username and Password and in the action of the form i am writing verify.php.

 

If verification is a success then i will start a session()

 

session_start();

$_SESSION['ls']="loggedin";   // ls stands for login status
$_SESSION['id']=$row['id'];
$_SESSION['user_name']=$row['user_name'];
$_SESSION['email']=$row['email'];
header('location : members.php');
die (" ");

 

and will redirect them to members.php

....

 

Everything is working fine...

 

But in login.php i have written a code on the top...

 

<?php
if(isset($_SESSION['ls']) && isset($_SESSION['id']) && isset($_SESSION['user_name']) && isset($_SESSION['email']) )
{
header('location:members.php');
die(" ");

}
?>

 

I want if a session is started and if user will access login.php they will automatically go to members.php

 

But this script is not working...

 

Iam not getting whats the problem...

also i m not getting any error login.php or anything

 

 

CODE WRITTEN ON THE TOP OF members.php IS :

 

<?php
session_start();
if(@$_SESSION['ls']!=="loggedin" ) // Checks if the person has done stage one (Registration.php)
{
   header('Location: login.php'); //If they haven't done it, it sends them back.
   die (" ");
}
?>

Link to comment
Share on other sites

to access any session variable, you must have session_start() at the top of the file, so login.php should be:

 

<?php
session_start();
if(isset($_SESSION['ls']) && isset($_SESSION['id']) && isset($_SESSION['user_name']) && isset($_SESSION['email']) )
{
header('location:members.php');
die(" ");

}
?>

 

in this case, you need to remove the other session_start() you have in login, or it will throw a warning.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.