Hi,

I have uploaded all my php pages to the server and everything runs perfectly fine. There is just one problem. When i click the refresh button on any page, the user is automatically logged out (session destroyed) and is directed to the login page. When i was refreshing the page on my local server, there was no problem like this. Is there any solution to this problem?

Thanks

Recommended Answers

All 8 Replies

You have to post your code first..

Here is my code:

<?php
session_start();
require("afterlogout.php");
require("globals.php");
?>

<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">

<head>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
	<meta name="description" content=""/>
	<meta name="keywords" content="" />
	<meta name="author" content="" />
	<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
      <link rel="stylesheet" type="text/css" href="dropdown.css" media="screen" />
	<style type="text/css">
<!--
.style1 {font-size: 120%}
.style2 {
	font-size: medium;
	color: #000000;
}
.style4 {
	color: #000000;
	font-size: 1.2em;
}
.style5 {
	font-size: medium;
	font-weight: bold;
}
-->
    </style>
    <script src="../SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
    <link href="../SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css">
    
      <script type="text/javascript">
	
		function submitPage()
			{
			document.userform.action= 'expenselocation.php';
  		    document.userform.submit();
			}
		</script>	
              <?php
			 	if(isset($_POST['Ok']))
				{
				
				$description = $_POST['description'];
				
				$query = "INSERT into tblexpenselocation (Description) VALUES ('$description');";
				 
				 $result = mysql_query($query) or die(mysql_error());
				 header( 'Location: expenselocation.php') ;
				 }
			    ?>
        
              <style type="text/css">
<!--
.style6 {color: #000000}
-->
              </style>
</head>
<title>Complete Systems Automation</title> 
<body>

<div id="header">
	<div class="center_wrapper">
		<span class="right">
				  <a id="linkcolor" href="userinfo.php">My Account</a> <div id="toplinks"><?php include("displayusername.php");?></div>&nbsp;&nbsp;
		<a href="logout.php" id="linkcolor">Logout</a></span> <div class="clearer">&nbsp;</div>

		<div id="site_title">
			<h1 align="center"><a href="#" class="style1">Complete Systems Automation</a></h1>
	  </div>

  </div>
</div>

<div id="navigation">
	<div class="center_wrapper">
	
		<ul>
			<?php include("header.html");?>
      </ul>
		<div class="clearer">&nbsp;</div>

	</div>
</div>

<div id="main_wrapper_outer">
	<div id="main_wrapper_inner">
		<div class="center_wrapper">

			<div class="left" id="main">
		
   <form name="userform" method="post" action="">	
	  
               <p align="center" class="style5 style6">Add Expense Location</p>
                <p align="center" class="style5">&nbsp;</p>
                <p align="center" class="style5">&nbsp;</p>
                <p align="center" class="style5">&nbsp;</p>
            <p><span class="style4">Description*</span>&nbsp;<span id="sprytextfield1">
              <input name="description" type="text" id="description" tabindex="1" value="" size="50" maxlength="100" autocomplete="off">
            <span class="textfieldRequiredMsg">Required</span></span>
            			
                <div align="center">
                  <p>
  <input type="submit" name="Ok" id="Ok" value="Ok" tabindex="2">
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <input type="button" name="Cancel" value="Cancel" tabindex="3" onClick="javascript:submitPage();" />
                  </p>
                </div>
			  </form>
			  <p align="center" class="style2">&nbsp;</p>
			  <p align="center">&nbsp;</p>
			</div>

		  <div class="clearer">&nbsp;</div>

		</div>
	</div>
</div>


<div id="footer">
	<div class="center_wrapper"><span class="left">&copy; 2009 Complete  Systems Automation, Inc. </span>
	  <div class="right"></div>
		
	  <div class="clearer">&nbsp;</div>

  </div>
</div>

<script type="text/javascript">
<!--
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
//-->
</script>
</body>
</html>

Just so you know, you cannot add headers after the first character (outside the PHP tags) has been written. Also, a few of your CSS properties will throw up some errors. I also noticed that you use javascript to submit your form. This doesn't seem necessary (You can set the form action with the action attribute and a input element of type submit will submit the form by default.

This means that i should write my header line something like this :

<?php
session_start();
require("afterlogout.php");
require("globals.php");

		 	    if(isset($_POST['Ok']))
				{
 				$description = $_POST['description'];
 $query = "INSERT into tblexpenselocation (Description) VALUES ('$description');";
 		 $result = mysql_query($query) or die(mysql_error());
				 header( 'Location: expenselocation.php') ;
				 }
			    ?>

Would it solve the problem with refresh?

This means that i should write my header line something like this :

<?php
session_start();
require("afterlogout.php");
require("globals.php");

		 	    if(isset($_POST['Ok']))
				{
 				$description = $_POST['description'];
 $query = "INSERT into tblexpenselocation (Description) VALUES ('$description');";
 		 $result = mysql_query($query) or die(mysql_error());
				 header( 'Location: expenselocation.php') ;
				 }
			    ?>

Would it solve the problem with refresh?

Yes, that's where you should put it! But sadly, no it won't fix your session problem. It will just prevent an error message from showing up when you try to redirect to that page.

Always try to use HTML action button to submit your page if you do not have any javascript checks.

Always try to use HTML action button to submit your page if you do not have any javascript checks.

Exactly! Why use javascript when you can simply use a submit button that does the same job!

I think you are getting this error because of that login page. Actually I have faced that with one of my client's website. So please try to do it as BzzBee told. I mean try to make your login page in HTML form. It will work absolutely good....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.