cookies - Pass value to the previous webpage in php -


i want know how can pass value cookie 1 page pervious 1 ,

this code

readcookie.php

<?php  foreach($_cookie $key => $value)     {echo("<p>$key: $value</p>");     $name=($_cookie['name']);      }       print('<a href="coockie.php?name:"'.$name'>go home</a>');     ?> 

cookie.php

<!doctype html> <html>  <?php    $name=$_get['name'];  echo'hello'.$name;  ?> <form method="post" action="setcookie.php"> <label>name<input type="text" name="name"></label> <label>age<input type="number" name="age"></label>  <input type="submit" name="submit">  </form>  </html> 

setcookie.php

<?php   setcookie("name" , $_post['name'] , time()+60*60*24*1); setcookie("age" , $_post['age'] , time()+60*60*24*1);   ?>  <p> read cookie click </p>   <a href="readcookie.php">here</a> 

what want when go readingcookie.php page coockie.php page , found welcome username ???

first, have typo: ?name:"'.$name' should be: ?name="'.$name'

in script line:

     print('<a href="coockie.php?name:"'.$name'>go home</a>'); 

should be:

     print('<a href="coockie.php?name="'.$name'>go home</a>'); 

second, why aren't using $_cookie['name'] name in cookie.php (instead of: $_get['name'], in example?) can use 9(change in: cookie.php) :

<?php  $name = ( isset($_cookie['name']) ) ? $_cookie['name'] : "guest" ;   echo'hello'.$name; ?> 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -