Clarify... SESSION Vars

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Zoram
Forum Contributor
Posts: 166
Joined: Sun Aug 18, 2002 3:28 pm
Location: Utah
Contact:

Clarify... SESSION Vars

Post by Zoram »

If i was to set a session variable using session_register() when a person logs in would the variable still be there to retrieve later? How?

I'm a little fuzzy on exactly how session variables work.
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

session

Post by AVATAr »

The session variable, as the name said, es a variable that is born in the session.

So you register the variable when you start the session and register it. But if the user exits the navigator -> the session exits too, and the varibles will disapear.

The session is a contract between your browser session and the server.. when you close de browser you loose the session

hope it helps
User avatar
Zoram
Forum Contributor
Posts: 166
Joined: Sun Aug 18, 2002 3:28 pm
Location: Utah
Contact:

Post by Zoram »

So how do you set them on one page and retrieve them from another?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Fari
Forum Commoner
Posts: 42
Joined: Thu Sep 19, 2002 8:41 pm
Location: Timmins - Ontario

session example:

Post by Fari »

page.php

Code: Select all

<?php 
  session_register('login'); 
  session_register('pwd'); 
  session_register('server'); 
  $login=$login_1;
  $pwd = $pwd_1;
  $server = $server_1;
?>
<HTML>
<HEAD>
     <META NAME="KEYWORDS" CONTENT="test6">
  <TITLE>Test</TITLE>
</HEAD>
<BODY text="#1c651c" bg
and in the next script (note the use of the variables $server,$login,$pwd registered in the previous script):

Code: Select all

<?php
session_start();
?>
<HTML>
<HEAD>
     <META NAME="KEYWORDS" CONTENT="test7">
  <TITLE>Test</TITLE>
</HEAD>
<BODY>
<?php

include 'includes.php';

echo"<TABLE BORDER="1" BORDERCOLOR="#003366" CELLSPACING="1" CELLPADDING="4">";
echo"<TR ALIGN="RIGHT">";
echo"<TD WIDTH="150">";
arial_2("Message : ");
echo"</TD>";
if (!($connection =  mysql_connect($server,$login,$pwd)))
 &#123;
   echo "<TD><font face="arial" size="2" color="#1c651c">Could not Connect!</FONT></TD></TR>";
   showerror();
 &#125;
User avatar
Zoram
Forum Contributor
Posts: 166
Joined: Sun Aug 18, 2002 3:28 pm
Location: Utah
Contact:

Post by Zoram »

So what is the difference between $HTTP_SESSION_VARS and session_register() ? which should i use?
rev
Forum Commoner
Posts: 52
Joined: Wed Oct 02, 2002 3:58 pm
Location: Atlanta, GA

Post by rev »

User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Post Reply