954,604 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to retain session in all pages

Hi all,
I have a login page in localhost(website link : www.csoftindia.net ) . When I logged in it is showing alternate html "you are logged in as..." but when moving another page like news or other page session is lost either or it is not destroying session.

Subrata

subrata_ushasi
Junior Poster in Training
52 posts since Aug 2008
Reputation Points: 10
Solved Threads: 5
 

Have you used session_start() in all pages ?

pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

On the header page header.php I used this code.

if(!session_id())
   {
   session_start();
   }
subrata_ushasi
Junior Poster in Training
52 posts since Aug 2008
Reputation Points: 10
Solved Threads: 5
 

it seems that you are unseting the session on next page

baig772
Junior Poster
123 posts since Mar 2011
Reputation Points: 29
Solved Threads: 6
 

Ok I am giving the user :sn@csoftindia.com and password :328023 of an website www.csoft.com where you can see the changes .
I am unsetting on the logout page.If you see the above will be clear what I want I think.

subrata_ushasi
Junior Poster in Training
52 posts since Aug 2008
Reputation Points: 10
Solved Threads: 5
 

i am not seeing any changes
on all pages i am seeing

logged in as:
subrata nandi
baig772
Junior Poster
123 posts since Mar 2011
Reputation Points: 29
Solved Threads: 6
 

Hi Baig ,
Yes ,this is done.
I included "include("config.php"); where session is started . Now the code written in every pages as :

if(!empty($_REQUEST['txtuser']) && !empty($_REQUEST['txtpassword']))
          {
    	  $textuser=$_REQUEST['txtuser'];
	  $texstpassword=$_REQUEST['txtpassword'];
	  $sql="select * from mytable where user='$textuser' and               password='$texstpassword'";
          $qry=mysql_query($sql);
          $row=mysql_num_rows($qry);
          $result=mysql_fetch_array($qry);
	  if($row >0)
	     {
	      $_SESSION['user']=$textuser;
	      $_SESSION['firstname']=$result['firstname'];
	      $_SESSION['lastname']=$result['lastname'];
	      }
	  }
       else
         {
         $row = 0;
         }
									  if(empty($_SESSION['textuser']))
	{
	 // NOT LOGGED IN CODE HERE
	}
else
       {
       logged code and html
       }		  
 ?>

and when logout the following code in logout.php page as follows :
<?php
include("common/config.php");
if(!isset($_SESSION['txtuser']))
{
unset($_SESSION['txtuser']);
}
session_destroy();
header("location:index.php");
?>
and that's it.
Subrata
skype id :subrata.nandi4

subrata_ushasi
Junior Poster in Training
52 posts since Aug 2008
Reputation Points: 10
Solved Threads: 5
 

that's good
please mark the thread solved :)

baig772
Junior Poster
123 posts since Mar 2011
Reputation Points: 29
Solved Threads: 6
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: