473,609 Members | 2,241 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Session doesn't work

I'm trying to use sessions to allow people to log into my site. The problem
is that sometimes it works and sometimes it doesn't! As far as I'm aware my
script is fine (hence why it works sometimes) and I've had people tell me
it's fine too. Basically, when a user enters their username and password it
checks that against my mysql database and if correct creates a session and
stores their username in it in a variable called uname. Then, when they
access another area of the site it checks to see if uname is set and if it
is then it lets them access that area and if it isn't asks them to log in
again. The session id is kept so I know the session is there but it doesn't
always register the variable uname. I think the php version is 4.1.2 (it's
hosted on sourceforge).

I've listed three files below. admin.php is where the user enters their
username and password. admin2.php is where it checks the username and
password and displays the admin section and addnews.php allows you to add
news to the site. It's when I try to add news when it sometimes works and
sometimes doesn't. When I click add news half of the time it shows the add
news section and half of the time it doesn't. This is because uname isn't
set when it should be (and is half of the time). If you want to see the site
go to http://linrar.sourceforge.net/index2.php (I will rename it index.php
once the site works).

admin.php

<?php
session_start() ;
session_unset() ;
session_destroy ();
?>
<html>
<head>
<link rel="stylesheet " type="text/css" href="style.css ">
<title>LinRAR Homepage</title>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" >
<tr>
<td>
<table border="0" cellpadding="10 " cellspacing="0" >
<tr>
<td width="122" valign="top">
<table width="122" border="0" cellpadding="2" cellspacing="0"
bgcolor="#00000 0">
<tr>
<td>
<table width="120" border="0" cellpadding="5" cellspacing="0"
bgcolor="#fffff f">
<tr>
<td>
<a href=index.php> News</a><br>
<a href=about.php> About</a><br>
<a href=download.p hp>Download</a><br>
<a href=support.ph p>Support</a><br>
<a href="http://sourceforge.net/projects/linrar">Sourcef orge</a><br>
<a href="admin.php ">Admin</a><br>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td valign="top">
<h1>LinRAR - Admin</h1>
<br>
To log in to the admin section type in your username and password below and
click enter:<br><br>
<form action=admin2.p hp method=post>
<table>
<tr><td>
UserName</td><td><input type="text" name="lruname"> </td></tr>
<tr><td>
Password</td><td><input type="password" name="lrpass"></td></tr>
</table>
<br>
<input type="submit" value="Enter" class="flatbutt on">
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>

admin2.php

<?php
session_start() ;
?>
<html>
<head>
<link rel="stylesheet " type="text/css" href="style.css ">
<title>LinRAR Homepage</title>
</head>
<body>
<?php
$notfounduser = 0;
$passwordincorr ect = 0;
$db = "linrar";
$user = "linrar";
$pass = "linrardb";
$link = mysql_connect(" mysql.sourcefor ge.net", $user, $pass);
mysql_select_db ($db, $link)
or die("Couldn't open $db: ".mysql_error() );
$result = mysql_query("SE LECT * from users");
$num_rows = mysql_num_rows( $result);
while ($a_row = mysql_fetch_arr ay($result))
{
if ($a_row[lruname] != $lruname)
$notfounduser = 1;
else
{
$notfounduser = 0;
$lrpass = md5($lrpass);
if ($a_row[lrpass] != $lrpass)
$passwordincorr ect = 1;
}
if ($notfounduser == 0)
break;
}

if ($notfounduser == 1)
print "User $lruname was not found.";
if ($passwordincor rect == 1)
print "Incorrect password entered for user $lruname.";

if ($notfounduser == 0 && $passwordincorr ect == 0)
{
session_registe r("uname");
$uname = $lruname;
print "<table border=0 cellpadding=0 cellspacing=0>" ;
print "<tr>";
print "<td>";
print "<table border=0 cellpadding=10 cellspacing=0>" ;
print "<tr>";
print "<td width=122 valign=top>";
print "<table width=122 border=0 cellpadding=2 cellspacing=0
bgcolor=#000000 >";
print "<tr>";
print "<td>";
print "<table width=120 border=0 cellpadding=5 cellspacing=0
bgcolor=#ffffff >";
print "<tr>";
print "<td>";
print "<a href=\"index.ph p\">Back (Logout)</a><br>";
print "<a href=\"addnews. php?".session_n ame()."=".sessi on_id()."\">Add
News</a><br>";
print "<a href=\"addadmin .php?".session_ name()."=".sess ion_id()."\">Ad d
Admin</a><br>";
print "<a
href=\"changepw d.php?".session _name()."=".ses sion_id()."\">C hange
Password</a><br>";
print "<a href=BoardPlus/forum.html>Foru m</a><br>";
print "<a href=\"phpMyAdm in-2.5.1\"</a>phpMyAdmin<br >";
print "<a href=count.php> Site Stats</a><br>";
print "</td>";
print "</tr>";
print "</table>";
print "</td>";
print "</tr>";
print "</table>";
print "</td>";
print "<td valign=top>";
print "<h1>LinRAR - Admin</h1>";
print "<br>";
print "Welcome $uname to the admin section.";
}
?>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>

addnews.php

<?php
session_start() ;
?>
<html>
<head>
<link rel="stylesheet " type="text/css" href="style.css ">
<title>LinRAR Homepage</title>
</head>
<body>
<?php
if (session_is_reg istered("uname" ))
{
print "<table border=0 cellpadding=0 cellspacing=0>" ;
print "<tr>";
print "<td>";
print "<table border=0 cellpadding=10 cellspacing=0>" ;
print "<tr>";
print "<td width=122 valign=top>";
print "<table width=122 border=0 cellpadding=2 cellspacing=0
bgcolor=#000000 >";
print "<tr>";
print "<td>";
print "<table width=120 border=0 cellpadding=5 cellspacing=0
bgcolor=#ffffff >";
print "<tr>";
print "<td>";
print "<a href=\"index.ph p\">Back (Logout)</a><br>";
print "<a href=\"addnews. php?".session_n ame()."=".sessi on_id()."\">Add
News</a><br>";
print "<a href=\"addadmin .php?".session_ name()."=".sess ion_id()."\">Ad d
Admin</a><br>";
print "<a href=\"changepw d.php?".session _name()."=".ses sion_id()."\">C hange
Password</a><br>";
print "<a href=BoardPlus/forum.html>Foru m</a><br>";
print "<a href=\"phpMyAdm in-2.5.1\"</a>phpMyAdmin<br >";
print "<a href=count.php> Site Stats</a><br>";
print "</td>";
print "</tr>";
print "</table>";
print "</td>";
print "</tr>";
print "</table>";
print "</td>";
print "<td valign=top>";
print "<h1>LinRAR - Add News</h1>";
print "<br>";

if ($changed == 1)
{
$dateadded = time();
$db = "linrar";
$user = "linrar";
$pass = "linrardb";
$link = mysql_connect(" mysql.sourcefor ge.net", $user, $pass);

if (!$link)
die ("Couldn't connect to MySQL: ".mysql_error() );
mysql_select_db ($db)
or die("Couldn't connect to database $db: ".mysql_error() );

$query = "INSERT INTO news VALUES ('$uname', '$dateadded', '$ntitle',
'$nmessage')";

mysql_query($qu ery, $link)
or die ("Couldn't add data to the table: ".mysql_error() );

mysql_close($li nk);
print "The following news has been added...<br><br >";
print "Title: $ntitle<br><br> ";
print "Message: $nmessage<br><b r>";
print "Posted by: $uname<br><br>" ;
$dateadded = date("d/m/y", $dateadded);
print "Date added: $dateadded<br>" ;
}
else
{
print "<form action=addnews. php?$sess&chang ed=1 method=post>";
print "Title <input type=text size=50 name=ntitle><br ><br>";
print "Message<br >";
print "<textarea rows=5 cols=70 name=nmessage></textarea><br><b r>";
print "<input type=submit value=Add>";
print "</form>";
}
}
else
{
print "Not logged in. <a href=admin.php> Click Here</a> to log in.";
}
?>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>

Jul 16 '05 #1
0 4019

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

Similar topics

5
6469
by: Peter | last post by:
L.S. I am developing a PHP-login script (on Lycos Tripod) that uses Session to pass on variables. Below is the entire (stripped) structure that I use. It opens a page where you can Set and Read the session variable BUT ... It doesn't work!!! It seems that both set- and readlink open their own private session. How can I get the read-link to access the proper session variable?
1
7775
by: Paul | last post by:
Hmmm, didn't seem to work. I have set session.use_cookies = 1 and session.use_trans_sid = 1 in my php.ini file. Index.php contains: ---------------------------------------------------------------------------- <?php ini_set("session.use_cookies", "off"); ini_set("session.use_trans_sid", "on"); session_start(); $_SESSION = ""; $_SESSION = ""; echo "<form method='POST' action='login.php'>
14
3214
by: Paul Yanzick | last post by:
Hello, I am trying to develop a book tracking application for my capstone in school, and am running into a problem. The application is an ASP.Net application written in C#. The first page you go to is a login form, which will set several session variables with the name used to log in, appropriate security level and some other misc variables, and then will go to a main menu for each particular security level using Server.Transfer. ...
2
3378
by: Jim Owen | last post by:
I know I';ve posted on this topic before, but it still doesn't work. I have a Session_End event in my Global.asax file, but it never fires. I have gone into my web.config file and in session state I changed the timeout to "2" and made sure the mode was "InProc". Then I opened my app, did some stuff, and closed it, expecting in two minutes' time the Session_End event would fire (It updates the database from the Cache). But it doesn't....
9
2376
by: Greg Linwood | last post by:
I'm having difficulty understanding Session state in ASP.Net. It's almost embarrassing asking this as I've been using ASP since it was first released & it really shouldn't be this hard to use - perhaps I'm just not very smart or perhaps MS is making this too hard for us sql bunnies to understand - I dunno, but I'd really appreciate someone explaining what I'm doing wrong here & perhaps suggest a better approach.. I'm familiar with use of...
10
3497
by: tshad | last post by:
I have been using the default session state (InProc) and have found that I have been loosing my information after a period of time (normally 20 minutes). Is there anyway to find out how much more time I have on a session? If I do a refresh, does reset the session clock? Do you have have to go to another page to reset the session timeout or will a postback also do it? This is important as we have a few pages that a user
6
3765
by: Bahman | last post by:
Hello! I have a simple question. Do we have session arrays that we can reference, assign, or select from? Could I please have a sample of how this is done. The obvious syntax that I am trying doesn't work. There are SA's in VB, but I am not seeing anything for C#.
1
19250
by: zzzbla | last post by:
Hello, I have a project in which I'm trying to embed one site, that uses session stored variables, inside an IFRAME in another site (which for that matter doesn't even use sessions). Problem is, that it doesn't always save the session. When I try to access it from some computers, I have no problem, the session variable is stored and I can browse the site in the IFRAME and everything's ok, but on other computers, the session variable...
18
3428
by: BillE | last post by:
When a user opens a new IE browser window using File-New-Window the integrity of an application which relies on session state is COMPLETELY undermined. Anyone who overlooks the fact that File-New-Window creates an instance of IE in the same process with the same SessionID as the parent window is in big trouble. This fundamentally restricts the usefullness of using session state management. I probably missed it somewhere - can...
9
7793
by: Josh | last post by:
I run a Joomla website and am familiar with php in some but not all aspects. Currently I am trying to find some solutions related to session handling. Am I correct in saying that "login" is kept in sessions? I can see active sessions in my mysql database, but is that the only place this information is stored? Sessions and cookies I know are related also, but how specifically (session info stored in cookies?)? Right now, when users...
0
8113
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8051
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
8557
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
8203
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,...
1
6047
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5504
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4066
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2517
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
0
1373
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.