Jump to content

session


abdelelbouhy

Recommended Posts

hello guys if you please help mei'm trying to see the difference between the cookie and the session the code here is simple form to collect the colors then set by the cookie for the next page and it work just fine when i commented the cookie code and replace by the session code it doesn't show anything here the codethe first page<form action="session1.php" method="post">enter back color:<input type="text" name="back" />enter fore color :<input type="text" name="fore" /><input type="submit" /></form>then the seconed<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><?php session_start(); session_register('bg'); session_register('fg'); $bg = $_POST['back']; $fg = $_POST['fore']; /*setcookie('bg',$bg); setcookie('fg',$fg);*/?><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title></head><body><?php echo $_SESSION['bg'], $fg;?><a href="session2.php">goto next page</a></body></html>then last<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><?php session_start(); /*$bg = $_COOKIE['bg'];*/?><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title></head><body><?php echo $bg, $fg ?></body></html>

Link to comment
Share on other sites

The difference between sessions and cookies are that cookies are located on the clients computer and can be viewed and edited by the client. Sessions exist on the server and can only be accessed by the server. This is important for private information.Session variables should be set like this.

$_SESSION["bg"] = $_POST["bg"];

Because this is what the php website says about session_register()-

WarningThis function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged.
Next, all session_start() calls need to come before html tags, otherwise it will not work.
Link to comment
Share on other sites

The difference between sessions and cookies are that cookies are located on the clients computer and can be viewed and edited by the client. Sessions exist on the server and can only be accessed by the server. This is important for private information.
Another difference is that all session data is normally lost when the user closes their browser. Cookies can be made to survive even after the browser is closed, so they are still there when the user restarts their browser and returns to your site.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...