jlgray48 Posted April 21, 2007 Share Posted April 21, 2007 My question is regarding the session command. I'm studying the difference between using Cookies and Sessions. I understand the underlying storing on the server or the client but I'm having trouble with syntax. For Example if I'm using cookies I would do this to store a customer id. <? setcookie("customerid", "john_adam"); ?> to set customerid to john_adam to retrieve I would $_cookie["customerid"] My question is how would I do this with session? <? $_SESSION("customerid", "john_adam"); ?> Link to comment https://forums.phpfreaks.com/topic/48037-solved-question-on-proper-use-of-session/ Share on other sites More sharing options...
Glyde Posted April 21, 2007 Share Posted April 21, 2007 You must add a session_start() call to the top of your PHP script (actually, it doesn't have to be at the top...just before anything is sent to the output channel). Then it's as simple as calling $_SESSION['sessionname'] = "value"; Sessions and cookies are very similar, and here's a quick explanation of the differences: Cookies are stored on the client's computer. In most browsers, the cookies are stored in a simple cookies.txt in plain text, which is beyond easy to edit. In Internet Explorer, each domain has it's own cookie file, such as [email protected]. Internet Explorer cookies are slightly tougher to edit, but not by much. Sessions, on the other hand, also create a cookie on the client's computer which is called PHPSESSID. In this cookie, a randomly assigned, but unique, session ID is given to the client. Then, there's a file on the server that is similar to a cookie file. Say your PHPSESSID was vaj94uwe3aHe7Aste8esaFa2eCH2muyu, you would have a file on the server in the tmp directory named vaj94uwe3aHe7Aste8esaFa2eCH2muyu.tmp. This file would contain all of your "cookies" better known as the sessions you set during your script execution. While sessions are more secure in the fact that the client has no access to them and can't directly edit them, they are less secure in the fact that clients can edit their PHPSESSID with a slight, yet probable possibility that they will access someone else's session. Link to comment https://forums.phpfreaks.com/topic/48037-solved-question-on-proper-use-of-session/#findComment-234801 Share on other sites More sharing options...
jlgray48 Posted April 21, 2007 Author Share Posted April 21, 2007 Thanks..... Here's another problem I'm missing the syntax on..... <html> <a href = "php_file_name.php?"Male"?"US Citizen"?"Above 17"> Submit data! </a> </html> This is a link that passes the three data to php_file_name.php. Is this the proper way or do you have to set all of your data up as variables and pass them that way? Thanks, jg Link to comment https://forums.phpfreaks.com/topic/48037-solved-question-on-proper-use-of-session/#findComment-234811 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.