Latest

Archive

Community news

C++

Communities and Content

Databases

Editorials

Emacs

General

HTML

Java

Notices

PHP

XML

Apache

C++

Database

General

HTML

Java

Javascript

Linux

Object oriented programming

Open source

Perl

PHP

Python

Ruby

SOAP

XML

Suggest a link

Advertise on zez

Contribute

Contact us

About zez


PHP4 sessions


Categories PHP Code

Topic:

PHP4 sessions

Author:

Gera Makarov

Time:

10.11.2000 10:32

Text:

Hi there,

I am trying to write a simple application which would utilize sessions.
I don't want to rely on cookies so I pass SID to the relevant pages.
The two problems I am currently struggling with are, first: how do
I pass SID to the initial page, the one that starts the session (I can
actually do it but I'm not sure if that's a good way of doing it, see
the
example code below), also when I refresh the initial page it creates a
new
session, is there a way to prevent it? and second: when I follow the
links
on the first page and then press browser's back button, the browser
(both
Netscape and IE5) is asking to refresh the page. Is it possible to avoid
it?

Thanks in advance.
Regards,

Gera


Here's the code that I wrote:



session_start();
session_register("SESSION");
$SESSION[sid] = SID;

...

//
// The email and password have been submited.
//
if ($SESSION[go] == 1) {

if ( !empty($primary_email) && !empty($password) ) {

if (!isset($SESSION[primary_email]) ||
!isset($SESSION[password])) {

//
// Incorrect e-mail and/or password.
//
if (!$sec->check_user($primary_email, $password)) {

print_messg("Incorrect username / password");
session_destroy();
exit;

//
// The user has been authenticated.
//
} else {

$SESSION[go] = 2;
$SESSION[primary_email] = $primary_email;
$SESSION[password] = $password;

start_html("","Members Area");
print_members($SESSION[sid]);
end_html;

}

}

//
// Empty e-mail and/or password.
//
} else if (empty($primary_email) || empty($password)) {

start_html("","");
print_messg("Please enter your e-mail and password");
end_html();
session_destroy();
exit;
}

//
// The user is already logged in.
//
} else if ($SESSION[go] == 2) {

start_html("","Members Area");
print_members($SESSION[sid]);
end_html;

//
// The user has not logged in yet or
// authentication has failed.
//
} else {

if (empty($SESSION[go])) $SESSION[go] = 1;

start_html("","Members Area");

//
// This will print a form which will ask
// for e-mail and password, when the form is
// submited it will return $primary_email
// and $password to this script
//
print_login($SESSION[sid]);
end_html;

}



Message threads

Topic: Author:
Time:
PHP4 sessions Gera Makarov 10.11.2000 10:32  
  PHP4 sessions Steve Yelvington 10.11.2000 10:32  
   RE: PHP4 sessions test test 28.11.2000 13:22  
   test coolname new 10.11.2000 10:32  


Forgot your password?

Register a new user

Results

Polls