Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to build server side cookies ??

Status
Not open for further replies.

hos2

Programmer
May 6, 2002
418
NL
I have the problem that my cookies sometimes dissapear after submitting a reaction or any other action. users have to relogin after that. I have heard that you can use session or something like that. I have searched the forum an get some subjects but I cant read all the posts associated with it :(

does anyone has a simple example how to use and build a cookie array with session variables ??

is it normal that you can only read 2 posts out of 120 posts of a topic ???? if someone can tell me what I do wrong with the search I'm glad to hear.

arthur
 
no such thing as server side cookies

to start a session:

session_start();
session_register('username'); //can be anything you need
then assign the variable
'assume DB connection to validate the user
'code here to hit db and pull out the password, compare then assign the username to the session varaible
$userName=$row["user_name"]

hth Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
In the simplest form:
Code:
session_start();
$_SESSION["value_name"] = "value";

Anything set into $_SESSION gets saved into the session. You'll need to call session_start() on all the subsequent pages that use the values. The $_SESSION variable is an "autoglobal" which means you can use it in classes and functions without having to do anything special.

Example:
Code:
<?php
session_start();
$_SESSION[&quot;message&quot;] = &quot;Hello world!&quot;;

function Message() {
     return &quot;Function: &quot;.$_SESSION[&quot;message&quot;].&quot;<br />&quot;;
}

class Message {
     function Get() {
          return &quot;Object: &quot;.$_SESSION[&quot;message&quot;].&quot;<br />&quot;;
     }
}

echo $_SESSION[&quot;message&quot;].&quot;<br />&quot;;
echo Message();
$Message = new Message();
echo $Message->Get();
?>

Try it! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top