Whats wrong with this PHP code. No matter whats the length of the strings (User Name or Password) I get redirected to "index.php?err_code=1" If I take off the header function and use an echo/print it validates correctly. <?php $username = htmlspecialchars($_POST['admin_user_name']); $passwd = htmlspecialchars($_POST['admin_pass']); // check string lengths of user name and password variables if ((strlen($username) == 0) || (strlen($username) > 25)) { header ("Location:index.php?err_code=1"); } elseif (strlen($passwd) == 0 || strlen($passwd) > 25) { header ("Location:index.php?err_code=2"); } // Redirect all login requests made thru $_GET variables to login page elseif (isset($_GET['admin_user_name']) || isset($_GET['admin_pass'])) { header ("Location:index.php"); } else { echo ("Success"); } ?> PHP:
Hi, What you have given the input for the following varaiables $_POST['admin_user_name'] and $_POST['admin_pass'] Soman.
I have tried n number of combinations. But the result is the same. My intention to redirect the visitor to "index.php?err_code=1" is only under the following conditions a) If the user name is blank (string length of 0) [OR] b) If the user name is greater than 25 characters (my HTML form has a limit of 25 chars but still I wanted to have this on server side for security reasons). Is that because of the "?" mark symbol in the uri? (inside the header redirect function) UPDATE Found the error causing code. It was the code at the bottom which actually checks if the user name and password matches the info stored in database [not shown in this thread]. Thanks "ranacseruet" - I will add the trim() function to them.
Hi , if you give the ? in the Header, it should work I have checked all the possiblities , it works $username = htmlspecialchars("soman%20%20we00b"); $passwd = htmlspecialchars(""); if ((strlen($username) == 0) || (strlen($username) > 25)) { header ("Location:index.php?err_code=1"); } elseif (strlen($passwd) == 0 || strlen($passwd) > 25) { header ("Location:index.php?err_code=2"); } else { echo ("Success"); } I have directly assign the value in the varaible, can you try this code. May be your POST method value is not getting correctly Soman