You are here: Newbie problems with session variables « PHP Programming Language « IT news, forums, messages
Newbie problems with session variables

Posted by infernon on 03/14/07 15:30

I am currently attempting to pull a value from a server variable
across three pages, but I'm having a problem.

On my login page, I am using the following code:

<?php
session_unset();
?>

<html>
<head>
<title>Please log in.</title>
</head>
<body>
<form method="post" action="test1.php">
<p>Enter your username:
<input type="text" name="user">
</p>
<p>Enter your password:
<input type="password" name="pass">
</p>
<p>
<input type="submit" name="Submit" value="Submit")
</p>
</form>
</body>
</html>

On test1.php, I am using the following code to check that the login
information is correct:

<?php
session_start();
$_SESSION['username'] = $_POST['user'];
$_SESSION['userpass'] = $_POST['pass'];
$_SESSION['authuser'] = 0;

if (($_SESSION['username'] == 'Joe') and
($_SESSION['userpass'] == '12345')) {
$_SESSION['authuser'] == 1;} else {
echo "Sorry, but you don't have permission to view this page.";
exit();
}
?>

On this page, there is also a link to another page that also checks
for a properly authenticated user with the previous credentials. The
problem that I'm having is that when someone clicks on the link, they
receive an error message telling them that they do not have permission
to view the page.

Here is the code from the page at the end of the link:

<?php
session_start();

if ($_SESSION['authuser'] !=1) {
echo "Sorry, but you don't have permission to view this page.";
exit();
}
?>

I am thinking that this problem is related to a server configuration
issue, but I can't seem to put my finger on it. I don't know why the
information in the session variable will be held for only one page.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация