Click here to get back home

very basic: session_start();

 HomeNewsGroups | Search | About
 comp.lang.php    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
very basic: session_start(); Twayne 06-14-2008
Get Chitika Premium
Posted by Twayne on June 14, 2008, 12:56 pm
Please log in for more thread options
If there are better places for basic questions like this, feel free to
redirect me.

Say I have a php page with session_start(); I can assign variables and
those variables will carry over to other pages in order to use them in
those other pages, right? e.g. fname and thus $fname. Let's also
assume I am not assigning Global variables within any of the code.

But, if by chance one of those 'other' pages ALSO begins with a
session_start(); does that close the first session and throw away its
variables, making them no longer available from 'other' pages?
Is the above what the line $_SESSION['views']=n; is intended to
accomodate?
e.g.:

<?php
session_start();
// store session data
$_SESSION['views']=1;
?>
<html>
<body>

Does that then allow me, from any page, to call whichever set of
variables I want/need for that particular page by retrieving a 'views'
set?

I'm trying to work it our programatically but it's a little confusing
without some verification from the 'ones that know' if you will.

TIA

Twane



Posted by Rik Wasmus on June 14, 2008, 1:05 pm
Please log in for more thread options
=

wrote:

> If there are better places for basic questions like this, feel free to=

> redirect me.
>
> Say I have a php page with session_start(); I can assign variables an=
d
> those variables will carry over to other pages in order to use them in=

> those other pages, right? e.g. fname and thus $fname.

No, not $fname, $_SESSION['fname'].

> Let's also
> assume I am not assigning Global variables within any of the code.

Doesn't matter.

> But, if by chance one of those 'other' pages ALSO begins with a
> session_start();

_every_ page that uses a session has to call session_start() (before any=
=

output) to be able to use the $_SESSION array.

> does that close the first session and throw away its
> variables, making them no longer available from 'other' pages?

Nope, it continues the session.

> Is the above what the line $_SESSION['views']=3Dn; is intended to
> accomodate?

> session_start();
> $_SESSION['views']=3D1;

It just sets a variable in the session array.

> Does that then allow me, from any page, to call whichever set of
> variables I want/need for that particular page by retrieving a 'views'=

> set?

You can only retrieve what you have set in the $_SESSION array. What do=
=

you mean with a 'views set'?
-- =

Rik Wasmus
...spamrun finished

Posted by Twayne on June 14, 2008, 1:34 pm
Please log in for more thread options
> On Sat, 14 Jun 2008 18:56:59 +0200, Twayne
>
>> If there are better places for basic questions like this, feel free
>> to redirect me.
>>
>> Say I have a php page with session_start(); I can assign variables
>> and those variables will carry over to other pages in order to use
>> them in those other pages, right? e.g. fname and thus $fname.
>
> No, not $fname, $_SESSION['fname'].
>
>> Let's also
>> assume I am not assigning Global variables within any of the code.
>
> Doesn't matter.
>
>> But, if by chance one of those 'other' pages ALSO begins with a
>> session_start();
>
> _every_ page that uses a session has to call session_start() (before
> any output) to be able to use the $_SESSION array.
>
>> does that close the first session and throw away its
>> variables, making them no longer available from 'other' pages?
>
> Nope, it continues the session.
>
>> Is the above what the line $_SESSION['views']=n; is intended to
>> accomodate?
>
>> session_start();
>> $_SESSION['views']=1;
>
> It just sets a variable in the session array.
>
>> Does that then allow me, from any page, to call whichever set of
>> variables I want/need for that particular page by retrieving a
>> 'views' set?
>
> You can only retrieve what you have set in the $_SESSION array. What
> do you mean with a 'views set'?

OK, that helps a LOT, Rik!
By "vews set" I meant something totally irrelevant; I thought a "set"
would be, for instance, a 'set' of variables contained in
$_SESSION['views']=1 , then another, different set would be contained in
... =2, and so on. I kind of caught on some when I came across a PHP
page counter but ... .

%_SESSION is the piece I've been missing out on; don't recall coming
across it before, but that doesn't mean much. I'm still learning to
find my way around the w3schools heriarchies.

Thanks much!

Twayne





Posted by larry on June 14, 2008, 1:09 pm
Please log in for more thread options
using session_start() on a script - if there is no session it sets
one up; if there is a session, it opens it. If you wait too long
between pages it disposes the session automatically (set time for
session to keep alive in php.ini).

You need session_start() on all pages that needs to access the
$_SESSION array.

$_SESSION is just like an array variable, so if you want to segregate
data you could set a sub array of page data in $_SESSION...

$_SESSION['views'][1] = ...array of data...;

Hope that helps
Larry

Posted by Twayne on June 14, 2008, 2:02 pm
Please log in for more thread options
> using session_start() on a script - if there is no session it sets
> one up; if there is a session, it opens it. If you wait too long
> between pages it disposes the session automatically (set time for
> session to keep alive in php.ini).

Ha! I think that might explain a couple of "strange" events that happen
when I go away and come back later! If I read that right, it's only
about 24 minutes (1440 S). I'm not going to change it because I don't
know the nuances/inter-plays of the php.ini yet. I'm perfectly happy
just knowing there's a reason for it! I've been getting ready to blame
the OS.

>
> You need session_start() on all pages that needs to access the
> $_SESSION array.
>
> $_SESSION is just like an array variable, so if you want to segregate
> data you could set a sub array of page data in $_SESSION...
>
> $_SESSION['views'][1] = ...array of data...;
>
> Hope that helps
> Larry

I think I'm starting to catch on; for whatever reason I've been totally
misinterpreting some of these things including $_SESSION. It's always
hardest for me to get the basics into my head when I start something new
like this.

Thanks much

Twayne



Similar ThreadsPosted
some examples of basic, basic concepts in PHP for novices January 26, 2006, 5:58 pm
Basic Authentication July 18, 2004, 3:15 pm
Basic PHP webapp October 6, 2004, 2:30 am
basic tutorial January 20, 2005, 1:21 am
new to PHP -- basic questions... June 1, 2006, 11:12 am
basic PHP questions April 24, 2007, 4:04 am
PHP on IIS with basic authentication August 2, 2007, 10:47 am
Basic Authentication question. July 23, 2004, 7:40 pm
cURL and XML - Missing something basic? October 25, 2004, 12:39 pm
Basic RegEx question January 24, 2005, 10:52 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap