PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > very basic: session_start();
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
very basic: session_start();

Réponse
 
LinkBack Outils de la discussion
Vieux 14/06/2008, 17h56   #1
Twayne
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut very basic: session_start();

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


  Réponse avec citation
Vieux 14/06/2008, 18h05   #2
Rik Wasmus
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: very basic: session_start();

On Sat, 14 Jun 2008 18:56:59 +0200, Twayne <nobody@devnull.spamcop.net>
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 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'?
--
Rik Wasmus
....spamrun finished
  Réponse avec citation
Vieux 14/06/2008, 18h09   #3
larry@portcommodore.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: very basic: session_start();

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 s
Larry
  Réponse avec citation
Vieux 14/06/2008, 18h34   #4
Twayne
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: very basic: session_start();

> On Sat, 14 Jun 2008 18:56:59 +0200, Twayne
> <nobody@devnull.spamcop.net> 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
>> 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 s 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




  Réponse avec citation
Vieux 14/06/2008, 19h02   #5
Twayne
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: very basic: session_start();

> 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 s
> 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


  Réponse avec citation
Vieux 14/06/2008, 22h22   #6
Olaf Schinkel
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: very basic: session_start();

Twayne schrieb:
> 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
>
>

WHY dont´t you read the PHP Manual?
Everything is described. Sessions too.

  Réponse avec citation
Vieux 15/06/2008, 00h37   #7
larry@portcommodore.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: very basic: session_start();

On Jun 14, 11:02 am, "Twayne" <nob...@devnull.spamcop.net> wrote:

>
> > 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...;
> >

> 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.


Sometimes it's a lot more simpler then you realize.

How to use arrays is a big part of making some cool PHP stuff,
especially how to handle them in form data and in $_SESSION. It's
taken me a while to wrap my brain around it too, but its worth it.
  Réponse avec citation
Vieux 16/06/2008, 14h32   #8
Twayne
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: very basic: session_start();

> Twayne schrieb:
>> 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
>>
>>

> WHY dont´t you read the PHP Manual?
> Everything is described. Sessions too.


I assume you mean php.net's; not only read it, reread it, reread it, and
then reread it again. w3schools is pretty decent stuff.


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 07h31.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,16041 seconds with 16 queries