473,799 Members | 2,985 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.in c";

// 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>InterHea lth 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>Loca l System</label></h2>
<hr>
<form action="login.p hp" 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_te xt"><label>User name:</label></td>
<td><input name="user" title="Enter your username here" type="text"
id="user"></td>
</tr>
<tr>
<td class="table_te xt"><label>Pass word:</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("LO CK 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("UN LOCK TABLES;", $connection);
if (!$res) {
echo "UNLOCK failed!";
exit;
}
// Run the query through the connection
if (!($result = @ mysql_query($qu ery, $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("Locatio n: password_finder .php?message=$m essage");
exit;
} else
{
// Yes. So fetch the matching row
$row = @ mysql_fetch_arr ay($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("Locatio n: password_finder .php?message=$m essage");
exit;
}
}
$type = $row['user_type'];
// Save the user's login name in the session
if (!session_is_re gistered("user" ))
{
session_registe r("user");
session_registe r("type");
}
// Everything went ok. Redirect to the next page
header("Locatio n: index.php");
}
?>
</body>
</html>
Jul 16 '05 #1
6 7204
"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_regist er()) which
depends on register_global s = On;
if you have register_global s = 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_global s 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_regist er()) which
depends on register_global s = On;
if you have register_global s = 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_global s 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_global s = 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_global s = 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_coo kies should be = On;
session.use_tra ns_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_global s = 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_global s = 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 misconfiguratio n? 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
11153
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 it doesn't recognise the user. I've used Session_Start() which I thought was meant to maintain the session variables between pages but it doesn't do work. Any ideas or FAQ's?
14
22634
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
2390
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 to do what I need to do. This appears to work just fine in Windows 2000 and XP with service pack 1, but it doesn't work with XP service pack 2 installed. I'm sure it's one of the "Enhanced security features" of service pack 2, but I can't...
1
3462
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 problem is the alert in the code -- alert('TittyX'); --. If I remove it, then it doesn't work, well the method runs fine, but I can't catch the -- theform.submit(); --. Another weird thing, is I can only catch the event in the Page_Load event on...
2
3479
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 tab pages based on 'on-the-fly' criteria, but make them disappear altogether. Is this not possible? Workarounds? TIA, Will
3
1822
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 successful before attempting to process any returned data from the file() function. The php file() manual page suggests that it returns FALSE if it is unsuccessful, however this simply doesn't happen on my system. My code looks like the following: ...
11
3707
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 code: ----------------------------- private Socket socket; private Socket clientSocket; public TcpServer(string serverIP,int serverPort) {
1
4183
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 onreadystatechange to another function of mine. onreadystatechange checks the ready state and if the ready state is 4 and the status is 200 it assigns to the innerHTML of a div. I also have some code that uses the attachEvent method so that all...
4
1392
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 properly. here is the code: if(($clear == 'Clear')) { $_SESSION = ""; $_SESSION = "";
0
9540
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10475
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10222
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10026
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5463
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4139
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 we have to send another system
2
3757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.