Jump to content

username from cookie


jenna

Recommended Posts

After you validate their information in your login script, add

 

setcookie('username',$username,time()+60*60*24*30); // $username being their username

 

and then on your form, add:

 

<input name="login" value="<?php if(isset($_COOKIE['username')){ echo $_COOKIE['username']; } ?>" />

Link to comment
https://forums.phpfreaks.com/topic/157482-username-from-cookie/#findComment-830251
Share on other sites

<?php 

$form = $_POST['form']; 

if($_GET['cookie'] == 'new'){ 
      setCookie('cookie', 2 ); 
      header('Location: '.$_SERVER['PHP_SELF']); 
}elseif($_GET['cookie'] == 'del'){ 
      setCookie('cookie'); 
      header('Location: '.$_SERVER['PHP_SELF']); 
} 
if($_COOKIE['cookie'] != null){ 
      echo 'Cookie exists!<br> 
<a href="'.$_SERVER['PHP_SELF'].'?cookie=del">Delete Cookie</a><br>'; 

}else{ 
      echo 'No cookie!<br> 

<a href="'.$_SERVER['PHP_SELF'].'?cookie=new">New Cookie</a><br>'; 
} 


?> 
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post"><input name="form" value="<?php if(isset($_COOKIE['cookie'])){ echo $_COOKIE['cookie']; } ?>" /><input name="form" type="hidden" value=""> 
<a href="<?php $_SERVER['PHP_SELF'] ?>?cookie=new">New or Chance</a></form>

 

now how can i submit both form and .$_SERVER['PHP_SELF'].'?cookie=new at the same time ?

Link to comment
https://forums.phpfreaks.com/topic/157482-username-from-cookie/#findComment-831080
Share on other sites

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.