-1

I am trying to make a Login Page. The code has an if clause, which will check if the data provided is correct or incorrect. To do this, I've made a querystring "?e=2" which will be used to display an error, this should execute only when there's a querystring, but that is not happening. I'm getting an error. How can I keep this check in the code but skip this if there is no querystring.

Notice: Undefined index: e in /storage/ssd3/126/12156126/public_html/user_login.php on line 18

Here is that part of the code:

 <?php
   if($_GET["e"] == 2) {
    echo "<table align=\"center\" class=\"login_error\"><tr><td>";
    echo "Username or Password is incorrect. Please try again";
    echo "</td></tr></table>";
  }
  ?>
lovecoding
  • 43
  • 6
  • **WARNING**: Writing an access control layer is not easy and there are many opportunities to get it severely wrong. Any modern [development framework](https://www.cloudways.com/blog/best-php-frameworks/) like [Laravel](http://laravel.com/) comes with an [authentication system](https://laravel.com/docs/master/authentication) built-in, and there are [authentication libraries](http://phprbac.net/) you can use. At the absolute least follow [recommended security best practices](http://www.phptherightway.com/#security) and **never store passwords as plain-text** or a weak hash like **SHA1 or MD5**. – tadman Mar 01 '20 at 18:49

2 Answers2

2

The error says it all - you're checking an index that is not defined. To check if it's defined, add the following condition:

if(isset($_GET["e"]) && $_GET["e"] == 2) {

This way the equality check will be skipped since the expression will fail on the first condition.

El_Vanja
  • 3,660
  • 4
  • 18
  • 21
-2

You can use if(isset($_GET['e'] && $_GET['e'] == '2')){ some code here... } because if there is no get parameter you encounter the error.

ariferol01
  • 221
  • 4
  • 13