-1

This is my situation, I have a login page and in the functions folder there is the php for that, say the page is example.com/login.php, upon login error it redirects to example.com/login.php#error

Essentially I'm trying to figure out how to add code that only shows when you are on the #error page.

Mateo
  • 11
  • 3
  • Instead of `example.com/login.php#error`, you should redirect the page to `example.com/login.php?error` so that you could catch the status using `$_GET` superglobal and display appropriate error message, kinda like this: `if(isset($_GET['error'])){ /* display error message */ }` – Rajdeep Paul Jun 28 '16 at 23:52
  • @RajdeepPaul Thanks man, that works great. – Mateo Jun 29 '16 at 00:04

2 Answers2

0

redirect with url like this:

example.com/login.php?error=here_Message

then, use this code for get the message:

<?php
if(isset($_GET['error'])){
    echo $_GET['error'];
      }
?>
  • Works perfect thanks, I just made my url example.com/login.php?error and then used if(isset($_GET['error'])){ echo "Login Failed"; } – Mateo Jun 29 '16 at 00:03
0

Assuming you're constrained in some way to use the hash (#error), you can use good old javascript. I adapted the solution below from this old response: https://stackoverflow.com/a/6682514/6525724

if(window.location.hash) {
  var hash = window.location.hash.substring(1); //Puts hash in variable, and removes the # character
  if(hash=="error") {  
    // Handle error
  }
}
Community
  • 1
  • 1
Nick
  • 16,066
  • 3
  • 16
  • 32
  • Wasn't constrained, but rather uneducated in php, just a beginner. I ended up using ?error instead, but thank you for your response. Will keep it in mind if i'm ever constrained to a hash. – Mateo Jun 29 '16 at 00:05