Ok, here's the sample code I found in one of my PHP books - it doesn't work exactly like my original script for checking passwords, but it does a close enough job to let me know that the sessions aren't staying registered.

I could ask my host if anyone else has had problems, but that would mean being able to get them on the phone, find someone who speaks English, and then hope that person has any kind of experience with Linux/PHP - which I'm quickly finding does not exist.

As it is a shared hosting situation, and I have no shell access (through telnet or SSH), I cannot check the php.ini file to see.

authmain.php
<?
session_start();

if ($userid && $password)
{
// if the user has just tried to log in

$db_conn = mysql_connect("localhost", "login", "passWord");
mysql_select_db("databaseName", $db_conn);
$query = "SELECT * FROM userlogin WHERE user='$userid' AND passwd=password('$password')";
$result = mysql_query($query, $db_conn);
if (mysql_num_rows($result) > 0)
{
// if they are in the database register the user id
$valid_user = $userid;
session_register("valid_user");
}
}
?>
<html>
<head>
<title>Test Sessions</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?

if (session_is_registered("valid_user"))
{
echo "You are logged in as: $valid_user <br><a href=\"logout.php\">Log out</a><br>";
}
else
{
if (isset($userid))
{
// if they've tried and failed to log in
echo "Could not log you in";
}
else
{
// they have not tried to log in yet or have logged out
echo "You are not logged in.<br>";
}

// provide form to log in
echo "<form method=post action=\"authmain.php\">";
echo "<table>";
echo "<tr><td>Userid:</td>";
echo "<td><input type=text name=userid></td></tr>";
echo "<tr><td>Password:</td>";
echo "<td><input type=password name=password></td></tr>";
echo "<tr><td colspan=2 align=center>";
echo "<input type=submit value=\"log in\"></td></tr>";
echo "</table></form>";
}
?>
<br>
<a href="members_only.php">Members section</a>
</body>
</html>

members_only.php
<?
global $userid;
session_start();

echo "<h1>Members only</h1>";

// check session variable

if (session_is_registered("valid_user"))
{
echo "<p>You are logged in as $valid_user.</p>";
echo "<p>Members only content goes here</p>";
}
else
{
echo "<p>You are not logged in.</p>";
echo "<p>Only logged in members may see this page.</p>";
}

echo "<a href=\"authmain.php\">Back to main page</a>";
?>

At 06:29 PM 1/21/2003 +0800, Jason Wong wrote:
On Tuesday 21 January 2003 17:59, Tim Thorburn wrote:
> Yes, the examples from the manual do work on the server using PHP 4.2.2 -
> however they do not work on the server using PHP 4.1.2.
>
> I've been using this same script for many sites with PHP versions 4.0.6
> thru 4.2.2 with no problems until now which leads me to believe that I must
> attempt to change a PHP setting through .htaccess since it is hosted on a
> shared server.
>
> I've tried the example from the manual on several other sites - works
> everywhere but on this problem server.

It's time to see some code :)

Does sessions work at all for the other people on your shared server? Ask your
host whether anybody else has complained.

> PHP 4.1.2 (doesn't work)
> '--enable-mm=shared'

Would this have anything to do with it? Apparently there could be problems
with storing sessions in mm:

http://marc.theaimsgroup.com/?l=php-general&m=104311365417871&w=2

Check in php.ini whether sessions are file based or using mm.

--
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

/*
Goals... Plans... they're fantasies, they're part of a dream world...
-- Wally Shawn
*/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to