0

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

5
Contributors
8
Replies
9
Views
7 Years
Discussion Span
Last Post by harshbavaliya
0

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>
0

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.

Edited by FlashCreations: n/a

0

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?

0

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.

0

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

0

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!

0

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....

Edited by harshbavaliya: subject change...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.