Re: How to create, name and start PHP sessions
| From: | Uchendu Nwachukwu | Date: | Thu, 18 Apr 2002 14:57:42 +0000 |
| Subject: | Re: How to create, name and start PHP sessions | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-93537@lists.php.net to get a copy of this message | ||
In your example, simply place this line in your code (on *every* page you
want the session to be on):
session_name("HasLoggedIn");
session_register("username");
If your PHP was compiled with '--enable-trans-sid' you shouldn't have to
worry about anything else. PHP will automatically store the session ID in a
cookie, or it will pass the session ID in your HTML links. If it wasn't
compiled with '--enable-trans-sid', you'll need to use the constant SID.
Example:
------------------------------------------------------------------
<?php
session_name("HasLoggedIn");
session_register("username"); ?>
Welcome <?=$username;?>. <!-- assumes user has already entered a username on
some other page -->
<a href="nextpage.php?<?=SID;?>">Click here to continue.</a>
------------------------------------------------------------------
Hope that helps! Check out http://www.php.net/manual/en/ref.session.php
for
more info
--
Uchendu Nwachukwu
newsreply AT unndunn DOT com - www.unndunn.com
"Phil Powell" <soazine@erols.com> wrote in message
news:20020418141725.75200.qmail@pb1.pair.com...
> Thanx, however, I cannot retain the session_name when I go to the next
URL.
> How do I retain the session_name especially when I have to use a form
> method=POST?
>
> I have a URL that will be the login
>
> Once you login you will have a session (that works now)
>
> That page with the session will have a form with five <input=file> type
form
> elements
>
> Once submitted you will be at a "thank-you" page and files uploaded, but
> then the session is gone (session_name is back to PHPSESSID again)
>
> What do I do to keep it? I cannot use cookies and putting it in the URL?
>
> Phil
> "Michael Virnstein" <michael.virnstein@brodos.de> wrote in message
> news:20020418104826.84326.qmail@pb1.pair.com...
> > session_name will retur the previos name of the session, so in your case
> > $stuff will contain "PHPSESSID"
> > and i think you have to call session_start(); before you do
> > $HTTP_SESSION_VARS["username"] = $username;
> >
> > so perhaps this will work:
> >
> > session_name("hasLoggedIn");
> > $stuff = session_name();
> > session_start();
> > $HTTP_SESSION_VARS["username"] = $username;
> >
> > Regards, Michael
> >
> > "Phil Powell" <soazine@erols.com> schrieb im Newsbeitrag
> > news:20020418094249.30058.qmail@pb1.pair.com...
> > > Will the following lines set up a session by the name of "hasLoggedIn"
> > with
> > > HTTP_SESSION_VARS["username"]?
> > >
> > > $stuff = session_name("hasLoggedIn");
> > > $HTTP_SESSION_VARS["username"] = $username;
> > > session_start();
> > >
> > > I am trying to create a page that sets a session variable upon
> successful
> > > login, problem is, the session_name() never changes it always remains
> the
> > > default PHPSESSID what am I doing wrong now?
> > >
> > > I fixed the problem with multiple files, that was bizarre!
> > >
> > > Thanx
> > > Phil
> > >
> > >
> >
> >
>
>