473,503 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sessions (another why doesn't it work)

Hi Everyone,

I'll just start, and say I am not a PHP developer (I'm a sysadmin, who
has gotten lumped with a non-working website). But since I like to do
this type of stuff, I though I might just learn WTF is going on? :)

Basically, sessions are being created, but no info in being stored in
the session, and if data is stored (about 1 in 20 goes), it doesn't
follow-on on a page redirect.

The environment is Win2K Svr SP3, IIS5, PHP4.3.2 (CGI), MySQL 4.0.13.
AFAICT everything is working, as the PHP pages get rendered correctly,
and when user authentication (to MySQL) occurs, no errors are reported
in either PHP logs or MySQL. I've doubled checked the PHP setup, and
php.ini is being read correctly (and varified using phpinfo(); ). All
the session directories are read/write for IUSER_Machine.

Now the interesting thing is, when I first installed PHP about a week
ago, sessions were working fine. Sessions stopped working when I
modified the smtp field in php.ini? (it was the only field I did
modify). The other interesting thing is that when the user goes to the
login page, 3 session files are created?

So any clues?

Chewy509...

PS. Code is as follows: (login.php). (index.php, checks for a session
variables, if not comes here, else goes to the start page of the
system).

<?
// Include the database parameters
include "mysqldb.inc";

// Start a session
session_start();

// Has the employee entered a username and password?
if (empty($user) || empty($password))
{

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>InterHealth HRM Login</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<h2><label>Local System</label></h2>
<hr>
<form action="login.php" method="POST">
<table width="30%" border="0" align="center" class="table">
<tr>
<td colspan="2"><h2><label>Log in</label></h2></td>
</tr>
<tr>
<td colspan="2"><hr></td>
</tr>
<tr>
<td class="table_text"><label>Username:</label></td>
<td><input name="user" title="Enter your username here" type="text"
id="user"></td>
</tr>
<tr>
<td class="table_text"><label>Password:</label></td>
<td><input name="password" title="Enter your password here"
type="password" id="password"></td>
</tr>
<tr>
<td></td>
<td><input name="submit" title="Log in" type="submit" class="button"
value="Log in"></td>
</tr>
</table>
</form>
<hr>
<?

} else
{

// Connect to the database
if (!($connection = @ mysql_pconnect($dbhost, $dbuser,
$dbpassword)))
showerror();

if (!mysql_select_db($database, $connection))
showerror();

$res = mysql_query("LOCK TABLES users READ;", $connection);
if (!$res) {
echo "LOCK failed!";
exit;
}
// Create a query to find any rows that match the username the user
entered
$query = "SELECT * FROM users WHERE username = \"{$user}\"";
$res = mysql_query("UNLOCK TABLES;", $connection);
if (!$res) {
echo "UNLOCK failed!";
exit;
}
// Run the query through the connection
if (!($result = @ mysql_query($query, $connection)))
showerror();

// Were there any matching rows?
if (mysql_num_rows($result) == 0)
{
$message = "The username or password you entered was not found in
the database.";
header("Location: password_finder.php?message=$message");
exit;
} else
{
// Yes. So fetch the matching row
$row = @ mysql_fetch_array($result);

// Does the user-supplied password match the password in the table?
if ($password != $row['password'])
{
// Now, redirect the browser to the current page
header("Location: password_finder.php?message=$message");
exit;
}
}
$type = $row['user_type'];
// Save the user's login name in the session
if (!session_is_registered("user"))
{
session_register("user");
session_register("type");
}
// Everything went ok. Redirect to the next page
header("Location: index.php");
}
?>
</body>
</html>
Jul 16 '05 #1
6 7189
"Agelmar" wrote in message...
Chewy509 wrote:
Hi Everyone,

I'll just start, and say I am not a PHP developer (I'm a sysadmin, who
has gotten lumped with a non-working website). But since I like to do
this type of stuff, I though I might just learn WTF is going on? :)

Basically, sessions are being created, but no info in being stored in
the session, and if data is stored (about 1 in 20 goes), it doesn't
follow-on on a page redirect.

The environment is Win2K Svr SP3, IIS5, PHP4.3.2 (CGI), MySQL 4.0.13.
AFAICT everything is working, as the PHP pages get rendered correctly,
and when user authentication (to MySQL) occurs, no errors are reported
in either PHP logs or MySQL. I've doubled checked the PHP setup, and
php.ini is being read correctly (and varified using phpinfo(); ). All
the session directories are read/write for IUSER_Machine.

Now the interesting thing is, when I first installed PHP about a week
ago, sessions were working fine. Sessions stopped working when I
modified the smtp field in php.ini? (it was the only field I did
modify). The other interesting thing is that when the user goes to the
login page, 3 session files are created?


One guess... you are using really old code (session_register()) which
depends on register_globals = On;
if you have register_globals = Off in php.ini, this will not work. Was there
a php.ini before you added in the bit about smtp and saved it? And is
Register_globals now set to on or off?

Try just using $_SESSION and see if it works.
http://www.php.net/session_register for info on the old method and a bit on
using $_SESSION


Globals has always been off, (as per the 4.3.2 default). I've tried
turning it on, without any effect.

In regard to the php.ini file, there has only been 1 file, which I
made a backup of, and editted the the file. After restoring the backup
copy, it still did not work.

By the way, thanks for the link...
Jul 16 '05 #2
"Agelmar" wrote in message...
Chewy509 wrote:
Hi Everyone,

I'll just start, and say I am not a PHP developer (I'm a sysadmin, who
has gotten lumped with a non-working website). But since I like to do
this type of stuff, I though I might just learn WTF is going on? :)

Basically, sessions are being created, but no info in being stored in
the session, and if data is stored (about 1 in 20 goes), it doesn't
follow-on on a page redirect.

The environment is Win2K Svr SP3, IIS5, PHP4.3.2 (CGI), MySQL 4.0.13.
AFAICT everything is working, as the PHP pages get rendered correctly,
and when user authentication (to MySQL) occurs, no errors are reported
in either PHP logs or MySQL. I've doubled checked the PHP setup, and
php.ini is being read correctly (and varified using phpinfo(); ). All
the session directories are read/write for IUSER_Machine.

Now the interesting thing is, when I first installed PHP about a week
ago, sessions were working fine. Sessions stopped working when I
modified the smtp field in php.ini? (it was the only field I did
modify). The other interesting thing is that when the user goes to the
login page, 3 session files are created?


One guess... you are using really old code (session_register()) which
depends on register_globals = On;
if you have register_globals = Off in php.ini, this will not work. Was there
a php.ini before you added in the bit about smtp and saved it? And is
Register_globals now set to on or off?

Try just using $_SESSION and see if it works.
http://www.php.net/session_register for info on the old method and a bit on
using $_SESSION


Also as another followup, I've turned register_globals = On, and also
added in the php code to "echo (session_id());" at the top of the
login page. However when I attempt to login, the session ID keeps
changing, and 3 session files are being created per login attempt. Is
this normal behaviour?

PS. Sessions are still not working, even with register_globals = On;
Jul 16 '05 #3
Chewy509 wrote:
<snip>
Try just using $_SESSION and see if it works.
http://www.php.net/session_register for info on the old method and a
bit on using $_SESSION


Globals has always been off, (as per the 4.3.2 default). I've tried
turning it on, without any effect.

In regard to the php.ini file, there has only been 1 file, which I
made a backup of, and editted the the file. After restoring the backup
copy, it still did not work.

By the way, thanks for the link...


Have you tried testing sessions separately?

e.g.
page1.php:

<?php
session_start();
$_SESSION['blah'] = "This is stored in the session";
echo 'Click <a href="page2.php">here</a> to go to page 2.';
?>

page2.php
<?php
session_start();
echo 'The value of blah stored in the session is ', $_SESSION['blah'];
?>

If this doesn't work, I'd suspect that it's a permissions problem somewhere
/ somehow. If it does work, I guess I'd take another look at the script.

One other thing I'd check in php.ini - session.use_cookies should be = On;
session.use_trans_sid should also be on just in case a person's browser is
set to reject cookies.

And just out of curiosity, try the following as an alternate to page1.php if
it does not work - (this version explicitly passes the session ID if the
cookie is rejected)

<?php
session_start();
$_SESSION['blah'] = "This is stored in the session";
echo 'Click <a href="page2.php?', strip_tags(SID), '">here</a> to go to page
2.';
?>
Jul 16 '05 #4
Chewy509 wrote:
Also as another followup, I've turned register_globals = On, and also
added in the php code to "echo (session_id());" at the top of the
login page. However when I attempt to login, the session ID keeps
changing, and 3 session files are being created per login attempt. Is
this normal behaviour?

PS. Sessions are still not working, even with register_globals = On;


No, certainly not normal. Try my suggestion in my 7:49pm post to see if
sessions are working at all, but before doing so, I suggest that you clear
out all your temporary internet files and cookies, and try again. I have
seen browsers do wierd things regarding cookies after the cache grows beyond
a certain point. After clearing cache, try closing all browser windows
before making another attempt at it.
Jul 16 '05 #5
also...put this on the second page...

if (isset($_COOKIE["PHPSESSID"]))
{
echo $_COOKIE["PHPSESSID"];
}
else
{
echo "Cookies not turned on in the browser";
}

unless I missed this point in a previous post...maybe you just have cookies
turned off in your browser
--
Chris Mosser

Jul 16 '05 #6
Chewy509 wrote:
After trying your suggestion, sessions are working correctly, so it's
something in the php file I posted. After going over it again, and
triple-checking the php.ini file, found it was a misconfiguration? in
the configuration file (php.ini). In particular the include_path
variable. By default it's set to ".\", however when I set it to
"e:\HRM", sessions started working. (E:\HRM is where the website is
stored on the local machine). So it seems that several includes where
not being included, which was breaking the session handling code... :(

Just like to thank everyone who posted in response to this query. :)


LOL... I dont think I would have thought of that one... :-) Then again,
whenever I do includes, I always supply a full path (usually via the use of
$_SERVER['DOCUMENT_ROOT']) unless it's in the same directory, in which case
I do ./filename

Glad you found the problem and have it working :-)
// Ian
Jul 16 '05 #7

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

Similar topics

19
11125
by: Chris Allen | last post by:
Hi I'm new to PHP and I'm trying to create a Login Form. Once the user has logged in then he shouldn't have to log in again. The trouble is I'm getting a new session ID between every page and so...
14
22551
by: OldGuy | last post by:
Hi All Sendmail 8.12.11 php 4.3.9 Sendmail is installed and works properly. php is NOT in safemode from the command line; mail user@domain.com < testmsg works fine.
2
2357
by: jerry | last post by:
I'm trying to run an application under another user within a winform app writen in C#. I have tried a number of different things, but it seems that the CreateProcessWithLogonW function should work...
1
3434
by: Richard \(MrBonus\) | last post by:
the code is taken from my asp.net page. (written in C#) Hi, im trying to make my page postback before the it unloads, i've tried a lot of stuff, and finally I made something that worked, the...
2
3461
by: Will Freeman | last post by:
Hello all, I saw the post earlier this week that the .Visible property for Tab Pages doesn't work. It seems that the .Enabled property also doesn't work. I would like to only disable one or more...
3
1807
by: Dave Moore | last post by:
Hi All, Ok, here's my problem. I want to open a file and process its contents. However, because it is possible that the file may not exist, I also want to check whether the file() function is...
11
3670
by: Nuno Magalhaes | last post by:
Does anyone know why the BeginAccept doesn't work? If, in the code below, I do the normal Accept function I can get the client socket but it seems that the callback isn't really called. Here's the...
1
4159
by: mathewda | last post by:
Hey, I'm having a problem that I consider kinda weird that is alluding me at the moment. I've wrote some code that will set up an XMLHttpRequest, it then makes a call to open and send and sets the...
4
1378
by: shankari07 | last post by:
hi guys , i have developed a website which works fine in one server but not working in another server. the problem is i have a button which clears up the session variables that is not working...
0
7093
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
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7348
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...
1
7006
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
5592
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,...
1
5021
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
3175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3166
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1519
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.