| | |
Session Login Problem
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Apr 2006
Posts: 20
Reputation:
Solved Threads: 0
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)
PHP Syntax (Toggle Plain Text)
<?PHP session_start(); mysql_connect("localhost", "*******", "*******")or die(mysql_error()); mysql_select_db("eluxian"); $email = $_POST['email']; $pass1 = $_POST['password']; $pass = md5($pass1); $check = mysql_query("SELECT password FROM members WHERE email='$email'") or die("Email not found in database"); $fetch = mysql_fetch_array($check) or die(mysql_error()); $password = $fetch['password']; if ($password != $pass){ echo "You entered a bad password"; }else{ $_SESSION['email'] = $email; echo "<meta http-equiv='Refresh' content='0;url=news.php'>"; echo "Correct password. Forwarding now..."; } ?>
Last edited by Ries; Jun 16th, 2006 at 6:32 pm.
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.
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!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
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.
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!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
![]() |
Similar Threads
- Hotmail Login Problem! (Web Browsers)
- ASP.NET - session objects Problem (ASP.NET)
- Losing session variable problem...help! (ASP)
- Netscape 7.1, Hotmail login problem - cookies 'disabled" (Windows NT / 2000 / XP)
- Hotmail login problem (Web Browsers)
Other Threads in the PHP Forum
- Previous Thread: PHP "hello" in different languages ???
- Next Thread: Warning: session_start():
| Thread Tools | Search this Thread |
advanced apache api array basics beginner binary broken cakephp checkbox class cms code combobox cookies cron curl database date datepart display dropdownlist dynamic echo email eregi error execution file files folder form forms function functions google head href htaccess html if...loop image include includingmysecondfileinthechain insert ip javascript job joomla jquery key library limit link login mail menu mlm multiple mysql oop password paypal pdf pdfdownload php phpvotingscript problem query radio random recursion remote screen script search server sessions smarty sms sorting source space sql stored syntax system table traffic tutorial unicode update upload url validator variable video web youtube zend






