Jump to content

Disappearing info when browser back button is hit


CloudBreaker
Go to solution Solved by Ch0cu3r,

Recommended Posts

Everything works as it should from login to main to project page.  When it hit the back button on the project page the project values taken from a while loop change depending on which associated l value link  I click on.

 

 

Click on first value, hit back - all values are still there.

Click on second value, hit back - just one value that doesn't belong to the logged in user shows up.

Click on the third value, hit back - no values are shown.

 

It's almost as if I need to disable going back to the previous page using the browser and redirect the user with links that somehow run through the code properly.

 

 

Landing page after log-in:

<!DOCTYPE html>

<?php
session_start(); 

if(!$_SESSION['user_loginName']){
	header("location: index.php");
	}
else {

	$servername = "localhost";
	$username = "root";
	$password = "";
	$dbname = "hsa_project_hub";


// Create connection
	$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
	if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
	
	}
	
		
	
?>	






<!--Project Hub main.  Listed projects are dependant upon login permissions-->

<html>

	<head>
		<title>Project Hub Main</title>

		<link href="hsastyle.css" rel="stylesheet">

	</head>
		<body>
			<div id="main_container">
				<p><em>version 1.0 beta</em></p>
		
				<div id="banner">
			
					<div id="logo">
						<img src="images/hsa-logo.jpg" alt=HSA logo>
					</div>
		
					<h2><em>Project Hub</em></h2>
					<h5><a href="logout.php">Log Out</a></h5>
					<h6>Welcome  <?php echo $_SESSION['firstName'];?></h6>
			
						
				</div> <!--End Banner-->
			
			
				<h1>PROJECTS:</h1><br>
				
				
	<!--List of projects by user -->
	<div class="CSSTableGenerator" >	
		<table align="center">
		
			<tr align="center">
				<th>Project Name</th>
				<th>Project (HSA) No.</th>
				<!--<th>RFI's</th>
				<th>Submittals</th>	-->			
			</tr>


			
	<?php	
	

		//Getting projects from user session variable
			$userid=$_SESSION['id'];
			
			
			
			$sql = "SELECT projects.name,projects.project_id\n"
			. "FROM hsa_users,projects,member_project\n"
			. "WHERE projects.id=member_project.project_id\n"
			. "AND member_project.user_id=$userid\n"
			. "AND hsa_users.id=$userid";
			
			$result=mysqli_query($conn,$sql);
			$row=mysqli_fetch_assoc($result);
			
			
			 $run = mysqli_query($conn, $sql);
			 $i=0;
			 
			 
			 while($row=mysqli_fetch_assoc($run))
			 {
				$projName	=$row['name'];
			 	$projNumber	= $row['project_id'];
				$i++;
				
				
			 
	?>
	
	
		<tr align="center">
				
				
				<td><a href="project.php?id=<?php echo $projNumber; ?>"> <?php echo $projName;?></a></td>
				<td><?php echo $projNumber;?></td>
				
		</tr>		
		
		<?php
			 } //end while loop
		?>
		
		

		</table>
	</div>
					
			</div> <!--End main container-->

Project page = this is the page where the back button is hit in the browser.

?php

	$conn = mysqli_connect("localhost","root","","hsa_project_hub");

	session_start(); 

	if(!$_SESSION['user_loginName']){
	header("location: index.php");
	}
	else {
		
?>



					
<?php

	// retrieve the project id from url, and make sure its a numeric value
	if(isset($_GET['id']) && is_numeric($_GET['id']))
	{
	
	// prepare query, the project id is bound as a value
   
		$stmt = $conn->prepare("SELECT project_id, name, id, address FROM projects WHERE project_id = ?");
	
	 // bind project id value to query
	 
		$id = intval($_GET['id']);
		$stmt->bind_param('i',$id);
		//$stmt->bind_param('i', intval($_GET['id']));  THIS DIDN'T WORK.
		
		//$stmt->bind_param('i',$id)
		
	 // check the stmt did execute
		if($stmt->execute())
		{
	
		// fetch the result from the query
        $result = $stmt->get_result();
        // fetch the row
        if($row = $result->fetch_assoc())
			{
			  // output the project details here
				//echo "Project id: " . $row['id']."<br>";
				//echo "Project Number: " . $row['project_id']."<br>";
				//echo "Project Name: " . $row['name']."<br>";
				//echo "Project ADDRESS: " . $row['address']."<br>";
				
			
			}
		
		 // no row was returned for the project id supplied, display error
			else
			{
            echo 'Project id ' . intval($_GET['id']) . ' does not exist';
			}
		}
    // statement did not execute, trigger an error
			else
		{
        trigger_error('MySQL error, unable to fetch project: ' . $conn->error);
		}
	}

	
	
	
		
		
	
	
?>


<!DOCTYPE HTML>

<html>

	<head>
		<title>Admin Panel</title>

	<link href="hsastyle.css" rel="stylesheet">

	</head>
		<body>
			<div id="main_container">
				<p><em>version 1.0 beta</em></p>
		
				<div id="banner">
			
					<div id="logo">
						<img src="images/hsa-logo.jpg" alt=HSA logo>
					</div>
		
					
					<div id="logout"><H5><a href="logout.php">Log Out</a></H5></div>
					<div id="welcome"><h6>Welcome  <?php echo $_SESSION['firstName'];?></h6></div>
					<div id="project_name">		
						<strong><em><?php echo $row['name']?></em></strong>
					</div>
					
			
						
				</div> <!--End Banner-->
				
			
			<div id="create">
				<FORM>
					<INPUT Type="BUTTON" Value="Create New RFI" Onclick="window.location.href='RFI_create.php'"> 
				</FORM>
			</div>		

			<div id="project">
				<FORM>
					<INPUT Type="BUTTON" Value="Create New Submittal" Onclick="window.location.href='admin_newProject.php'"> 
				</FORM>
				
			</div>	
			
			<div id="user_list">
				<FORM>
					<INPUT Type="BUTTON" Value="View RFI List" Onclick="window.location.href='rfi_list.php'"> 
				</FORM>
				
			</div>	
			
			<div id="project_list">
				<FORM>
					<INPUT Type="BUTTON" Value="View submittal List" Onclick="window.location.href='admin_newProject.php'"> 
				</FORM>
				
			</div>	


		
		
		
		<div class="CSSTableGenerator" >
			<!--project table-->
			<table align="center">
		
				<tr align="center">
				<th>Outstanding RFIs</th>
				<th>Outstanding Submittals</th>
			
			
		</tr>
			
			
			
		</div> <!--End main container-->
		
	
		
		<?php	
		//set SESSION VARIABLES FOR Project
		$_SESSION['projName']=$row["name"];
		$_SESSION['project_id']=$row["project_id"];	
		$_SESSION['id']=$row["id"];
		
		
		
		?>

	
			
					
				
		
		
		
		</body>
		
		
</html>


<?php } ?>
Link to comment
Share on other sites

Just from a quick peak... on the landing page you are creating the $userid = $_SESSION['id']. On the project page you are changing the $_SESSION['id'] to $row['id'] which I assume is the row associated with the project. So when you hit the back button, the $userid is now different and picking up whatever ID was associated with the project from the project page. I think.

  • Like 1
Link to comment
Share on other sites

  • Solution

akphidelt2007 is correct, line 160 ( $_SESSION['id']=$row["id"]; ) in project.php is overwriting the user id stored in $_SESSION['id']. This is why it does not show the users projects when you hit the browsers back button.

 

I do not see why the project info need to be saved in the session for? Whats the purpose for this?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.