Jump to content

Why don't these sessions work.


DeepakJ

Recommended Posts

This is my code:

<?php if ($_GET['verif']){
session_start();
$_SESSION['pageselect'] = "verif.php";
echo '<script>window.location = "index.html"</script>';
}
elseif ($_GET['sinput']){
session_start(); 
$_SESSION['pageselect'] = "sinput.php";
echo '<script>window.location = "index.html"</script>';
}
elseif ($_GET['linput']){
session_start();
$_SESSION['pageselect'] = "linput1.php";
echo '<script>window.location = "index.html"</script>';
}
elseif ($_GET['vdata']){
session_start();
$_SESSION['pageselect'] = "viewdata.php";
echo '<script>window.location = "index.html"</script>';
}
elseif ($_GET['rdata']){
session_start();
$_SESSION['pageselect'] = "reportdata.php";
echo '<script>window.location = "index.html"</script>';
}
?>

 

<html><head><title>AlibreCam Verification System</title></head>

<frameset rows="6%,50%">

  <frame src="frame_a.html">
  <frame src="<?php 
  if(isset($_SESSION['pageselect'])){
    echo $_SESSION['pageselect'];
    session_destroy();}
  else{
  echo "verif.html";
  }  
  ?>">
  

</frameset>

</html>

 

 

<html><head><title>AlibreCam Verification System</title></head>


<center><form action=process.php method=get>
<input type="submit" value="Verification" name = "verif">          
<input type="submit" value="Sales Input" name = "sinput">        
<input type="submit" value="License Input" name = "linput">         
<input type="submit" value="View Data" name = "vdata">         
<input type="submit" value="Report Data" name = "rdata">
</form></center>


</html>

Link to comment
https://forums.phpfreaks.com/topic/62933-why-dont-these-sessions-work/
Share on other sites

Well, I'm not sure which session part isn't working, but take a step back for now and look at how repetitve your code is. You could easily simplify that and make it more flexible. Plus, intead of using forms 'n buttons for the process, it would be easiers to make links, with a url being "process.php?page=..."

Example: (it's kinda messy, but you get the point)

//Arrays aren't better than using a class, but for a simple example you'll see what I'm saying
$pages=array(
array("stuff","Stuff to happen"),
array("blarg","Stuff that won't happen"),
array("etc","Et cetera"),
...
);

//process.php - Checking which page to include
$page=$pages[0]; //First page by default, if no others are found
foreach ($pages as $p) {
if ($_GET['page']==$p[0]) { $page=$p; break; }
}
$_SESSION['pageselect']=$page[0].".php"; //I'm not sure why you're doing this in the first place...
header("Location: index.html");

//Outputting the options
echo "Select a step:<ul>";
foreach ($pages as $p) {
echo "<li><a href='process.php?page=$p[0]'>$p[1]</a></li>";
}
echo "</ul>";

Archived

This topic is now archived and is closed to further replies.

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