Jump to content

username from cookie


jenna

Recommended Posts

How to create form that displays submited text in it self?

its like i loged in from from that form, entered my username there, and next time i come my username is already there and i only need to enter password.

 

Link to comment
Share on other sites

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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.