Session Control_2-5 Programming Exercises

Write the following content into the cookie, get the content from the cookie, and print it to the page

Reference renderings:

//climg.mukewang.com/58c6370c0001cba902390085.jpg

 

Task

 

(Data: imooc's name 'IMOOC', imooc's password '123456' imooc's email '[email protected]')

1. Write the content into the cookie and create an array

2. Detect whether the cookie exists, and print it if it exists (isset can be used)

3. Traverse the obtained cookie to the page

 

1 <? php
 2     // write cookie 
3     $name = setcookie ('name','IMOOC' );
 4     $pwd = setcookie ('pwd','123456' );
 5     $email = setcookie ('email', '[email protected]' );
 6     // $arr=[];
 7     
8  
9     //Check if cookie is set, output
 10 if set     // for($i=0;$i<count($_COOKIE); $i++){
 11     // echo 
 12     // }
 13      // isset()   
14      foreach ( $_COOKIE as $key=>$value){
15         if(isset($_COOKIE[$key])){
16             echo $key.":".$value.'<br>';
17         }
18     } 
19    
20 ?>

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324818262&siteId=291194637