本文實例講述了php保存信息到當前Session的方法。分享給大家供大家參考。具體如下:
php中可通過$_SESSION保存session變量,下面的代碼簡單演示了 $_SESSION的用法
<?php session_start(); print("<html><b>"); $_SESSION["sitename"] = "W3M"; print("A value saved in the session named as sitename.\n"); $_SESSION["MyChoice"] = "red"; print("A value saved in the session named as MyChoice.\n"); echo $_SESSION['sitename']."\n"; echo $_SESSION['MyChoice]."\n"; print("</b></html>\n"); ?>
上面的代碼輸出結果如下:
A value saved in the session named as MyLogin. A value saved in the session named as MyColor. W3M red
希望本文所述對大家的php程序設計有所幫助。