Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    May 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    value from cookie

    How to submit content from html form to cookie and then read it from there as form value?

  • #2
    New Coder
    Join Date
    May 2009
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts
    PHP Code:
    <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <input type="text" name="cookie" />
    <input type="submit" value="Submit" />
    </form>
    <?php
    //set the cookie value to the data from the form
    if(isset($_POST['submit'])) {
        
    setcookie("cookie_name"$_POST['cookie'], time()+3600);
    }

    //retrieve the data from cookie and show it
    echo $_COOKIE['cookie_name'];
    ?>
    That should do it.
    For more info on cookies, check out http://www.w3schools.com/PHP/php_cookies.asp

  • #3
    New to the CF scene
    Join Date
    May 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thang you, but it does not create any cookie to read from.
    objective is to replace form value each time with something submited from there.

  • #4
    New to the CF scene
    Join Date
    May 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <?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 ?

  • #5
    New to the CF scene
    Join Date
    May 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    any ideas ?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •