Connecting Tech Pros Worldwide Help | Site Map

session checking for login

Newbie
 
Join Date: Sep 2007
Location: indonesia
Posts: 25
#1: Sep 26 '07
Hi theScripts!
I have a problem with my session.

When user login in my site, the session will save the user name and password. In my Login.php I have:
Expand|Select|Wrap|Line Numbers
  1. session_start();
  2.      $qr="SELECT*FROM tbllogin WHERE nama='$_POST['nama']' AND password='$_POST['password']' ";
  3.     $res=mysql_query($qr);
  4.     $row=mysql_fetch_assoc($res);
  5.    $num=mysql_num_rows($hasil);
  6.  
  7.     if($num!=0)
  8.  
  9.     {    
  10.     $Username="$row[nama]";
  11.     $Passwd="$row[password]";
  12.     session_register("Username","Passwd");
  13.     header ("Location: Home.php");
  14.     }
  15.     else
  16.     {
  17.         header("Location:LoginFailed.html");
  18.     }
  19.  
And everything is fine. The session is saved, because I've checked it C:\webserver\Apache2.2\bin\php\datasession (it is the directory where my session.save_path refers to.)

Then, in my Home.php I have:
Expand|Select|Wrap|Line Numbers
  1. include "ceksesi.php";
  2. // bla bla
  3.  
In ceksesi.php I have:
Expand|Select|Wrap|Line Numbers
  1. <?
  2. session_start();
  3. if(!session_is_registered(Username) && !session_is_registered(Passwd))
  4.   {
  5.      header("location:Login.html");
  6.   }
  7. ?>   
  8.  
When Logout is pressed, the session is deleted (also, the file in ...\datasession is deleted )
Here is the code of my Logout.php :
Expand|Select|Wrap|Line Numbers
  1. session_start();
  2. session_unregister("Username");
  3. session_unregister("Passwd");
  4. session_destroy();
  5.  
The problem is, the user can open the Home.php without login. Is there any suggestion? I don't know what's wrong with my ceksesi.php.

Thanks b4...
Newbie
 
Join Date: Sep 2007
Location: indonesia
Posts: 25
#2: Sep 27 '07

re: session checking for login


Quote:

Originally Posted by momogi

Hi theScripts!
I have a problem with my session.

When user login in my site, the session will save the user name and password. In my Login.php I have:

Expand|Select|Wrap|Line Numbers
  1. session_start();
  2.      $qr="SELECT*FROM tbllogin WHERE nama='$_POST['nama']' AND password='$_POST['password']' ";
  3.     $res=mysql_query($qr);
  4.     $row=mysql_fetch_assoc($res);
  5.    $num=mysql_num_rows($hasil);
  6.  
  7.     if($num!=0)
  8.  
  9.     {    
  10.     $Username="$row[nama]";
  11.     $Passwd="$row[password]";
  12.     session_register("Username","Passwd");
  13.     header ("Location: Home.php");
  14.     }
  15.     else
  16.     {
  17.         header("Location:LoginFailed.html");
  18.     }
  19.  
And everything is fine. The session is saved, because I've checked it C:\webserver\Apache2.2\bin\php\datasession (it is the directory where my session.save_path refers to.)

Then, in my Home.php I have:
Expand|Select|Wrap|Line Numbers
  1. include "ceksesi.php";
  2. // bla bla
  3.  
In ceksesi.php I have:
Expand|Select|Wrap|Line Numbers
  1. <?
  2. session_start();
  3. if(!session_is_registered(Username) && !session_is_registered(Passwd))
  4.   {
  5.      header("location:Login.html");
  6.   }
  7. ?>   
  8.  
When Logout is pressed, the session is deleted (also, the file in ...\datasession is deleted )
Here is the code of my Logout.php :
Expand|Select|Wrap|Line Numbers
  1. session_start();
  2. session_unregister("Username");
  3. session_unregister("Passwd");
  4. session_destroy();
  5.  
The problem is, the user can open the Home.php without login. Is there any suggestion? I don't know what's wrong with my ceksesi.php.

Thanks b4...

Please....

:)
Newbie
 
Join Date: Sep 2007
Location: indonesia
Posts: 25
#3: Sep 27 '07

re: session checking for login


to all of thescripts's members...

I wanna tell you that my question is solved.
it was just a simple mistake...

--thanks--

:D
Reply