Jump to content

how to secure login form


priyanka

Recommended Posts

Hi,

 

 

I am using following code in login form:

<td><input type="hidden" name="txtURL" value="<?=$_GET['url']?>"><input name="submit" type="submit" value="Submit" class="button" /> <input id="reset" name="reset" type="reset" value="Reset" class="button" /></td>

 

but a coding checker software says that it has security issues in <?=$_GET

 

I have one more form for login check, there i wrote

 

if(!isset($result['evoId'])){
        header('Location: login.php?action=invalid');

 

Software gives error in "IF"

 

and i used this in logi chk

if($txtURL=='reverse'){
                header('Location: ABC=');
            }else{
                header('Location: index.php');

 

It gives error in "if($tx"

 

please help and suggest

 

Priyanka

Link to comment
https://forums.phpfreaks.com/topic/283225-how-to-secure-login-form/
Share on other sites

You need to sanitize $_GET['url'] because it might contain malicious code.

 

You could do something like this

 

function clean_data($input) {
    $input = trim(htmlentities(strip_tags($input,",")));
 
    if (get_magic_quotes_gpc())
        $input = stripslashes($input);
 
    $input = mysql_real_escape_string($input);
 
    return $input;
}

then you could do this
 

<input type="hidden" name="txtURL" value="<?=clean_data($_GET['url'])?>">

I would recomend cleaning all data after the form is submitted, not before.

if(isset($_POST['submit'])){

  foreach($_POST as $k => $v){
     ${$k} = some_safeclean_function($v);
  }

  // input name 'myinput' is now clean as $myinput along with all the other posted inputs

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.