login issue

Well, can you send me a private message with your login page. I do not need any codes, just want to look at the actual live page…

You have index.php which works same as index.html in most cases. So, I just need a peek at that page first.
I can view it online if you send me the url or web address…

Dee,
So, I got a little mixed up on your code. I usually do login’s a bit different and couldn’t see the trees
for the forest… Basically, there were three problems. I put the code into a little bit more formatting
and all of a sudden they jumped out at me.

First, the easy one, whenever you use any SESSION variables, you MUST start the session near the
beginning of the page. So, I added the " session_start(); " line at the beginning. Minor point, but will
save you from wondering why those session variables are not showing up in the profile page.

The real error is simple and I am sorry I did not catch it earlier. You have the validation code and the
processing code on the same page as the form. The name of the password field is “password” and in
the Javascript’s validation code only had the name as “pass”. Also, in the working part of the PHP code,
the $_POST[’’] used “pass” also. You pull this in this format: $pass=$_POST[‘pass’], not ‘password’.
So, none of the processing was actually using the real password. I made the needed changes, mostly
for myself, but I posted the fixed code below.
I also, changed the first if to use the more standard if(isset(…)). Most programmers use that code
instead of if(variable==“somevalue”)… Just more standard.

So, please try THIS version. Hope is has been a learning tool for you! LOL… Good luck!
[php]

<?php session_start(); if (isset($_POST['submit'])) { ini_set('display_errors',1); error_reporting(E_ALL); //Connect to the database through our include include_once "connect_to_mysql.php"; $email = $_POST['email']; $pass = $_POST['password']; $remember = $_POST['remember']; // Added for the remember me feature $email = strip_tags($email); $pass = strip_tags($pass); $email = mysql_real_escape_string($email); $pass = mysql_real_escape_string($pass); $pass = md5($password); // Make query $sql = mysql_query("SELECT * FROM memberFiles WHERE email='$email' AND password='$pass' AND email_activated='1'"); $login_check = mysql_num_rows($sql); if($login_check > 0){ while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $_SESSION['id'] = $id; $username = $row["username"]; $_SESSION['username'] = $username; $email = $row["email"]; $_SESSION['email'] = $email; mysql_query("UPDATE memberFiles SET last_log_date=now() WHERE id='$id'"); } // close while // Remember Me Section Addition... if member has chosen to be remembered in the system if($remember == "yes"){ setcookie("idCookie", $id, time()+60*24*60*60, "/"); // 60 days; 24 hours; 60 mins; 60secs setcookie("usernameCookie", $username, time()+60*24*60*60, "/"); // 60 days; 24 hours; 60 mins; 60secs setcookie("emailCookie", $email, time()+60*24*60*60, "/"); // 60 days; 24 hours; 60 mins; 60secs setcookie("passCookie", $pass, time()+60*24*60*60, "/"); // 60 days; 24 hours; 60 mins; 60secs } // User is logged in, now switch to the live site... header("Location: home.php"); // This would be the next page, I used home.php as sample } else { echo "


"; //just to make it easier to read... echo "Your email address or password did not match our records!"; echo "If you wish to try again click on the link below:"; echo '

Press here to return to login!'; } }// close if post ?> Login to your profile



Log in to your account here

Email Address:
Password:
 
Remember me!
[/php]

Both things make perfect sense NOW. I guess not having enough experience I couldn’t see it either.

Oh, I forgot, you also loaded the “remember” post, but, had no remember-me field…
I added that for you too…

First thank you again for all the help. I noticed the missing remember post but wasn’t sure how to handle it since there is no function for that on the index…? That said, now I’ve run into a different problem; when I access the login.php page, I get:

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/content/53/8957353/html/login.php:2) in /home/content/53/8957353/html/login.php on line 3

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/53/8957353/html/login.php:2) in /home/content/53/8957353/html/login.php on line 3

So the logical fix is to remove the session start variable at the beginning of the code and sure enough, the page loaded cleanly. Then, I tried to sign in and have the site remember me, the fields cleared but that was all. Looking back over the code, I still can’t see the problem…

P. S. That also makes me wonder whether or not I’ll have this issue when someone tries to log in from anywhere else on the site.

LOL, yep, I forgot, this page is calling itself, so that is an issue with the session_start…
Change: session_start(); line to these lines:

[php]
if (!isset($_SESSION)) {
session_start();
}
[/php]
This will start the session if it is not started, otherwise just skips the starting…

Hey EA, thanks again. While I can see how the other lines can be a fix, because it seems like the header is sending the session variables, my initial solution works to a degree. I can access the page with no problems but when I try to log in it only clears the spaces; I am not redirected anywhere. When I changed the session start variable to what you prescribes, this is what I got:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/53/8957353/html/login.php:2) in /home/content/53/8957353/html/login.php on line 5

I’m not sure if my eliminating the session variable is the right solution but I am also wondering if I need to alter the redirection to make sure it sends me somewhere – anywhere.

Take out these lines, they are just for debugging and must go first. Not needed at this point!

ini_set('display_errors',1); 
error_reporting(E_ALL);

All done, same error.

Well, I am going by the last code you posted and line #5 was the error_reporting line.
Sorry, but repost it. Thanks…

This isn’t possibly a problem form the makeautolinks.php page do you?

Here’s the code again.

[php]

<?php if (!isset($_SESSION)) { session_start(); } if (isset($_POST['submit'])) { //Connect to the database through our include include_once "connect_to_mysql.php"; $email = $_POST['email']; $pass = $_POST['password']; $remember = $_POST['remember']; // Added for the remember me feature $email = strip_tags($email); $pass = strip_tags($pass); $email = mysql_real_escape_string($email); $pass = mysql_real_escape_string($pass); $pass = md5($password); // Make query $sql = mysql_query("SELECT * FROM memberFiles WHERE email='$email' AND password='$pass' AND email_activated='1'"); $login_check = mysql_num_rows($sql); if($login_check > 0){ while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $_SESSION['id'] = $id; $username = $row["username"]; $_SESSION['username'] = $username; $email = $row["email"]; $_SESSION['email'] = $email; mysql_query("UPDATE memberFiles SET last_log_date=now() WHERE id='$id'"); } // close while // Remember Me Section Addition... if member has chosen to be remembered in the system if($remember == "yes"){ setcookie("idCookie", $id, time()+60*24*60*60, "/"); // 60 days; 24 hours; 60 mins; 60secs setcookie("usernameCookie", $username, time()+60*24*60*60, "/"); // 60 days; 24 hours; 60 mins; 60secs setcookie("emailCookie", $email, time()+60*24*60*60, "/"); // 60 days; 24 hours; 60 mins; 60secs setcookie("passCookie", $pass, time()+60*24*60*60, "/"); // 60 days; 24 hours; 60 mins; 60secs } // User is logged in, now switch to the live site... header("Location: home.php"); // This would be the next page, I used home.php as sample } else { echo "


"; //just to make it easier to read... echo "Your email address or password did not match our records!"; echo "If you wish to try again click on the link below:"; echo '

Press here to return to login!'; } }// close if post ?> Login to your profile



Log in to your account here

Email Address:
Password:
 
Remember me!
[/php]

I’m confused… You said the error you are now getting is in the login.php page at line #5.
But, it is not showing an error there… Also, you have never mentioned makeautolinks.php…
What is that file? I thought we were just dealing with the login.php page?

Maybe I have been unclear…the entire site is made and yes that is the login.php page we are talking about. My question was really about whether the other page could be causing the login.php page problem. There is a makeautolinks.php page along with several others that link directly to the index.php page. I’ll try to focus on one thing at a time (I am scatterbrained). Yes on the login.php page when I point my browser there I get the login.php page with this at the top:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/53/8957353/html/login.php:2) in /home/content/53/8957353/html/login.php on line 5.

LOL… This is why I hate doing the PHP validation on the same page as the log-in form!
(Normally they are two separate pages…)

So, two issues and a solution for the error…

First, when the user name does validate, the header/location sends it to home.php, I think you wanted that to be the profile.php page… Correct? You should change that.

Next, if the user name validation does not work and a message is given, the return-to-login-page message is a link that should go back to the login.php page. Correct? You should change that.

Now, for the error, I am sure you got that message after pressing SUBMIT !!! Well, the problem is because it is looking for a submit button named “submit”. But, in the form section at the bottom of the page, where the actual button is, you have named it “Submit”. See the difference! CAPS are important. So, change that name= at the bottom of the page to submit not Submit. And, try again. Let me know! Good luck!

Okay, I changed all of the things you suggested (easy to see and correct). But today’s original issue (or part of it, anyway) was that bringing UP the login page gives me:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/53/8957353/html/login.php:2) in /home/content/53/8957353/html/login.php on line 5.

Then it tells me: Your email address or password did not match our records! If you wish to try again click on the link below:

That’s why I’m confused. Is it dying in the form validation?

Can you send me a link to the site so I can see what is going on? If it is private send the link in a personal message by clicking on my ID. I need to see what it is doing.

Oh, I am assuming you mean when you type in the site it immediately gives you that error…

LOL, Thanks for the link… Let me explain something about PHP. If you are using PHP on the same page as HTML, you MUST make sure the PHP is in the correct spot. In your case, for some reason it is the SECOND LINE.
The first line is blank. So, the browser starts creating a page because you have TEXT on it. That starts a browser page to display the blank text. Then, PHP kicks in and tries to start a session after HTML (even though blank) has started.

So, I think you just need to make sure the FIRST line is <?PHP !!! Try that and let me know…

Okay, I took away the space and the error went away. I saw the extra space and really just cut and pasted what you corrected so that may be where that particular problem arose. Now, I still can’t sign in but at least I don’t have the error.

Okay, we are close, I am sure! Now, you can not log in. Does it give you an error or just goes back to the login? What’s it doing now…

Sponsor our Newsletter | Privacy Policy | Terms of Service