Forum Moderators: coopster

Message Too Old, No Replies

sessions

understandin how to use sessions effectively

         

bono667

11:30 am on Aug 21, 2003 (gmt 0)

10+ Year Member



right guys,,

I developing a new site and its the first time im having a user login..

Ive been menaing to understand sessions for a while...

Ive managed to set a cookie with the user deatils when they login, this also gives a unique logcode. that rights to the database everytie the user logs in..but i dont what to do with it or wether I need it all.

Ive but lookin at sessions but i cant get the to work on my local machine (runnng apache and obviously php,, n mysql..).

ive been looking for a good php seesions tutorial but cant seem to find a good one,, found one a t hot scripts but it didnt seem to be right..

ne way can you help out?

henry0

11:51 am on Aug 21, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you try to run sessions within a local machine using
Apache, MySQL and PHP be advised that sessions will not work from a PC MS environment
You need to run your tools within a nix environment
Redhat for ex.

why do not you try your experimentations from the server.

You mentioned hotscripts
Do not look only for sessions but look for authentication scripts

Timotheos

6:16 pm on Aug 21, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Apache, MySQL and PHP be advised that sessions will not work from a PC MS environment

I've set up Apache, MySQL and PHP using the firepages installer on a Win98 and a WinXP machine and I've had no problems with sessions.

Zend has some good tutorials. Here's the one on sessions [zend.com].

henry0

6:40 pm on Aug 21, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I run mostly Redhat
but I ref to install done on 98SE by using the Triad package
I was never been able to get sessions working in that environment

jamie

7:48 pm on Aug 21, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



bono667,

second what henry says about using authentification scripts.

i've just started user patUser on bits of my site and it's relatively easy to implement and copes with anything i can dream of. it is simply a class which manages user logins, etc.

you'll learn a lot about sessions just from implementing it - good luck ;-)

bono667

8:21 am on Aug 22, 2003 (gmt 0)

10+ Year Member



thanks guys ,, will look at authentication scripts.

will try my scripts on my online server see if they work..

bono667

2:45 pm on Aug 25, 2003 (gmt 0)

10+ Year Member



right,, sessions wont work on my test server so im doing it all online now..

can anyone see what is wrong with my scripts?

part of my login.php script
//intitiate session
session_start();

//register some seesion variables
session_register("SESSION");

//including the username
session_register("SESSION_USERNAME");
$SESSION_USERNAME = $username;


part of the page i want to be protected
(I commented out the session start as it didnt work with it in.)
//session_start();
if (!session_is_registered("SESSION"))
{
//if session check fails, invoke error handler
print "your not logged in";
}
else
{

//display results

print "<html>
<head</head>
<body>

</body>
</html>
";
}

zeebart

3:56 pm on Aug 25, 2003 (gmt 0)



can anyone see what is wrong with my scripts?

part of my login.php script
//intitiate session
session_start();

YES, what's wrong is when you are using SESSIONS the very first line of code (WITH NO EXCEPTIONS!) MUST BE


<?php session_start();?>

there can be no spaces before the opening php tag either. this is the header that MUST BE SEND first

bono667

6:56 pm on Aug 25, 2003 (gmt 0)

10+ Year Member



wierd ,, erm .. ill try it

RonPK

6:12 am on Aug 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In recent versions of PHP (4.1.0 +) there's no need to use session_register(). One can simply add a key to the $_SESSION superglobal:

 $_SESSION['foo']= 'bar'; 

Minor addition to zeebart's post: make sure that session_start() comes before any output is sent to the browser (headers, cookies, text, whatever). It is however quite OK to do other stuff first, like database queries.

bono667

10:07 am on Aug 26, 2003 (gmt 0)

10+ Year Member



im having real problems with this,, but ill try that,, I have to learn this its pretty important..