473,414 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

question about session variables

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.
Jun 27 '08 #1
1 1378
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.
js*******@attglobal.net
==================
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Xizor | last post by:
Let's say I run a server. I have two people using the server. Bill and Joe. Bill is at address.com/bill and Joe is at address.com/joe. Let's say Joe and Bill are both using PHP with sessions on...
8
by: Karen | last post by:
Hi there.... i got a quick one for you guys. i've this session variable that is updated by calling a server method (i set this value when the user hits a submit button in my form. The server...
4
by: VB Programmer | last post by:
If I have a variable I want to share in my application what is the difference between just declaring a variable (Dim strMyVar as String) and using a session variable (Session("strMyVar"))? When...
10
by: glenn | last post by:
I am use to programming in php and the way session and post vars are past from fields on one page through to the post page automatically where I can get to their values easily to write to a...
3
by: Gauthier Segay | last post by:
Hello, I've an application where all my pages implement a PAGE_CODE string property, this property is stored in HttpContext.Current.Items. In some page, I must persist data in session while...
14
by: Coleen | last post by:
Hi All :-) We have an APSX application using VB.net as the code behind, which uses one or two session variables per page. These Session variables are passed to the final page and calculations...
3
by: Phillip N Rounds | last post by:
In diagnosing a problem, I noted that a button_click event gets run only after the page Page_Load event of the post back. (VS 2003, ASPNET 1.1, C#) Can this be correct? I'm trying to set...
2
by: Michaelk | last post by:
Can somebody tell me how many Session variables would be considered exessive, and when they start really affect the server speed. For example on 20-30 asp pages I need to use about 200-300 session...
2
by: DLN | last post by:
Hello all, I apologize for the naivety of this question, but I'm wondering whether session variables can ever be modified (somehow) by a client without having to go through code that I write. ...
1
by: Britt | last post by:
Hi, I read that SessionState is on by default. I also read that if it's not required, it must be better off (because of resources) My question is: i don't use session variables (like e.g....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.