Click here to get back home

question about session variables

 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
question about session variables Sudhakar 06-02-2008
Get Chitika Premium
Posted by Sudhakar on June 2, 2008, 2:20 pm
Please log in for more thread options
i have a registration page called register.php if the data entered is
validated correctly i call a file called thankyou.php or else
validate.php

presently a user after seeing the url website.com/thankyou.php if they
enter the url directly in the browser as website.com/thankyou.php they
can access the file, if a user accesses the file this way i would like
to redirect to a page saying "Direct acess to this file is not
allowed"

previously i used sessions in register.php and also in thakyou.php and
validate.php and it worked fine for some reason now it is not working
the way it is supposed to i might have made some changes which i do
not know

previously my code in register.php was, the first few lines of
register.php file
=====================================================================
<?php
ob_start();
session_start();
if(!session_is_registered("directaccess"))
{
session_register("directaccess");
}
// rest of the html and php code
ob_end_flush();
?>
=====================================================================
code in thankyou.php, the first few lines of register.php file
=====================================================================
<?php
session_start();
if(!session_is_registered("directaccess"))
{
header("Location: http://website.com/directaccess.html");
exit;
}
// rest of the html and php code
ob_end_flush();
?>
=====================================================================
NOTE = in thankyou.php i display a thank you message by retrieving the
first name from register page and displaying in thankyou.php using
session variables in the following way

in register.php, the first few lines of register.php file
=====================================================================
if(!session_is_registered("firstname"))
{
session_register("firstname ");
}
$_SESSION[firstname] = $ firstname;
=====================================================================

in thankyou.php, the first few lines of register.php file
=====================================================================
if(session_is_registered("firstname "))
{
echo $_SESSION[firstname];
session_unregister("firstname ");
}
=====================================================================

please advice how i should rewrite the php code in both the
files(register.php and thankyou.php) so that if a user enters the url
directly in the browser i can redirect to directaccess.html file

thanks.

Posted by Jerry Stuckle on June 2, 2008, 3:14 pm
Please log in for more thread options
Sudhakar wrote:
> i have a registration page called register.php if the data entered is
> validated correctly i call a file called thankyou.php or else
> validate.php
>
> presently a user after seeing the url website.com/thankyou.php if they
> enter the url directly in the browser as website.com/thankyou.php they
> can access the file, if a user accesses the file this way i would like
> to redirect to a page saying "Direct acess to this file is not
> allowed"
>
> previously i used sessions in register.php and also in thakyou.php and
> validate.php and it worked fine for some reason now it is not working
> the way it is supposed to i might have made some changes which i do
> not know
>
> previously my code in register.php was, the first few lines of
> register.php file
> =====================================================================
> <?php
> ob_start();
> session_start();
> if(!session_is_registered("directaccess"))
> {
> session_register("directaccess");
> }
> // rest of the html and php code
> ob_end_flush();
> ?>
> =====================================================================
> code in thankyou.php, the first few lines of register.php file
> =====================================================================
> <?php
> session_start();
> if(!session_is_registered("directaccess"))
> {
> header("Location: http://website.com/directaccess.html");
> exit;
> }
> // rest of the html and php code
> ob_end_flush();
> ?>
> =====================================================================
> NOTE = in thankyou.php i display a thank you message by retrieving the
> first name from register page and displaying in thankyou.php using
> session variables in the following way
>
> in register.php, the first few lines of register.php file
> =====================================================================
> if(!session_is_registered("firstname"))
> {
> session_register("firstname ");
> }
> $_SESSION[firstname] = $ firstname;
> =====================================================================
>
> in thankyou.php, the first few lines of register.php file
> =====================================================================
> if(session_is_registered("firstname "))
> {
> echo $_SESSION[firstname];
> session_unregister("firstname ");
> }
> =====================================================================
>
> please advice how i should rewrite the php code in both the
> files(register.php and thankyou.php) so that if a user enters the url
> directly in the browser i can redirect to directaccess.html file
>
> thanks.

Several comments.

First of all, don't use ob_start() and ob_end_flush(). They aren't
needed and can hide problems. Rather, just don't send anything (even
whitespace) before calling session_start().

Also, session_register() and session_is_registered() are deprecated (and
depend on register_globals being set in your php.ini, which is a big
no-no. Rather, use the $_SESSION variable. Something like:

=====================================================================
<?php
session_start();

// When you want to set 'directaccess' in the session, use:

$_SESSION['directaccess'] = (some value here)
?>
=====================================================================
code in thankyou.php, the first few lines of register.php file
=====================================================================
<?php
session_start();
if (!isset($_SESSION['directaccess')) {
header("Location: http://website.com/directaccess.html");
exit;
}
// rest of the html and php code
?>
=====================================================================
NOTE = in thankyou.php i display a thank you message by retrieving the
first name from register page and displaying in thankyou.php using
session variables in the following way

in register.php, the first few lines of register.php file
=====================================================================

$_SESSION[firstname] = $firstname;
// The rest isn't needed

=====================================================================

in thankyou.php, the first few lines of register.php file
=====================================================================
if(isset($_SESSION['firstname'))
{
echo $_SESSION[firstname];
}

// Also, you had a space after "firstname " here - which is incorrect
=====================================================================



--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Similar ThreadsPosted
Newbie Sessions, session variables/objects and ADODB question February 13, 2006, 7:04 am
Session variables not being stored to session.save_path correctly April 16, 2005, 1:01 pm
can you set FILES[] variables to session variables? October 17, 2006, 3:04 pm
session variables? November 16, 2004, 7:30 pm
Session Variables How Many? March 30, 2006, 10:49 am
How do I set Session Variables August 21, 2006, 8:34 pm
PHP Session Variables October 12, 2006, 6:40 am
Session variables and IE7 September 5, 2007, 1:46 pm
Use of session variables January 13, 2008, 5:40 pm
session variables June 30, 2008, 5:03 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap