jwk811 Posted September 4, 2006 Share Posted September 4, 2006 How to a make data go into a session or cookie? Will I need a database or is it like the get/post thing? Quote Link to comment https://forums.phpfreaks.com/topic/19674-sessioncookie/ Share on other sites More sharing options...
wildteen88 Posted September 4, 2006 Share Posted September 4, 2006 If you want use a sesion make sure you have session_start() as the first line of any php page that uses a session. To create/access the sessioin use $_SESSION['session_variable_name_here']So to create a session that holds your name, use:$_SESSION['name'] = 'jwk811']That creates a session variable called name. Which holds jwk811 as its value.Now to use that in any page. Make sure you have session_start() at the top of the page now add:echo $_SESSION['name'] where you want your name to appear.The same applies with cookies however to create a cookie you must use the [url=http://php.net/setcookie]setcookie[/url] function. Then to access your cookie you use $_COOKIE['cookie_name_here']. NOTE: YOu can not set and use cookies at the same time like you can do with sessions.Also when ever you use the sesison_start or setcookie function make sure you are not putting anything to the browser, otherwise you'll either get a blank screen or a nasty header cannot be sent error message. Quote Link to comment https://forums.phpfreaks.com/topic/19674-sessioncookie/#findComment-85775 Share on other sites More sharing options...
Daniel0 Posted September 4, 2006 Share Posted September 4, 2006 [quote author=wildteen88 link=topic=106847.msg427790#msg427790 date=1157383516]Also when ever you use the sesison_start or setcookie function make sure you are not putting anything to the browser, otherwise you'll either get a blank screen or a nasty header cannot be sent error message.[/quote]That can be fixed using [url=http://www.php.net/manual/en/ref.outcontrol.php]output control[/url]. Quote Link to comment https://forums.phpfreaks.com/topic/19674-sessioncookie/#findComment-85799 Share on other sites More sharing options...
jwk811 Posted September 4, 2006 Author Share Posted September 4, 2006 Wow, I must be really stupid because this doesn't make any sense to me. How does everyone else get this so easily, lol. I'm trying my hardest but nothing ever works for me. :( Quote Link to comment https://forums.phpfreaks.com/topic/19674-sessioncookie/#findComment-85847 Share on other sites More sharing options...
wildteen88 Posted September 4, 2006 Share Posted September 4, 2006 Well I havent gone into detail about using sessions/cookies. I have just brushed the surface of how to use sessions/cookies with PHP. To understand more about sessions and cookies I'd recommend that you read the manual on [url=http://php.net/session-start]sessions[/url] and [url=http://www.php.net/setcookie]setcookie[/url].Also search google for "using sessions with PHP" and "using cookies with PHP" they should return some results.When I started using sessions I wasnt sure either. There was a good tutorial here when I was learning sessions, but I can find it. Quote Link to comment https://forums.phpfreaks.com/topic/19674-sessioncookie/#findComment-85850 Share on other sites More sharing options...
jwk811 Posted September 4, 2006 Author Share Posted September 4, 2006 You see, I am trying to make a shipping cart on my website. I'm not sure but I think I'm going to need sessions to carry out the data on every page so the cart with there items in it will always be there. Quote Link to comment https://forums.phpfreaks.com/topic/19674-sessioncookie/#findComment-85862 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.