Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session Help

Status
Not open for further replies.

humbleprogrammer

Programmer
Oct 30, 2002
315
US
Hi,

I am not very familiar with PHP and am hoping someone can help me with sessions.

I am trying to store a querystring value in a session and if the value doesn't equal something, I want it to route the user back to the main page. If it does equal the specified value, I want it to stay on the same page and display the HTML. Currently the page isn't doing anything, it just shows up blank. Below is my code. Can someone please help? Thanks in advance!

<?php
session_start();
if(!session_is_registered(&quot;clientaccess&quot;))
{
session_register(&quot;clientaccess&quot;);
}
?>
<?php
$qryclientaccess = $_GET['clientaccess'];
if ($qryclientaccess) != &quot;&quot;
{
$clientaccess = $qryclientaccess;
}

if($clientaccess != &quot;test&quot;)
{
header(&quot;location:../index.php&quot;)
}
?>

<html>
<head>
<title>Test User Page</title>
</head>
<body>
<br><br><br>
<p align=&quot;center&quot;><b><font size=&quot;4&quot; color=&quot;#800000&quot;>This is a test client
page...</font></b></p>
</body>
</html>
 
Except for the two typos your posted code has, I can't find any problems.

If I run the script (after fixing the two errors) as &quot; the script correctly tries to redirect me to index.php.

If I run the script as &quot; then I correctly see &quot;client test page&quot;.

After that, since the session variable is set, I get &quot;client test page&quot; whether the &quot;?clientaccess=test&quot; is present or not.

This is all correct behavior according to your code.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Thanks for your reply. I thought I had found the typos and corrected them but the same blank page is displaying. The way you have the script working is exactly how I need it to work. Below is my code with the typos I fixed. Can you please point out any other typos that I may have missed?

Thanks!

<?php
session_start();
if(!session_is_registered(&quot;clientaccess&quot;))
{
session_register(&quot;clientaccess&quot;);
}
?>
<?php
$qryclientaccess = $_GET['clientaccess'];
if ($qryclientaccess) != &quot;&quot;
{
$clientaccess = $qryclientaccess;
}

if($clientaccess) != &quot;test&quot;
{
header(&quot;location:../index.php&quot;);
}
?>

<html>
<head>
<title>Test User Page</title>
</head>
<body>
<br><br><br>
<p align=&quot;center&quot;><b><font size=&quot;4&quot; color=&quot;#800000&quot;>This is a test client
page...</font></b></p>
</body>
</html>
 
I'm wondering if your PHP configuration settings are preventing either the script from running or preventing error messages from being produced.

What are your settings for register_globals and for error_reporting?

If register_globals is set to &quot;off&quot;, then session_register() will not work. For security reasons you should leave it set to &quot;off&quot;, and instead of using session_register(), manipulate the $_SESSION superglobal array directly.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
and try a viewsource of ur page... if u can see the <?php and ?> php tags then check ur server configuration...

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top