0

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

3
Contributors
7
Replies
8
Views
5 Years
Discussion Span
Last Post by baig772
0

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

if(!session_id())
   {
   session_start();
   }
0

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.

Edited by subrata_ushasi: responding to a post

0

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))
{
unset($_SESSION);
}
session_destroy();
header("location:index.php");
?>
and that's it.
Subrata
skype id :subrata.nandi4

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.