PHP variables / error message for login

  • Thread starter Thread starter wwjd_kilden
  • Start date Start date
  • Christian Chat is a moderated online Christian community allowing Christians around the world to fellowship with each other in real time chat via webcam, voice, and text, with the Christian Chat app. You can also start or participate in a Bible-based discussion here in the Christian Chat Forums, where members can also share with each other their own videos, pictures, or favorite Christian music.

    If you are a Christian and need encouragement and fellowship, we're here for you! If you are not a Christian but interested in knowing more about Jesus our Lord, you're also welcome! Want to know what the Bible says, and how you can apply it to your life? Join us!

    To make new Christian friends now around the world, click here to join Christian Chat.
W

wwjd_kilden

Guest
Help programmers

I've stolen some code : PHP Login script tutorial
to find out how to make logins using PHP. All well so far, only I adjusted for mysqli and altered the chec_klogin page to contain a bit of code saying

else{
header("location:main_login.php");
}


...to send the user back to the login if the login info fails

In doing this, it would make sense to tell the user why they are back at a blank login (ie the standard "Username or password incorrect, please try again." - How do I do this when the login page and the login check are in different files?
(I'm not terribly good with PHP yet).

Do I use session variables? If so: How do I check (at the login page) whether or not it is relevant to output the message?
Or something else?

*scratches head*
 
There is a ton of ways to handle a login system.

One option is to have a login page and you either post back to same page and conditionally handle GET and POST requests or just POST to another page for processing the login. The other option is to make an ajax request to the server using javascript.

If you are just wanting a simple redirect back to the login page on error, googling "PHP redirect" should be all you need or you could use javascript to do it. When you redirect back to the login page just pass an error message/identfier as a query parameter.

for example,

somewebsite.com?error=2

switch(
$_GET["error"]){
case 1:
//some error 1
break;
case 2:
//some error 1
break;
case 3:
//some error 1
break;
default:
//no error
}