Forum Thread
  Posts  
PHP - Sessions (Forums : Coding & Scripting : PHP - Sessions) Locked
Thread Options
BigBird
BigBird Mod DB Pilot
Mar 4 2004 Anchor

In lamans terms (very seasy to understand), how do you use them, I know the basics of getting them started, but how does one add variables to them?

--

BigBird

Mod DB Guy
Play Something Different

Megasaxon
Megasaxon Jubinator
Mar 4 2004 Anchor

Au3.php.net

read through it :)

--

"I'm the one that ate your baby" - Megasaxon

BigBird
BigBird Mod DB Pilot
Mar 4 2004 Anchor

thanks mega, helped a bit

Moddb.com < wolf's post helped a tad too

starting to get the general idea o_O

- Edited By BigBird On Wed 3rd, Mar 2004 @ 9:52:46pm

--

BigBird

Mod DB Guy
Play Something Different

Mar 4 2004 Anchor

I tried using them but they totally fucked my forum over :s

--

Why wont it save me?

Mar 4 2004 Anchor

I've been learning PHP lately but I'm not nearly to the level of even using SQL.

jacksonj04
jacksonj04 Over 9000
Mar 4 2004 Anchor

if you can, use plain cookies

--

Barcode Imagejacksonj04 the generally helpful one
Lost, confused or just need a virtual cuddle? PM me.
Need urgent help from staff? PM us all.

BigBird
BigBird Mod DB Pilot
Mar 4 2004 Anchor

mm but i know evan less about cookies heh :S

--

BigBird

Mod DB Guy
Play Something Different

Mar 7 2004 Anchor

If you want to develop a good site you must know the dif between them

Cookies
Good for storing everything wich isnt important. You may want to store user-settings, shoppingcarts and other stuff in it. Since a cookie is saved on a client computer it's not good for security. But everytime the user walks in your site you can use the data ( if u set the cookie expiration date very high)

Sessions
Good for security/login data. But becareful dont use it to much, you dont want to create a large overhead on your server. A session is stored on the server. Also a cookie is made on the clients computer, so the server can see from who the session is.

So basicly thats the differance between the two, the code can be found on www.php.net

BigBird
BigBird Mod DB Pilot
Mar 7 2004 Anchor

mm thanks Mr_C i think i might try to incorperate the two into my site somehow...

--

BigBird

Mod DB Guy
Play Something Different

BigBird
BigBird Mod DB Pilot
Mar 9 2004 Anchor

Sessions:
Au3.php.net
Will be used for login system

Cookies:
Au.php.net
Will be created during login, containing information concerning user number and such information that will be used continously throughout different pages

I alos found something pretty cool while i was doing a bit of reseach tonight, it checks wether or not the clients browser will accept cookies :D

Here&#039;s a good way to check that the host browser accepts cookies. (this one works, trust me!)

It includes a P3P header, so that the cookies are not blocked by IE6, unless the user has explicitly requested that cookies be blocked.

It uses a query string to see if the page has been re-loaded, which gets around the &quot;cookie is only visible after refreshing the page&quot; problem. It also preserves any existing query strings, so will still work if you include it on a page like &quot;cookiesetter.php?product=milk&price=3.50&quot;

testcookie.php

&lt;?php

header(&quot;P3P: CP=&quot;ALL DSP COR NID CURa OUR STP PUR&quot;&quot;);

$nocookies = false;
$reloaded = $_GET[&quot;ckset&quot;];
$url = $_SERVER[PHP_SELF];
$querystring = $_SERVER[QUERY_STRING];

$querystring = str_replace(&quot;ckset=ok&quot;, &quot;&quot;, $querystring);

setcookie(&quot;check_cookie&quot;, &quot;on&quot;, time()+(1000000));
if ($reloaded == &quot;&quot; and !isset($check_cookie)) {
echo &quot;&lt;META HTTP-EQUIV=&quot;refresh&quot; CONTENT=&quot;0;URL=http://www.naturalanimalcare.com&quot; .

$_SERVER[PHP_SELF] . &quot;?ckset=ok&quot; . $querystring . &quot;&quot;&gt;&quot;;
exit;
}

else {
if (!isset($check_cookie)) $nocookies = true;

}

?&gt;

To use this, save it as &quot;testcookie.php&quot; and then the page you want to test cookies in would go something like this ...

&lt;?php
include &quot;testcookie.php&quot;; // Test for cookies

// Other setcookie commands go here...
//
// Headers, layout, etc go here...
//
// Body text ...
If ($nocookies) {
echo &quot;Your browser is not accepting cookies.

Please turn them on or update your browser&quot;;
}
else {
echo &quot;Your browser is accepting cookies&quot;;
// Rest of the page goes here...
}

// Footers, etc.

?&gt;

you may not need it but it's here for my use later on heh :)

- Edited By BigBird On Mon 8th, Mar 2004 @ 9:37:03pm

--

BigBird

Mod DB Guy
Play Something Different

Reply to thread
click to sign in and post

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.