Jump to content

use cookies to input search text


PHPilliterate

Recommended Posts

Howdy!

I have a login page that uses a dynamic dropdown list to select the username, the have a cookie created that uses the USERNAME field for the cookie variable. When a user submits the login, it then takes them to a SEARCH page.

I need to know how (or if possible) to have the cookie pre-set the search field with the same name as as the USERNAME field from thje login page.

Here is my code from the login page that creates the cookie:

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST")     {
  setcookie("logIn", "".((isset($_POST["username"]))?$_POST["username"]:"")  ."", time()+(60*60*24*0), "/", "", 0);
}
?>

And this is the code for the SEARCH field from the search page:

<td class="DataTableCell"><input name="S_team" type="text" class="WADADataTableCell" id="S_team" value="<?php echo $_COOKIE['logIn']; ?>" /></td>

 

Is there a way to make this work?

Link to comment
https://forums.phpfreaks.com/topic/85770-use-cookies-to-input-search-text/
Share on other sites

Why use a cookie, why not use the posted name directly? Or if you need the cookie set, do both.

 

Thanks for the idea. How would I use the 'username" to be included on the next page in the search field? ??? (Reading php script is like reading hiroglyphics)  ;)

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.