Forum Moderators: open

Message Too Old, No Replies

autocomplete off php example

turn off autocomplete browser field

         

eXpertPHP

4:16 pm on Jul 3, 2008 (gmt 0)

10+ Year Member



Because the "autocomplete" parameter works only in Internet Explorer, then i will present you my simple solution ( in this case PHP ).
First page ( HTML Form ) :

<form method="post">
<input type="hidden" name="username" value="random1">
<input type="hidden" name="password" value="random2">
Username: <input type="text" name="random1" value=""><br />
Password: <input type="password" name="random2" value="">
</form>

Where "random1" and "random2" are random names generated, you can use in combination with unix time.

Second page ( PHP output ) :

<?php

if ( isset($_POST['username'], $_POST['password']) &&
isset($_POST[$_POST['username']], $_POST[$_POST['password']]) ) {

echo ''.
'Username: '.$_POST[$_POST['username']].'<br />'.
'Password: '.$_POST[$_POST['password']];

}

?>

With this simple solution you will don't worry about autocomplete anymore in any browser.

Complete PHP example for testing:

--- PHP Begin -------------------------------

<?php

if ( isset($_POST['username'], $_POST['password']) &&
isset($_POST[$_POST['username']], $_POST[$_POST['password']]) ) {

echo ''.
'Username: '.$_POST[$_POST['username']].'<br />'.
'Password: '.$_POST[$_POST['password']];
exit;

} else {

$u = 'u'.time().rand(0, 100);
$p = 'p'.time().rand(0, 100);

}

?>
<html>
<head>
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">
</head>
<body>

<form method="post" action="?p">
<input type="hidden" name="username" value="<?php echo $u; ?>">
<input type="hidden" name="password" value="<?php echo $p; ?>">
Username: <input type="text" name="<?php echo $u; ?>" value=""><br />
Password: <input type="password" name="<?php echo $p; ?>" value=""><br />
<input type="submit">
</form>

</body>
</html>

--- PHP End -------------------------------

[edited by: eXpertPHP at 4:32 pm (utc) on July 3, 2008]

eelixduppy

4:22 pm on Jul 3, 2008 (gmt 0)



the autocomplete attribute works for the following: Netscape 6.2 (Mozilla 0.9.4) or later. IE 5 or later.

set like this:


<form method="post" action="" autocomplete="off">

I'm not exactly sure where you use the solution presented above...

eXpertPHP

4:34 pm on Jul 3, 2008 (gmt 0)

10+ Year Member



In credit card fields ? think twice.