Session Login Problem

Reply

Join Date: Apr 2006
Posts: 20
Reputation: Ries is an unknown quantity at this point 
Solved Threads: 0
Ries Ries is offline Offline
Newbie Poster

Session Login Problem

 
0
  #1
Jun 16th, 2006
This is my code im using for my login, but when it re-directs to the next page the $_SESSION['email'] array doesnt contain any data, what is wrong with my coding that causes this(btw to check it had no data I echoed it and nothing came onto my screen)
  1. <?PHP
  2. session_start();
  3. mysql_connect("localhost", "*******", "*******")or die(mysql_error());
  4. mysql_select_db("eluxian");
  5.  
  6. $email = $_POST['email'];
  7. $pass1 = $_POST['password'];
  8.  
  9. $pass = md5($pass1);
  10.  
  11. $check = mysql_query("SELECT password FROM members WHERE email='$email'")
  12. or die("Email not found in database");
  13. $fetch = mysql_fetch_array($check) or die(mysql_error());
  14.  
  15. $password = $fetch['password'];
  16.  
  17. if ($password != $pass){
  18. echo "You entered a bad password";
  19. }else{
  20. $_SESSION['email'] = $email;
  21. echo "<meta http-equiv='Refresh' content='0;url=news.php'>";
  22. echo "Correct password. Forwarding now...";
  23. }
  24.  
  25. ?>
Last edited by Ries; Jun 16th, 2006 at 6:32 pm.
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,073
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: Session Login Problem

 
0
  #2
Jun 17th, 2006
Where are you echoing the session variable?
You should try echoing it right at the top.

Maybe you're overwriting with $_SESSION['email'] = $email;
Where $email will be empty on the second load of the page.

Try something like...


[php]
if ($_SESSION['email']) {
// session is set, check if valid

} else {
// session not set, ask for login

}
[/php]

Something to note:
sessions are available on the second load, after you set it.
(thats the reason we have it, continuity in a stateless protocol, http)
they dont always work, if cookies are not accepted by the browser, and your php ini only allows 'safe' sessions, where it isn't passed in the url, sessions will fail.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,073
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: Session Login Problem

 
0
  #3
Jun 17th, 2006
ps: ref.
http://us2.php.net/manual/en/ref.session.php

You'll notice theres alot of config in php.ini for sessions.
It may not be your code, maybe the config.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 234
Reputation: cancer10 is an unknown quantity at this point 
Solved Threads: 0
cancer10's Avatar
cancer10 cancer10 is offline Offline
Posting Whiz in Training

Re: Session Login Problem

 
0
  #4
Jun 18th, 2006
Dude you forgot to register the session, follow this code

$_SESSION['email'] = $email
session_register("email");
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC