I am sending login status = fail, back to my login page.Here is my code-
header("location:index.php?login=fail");
but that is sending through URL like-
http://localhost/303/index.php?login=fail
is there any way to pass value without showing in URL? And how to get this value on the second page?
there are several ways to accomplish your task
Other ways are to use session or hidden fields but you what you are doing is fine for the purpose. You can later retrieve the value like this:
You are passing that value via a GET request, which is why it appears in the URL. In order to pass a value without showing it in the URL, you want to pass it via a POST request.
In order to do this you aren't going to want to "return" the value to your login page. Instead, whatever php form is handling the process of logging in the user after they click the "login" button, will decide what to show the user.
In PHP post variables can be accessed by the global $_POST object -
Would get the value with the name "username" that you passed via POST:
In order to dynamically save and show errors to the user, you can store them in the session, for example have a file called "errors.php"
And in your php that checks the login, do:
Then redirect to your login page (don't pass any variables) and on your form always have this field:
If you didn't have any errors, it won't show anything and the login page will look normal.
Note: In any php form that you use a session_start(), it HAS TO BE THE FIRST THING in the form.