1 / 8

PHP-- advanced introduction

This advanced PHP introduction, presented by Chin-Chang Chang on April 23, 2007, covers the basics of using cookies and sessions in PHP. The session provides practical examples of how to set and retrieve cookies, manage session data, and clear cookies with specific paths. Attendees will learn about the `setcookie()` function, session management techniques, and the role of HTTP cookie variables in PHP. This session is essential for those looking to enhance their web applications with persistent data storage.

nieve
Télécharger la présentation

PHP-- advanced introduction

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PHP-- advanced introduction Speaker: Chin-Chang Chang Date:2007.4.23

  2. Cookie(1/2) • setcookie ( string name [, string value [, int expire [, string path [, string domain [, bool secure]]]]] ) • Ex. setcookie('stu_id', '95321517'); • $HTTP_COOKIE_VARS['cookie'] • echo $HTTP_COOKIE_VARS['stu_id'];

  3. Cookie(2/2) <?php setcookie('tCookie', $name, time()+60*60*24); echo "cookie = " . $HTTP_COOKIE_VARS['tCookie']; ?> <html> <head><title>cookie</title></head> <body> <form action="<?= $PHP_SELF; ?>" method="POST"> <input type="text" name="name"><input type="submit"> </form> </body> </html> http://stu.csie.ncnu.edu.tw/~beautidays.99/cookie.php

  4. Cookie Path <?php setcookie('path_test', $test, time()+60*60*24, '/~beautidays.99/cookie'); echo "cookie = " . $HTTP_COOKIE_VARS['path_test']; ?> http://stu.csie.ncnu.edu.tw/~beautidays.99/cookie/cookie2.php http://stu.csie.ncnu.edu.tw/~beautidays.99/cookie/path_test.php http://stu.csie.ncnu.edu.tw/~beautidays.99/path_test.php

  5. Cookie Clear • setcookie('path_test', '', time()+60*60*24); • setcookie('path_test', '', time()+60*60*24, '/~beautidays.99/cookie'); http://stu.csie.ncnu.edu.tw/~beautidays.99/link.php

  6. Session(1/2) • <?php • session_start(); • if(($HTTP_POST_VARS['user']==andy)&&($HTTP_POST_VARS['pass']==123)) • { • echo "success!"; • $user=$HTTP_POST_VARS['user']; • session_register('user'); • echo '<a href=“protected.php">next</a>'; • } • else • header('Location:login.php?error=1'); • ?> • http://stu.csie.ncnu.edu.tw/~beautidays.99/login2.php

  7. Session(2/2) <?php include('auth2.php'); ?> success! <form action="login2.php" method="POST"> <input type="submit" value="logout" onclick="<? session_unregister('user'); ?>"> </form>

  8. Reference • http://chensh.loxa.edu.tw/php/

More Related