-2


I want to show error as window browser alert like - Click Here
But i want to use URL as - Click Here
Is there any way to use?
I Have Code Below:

<?php
if(isset($_GET['i'])){
echo '<script type="text/javascript">alert("INFO:  ' . $_GET['i'] . '");</script>';
}
?>
Sukhchain Singh
  • 75
  • 1
  • 10
  • 1
    Code looks fine for what it's trying to do - is it not working? – Dan Smith Feb 18 '15 at 10:29
  • 2
    You can use a case statement (or any other type of control structure) inside your `if` statement to output the correct error message - based on the error code in the URL. Other pages can simply redirect to this main page with the correct ID in the URL or headers. – Fluffeh Feb 18 '15 at 10:30
  • It Is Working But i want URL Like http://royaliker.net/?i=100 – Sukhchain Singh Feb 18 '15 at 10:31
  • @SukhchainSingh: I see alert in link you post in comment above. Maybe cache? – pavel Feb 18 '15 at 10:32
  • See related question http://stackoverflow.com/questions/4246318/can-i-add-a-javascript-alert-inside-a-php-function-if-yes-how. – Mihai8 Feb 18 '15 at 10:32

1 Answers1

1

Display the message depending on your error code:

<?php
    if(isset($_GET['i'])){
        switch($_GET['i']) {
            case 100:
                $errorMsg = "Please use a valid email"; // For example
            break;
            case 200:
                $errorMsg = "Email already in use";
            break;
            default:
                // If $_GET['i'] has an unexpected value
                $errorMsg = "Oops, there was an unknown error";
            break;
        }
        echo '<script type="text/javascript">alert("INFO:  '.$errorMsg.'");</script>';
    }
?>