Thursday, 29 August 2013

PHP including files it shouldnt because of an if condition

PHP including files it shouldnt because of an if condition

Hi I have a crazy probem.
I try to Include different files depending on conditions. The code is the
following:
if($_SESSION['initial'] == 1){
require_once('ask_q.php');
exit("INITIAL");
}
elseif(isset($_POST['start_time'])){
$_SESSION['menu'][$menu_id]['task'][$task_id]['start_time'] = time();
$_SESSION['menu'][$menu_id]['task'][$task_id]['clicks'] = 0;
require_once($_SESSION['menu'][$menu_id]['file']);
exit('CASE 2');
// Wenn gesuchte Kategorie gefunden wurde
}elseif( $cat_wanted == $cat_current){
$_SESSION['menu'][$menu_id]['task'][$task_id]['end_time'] = time();
$_SESSION['menu'][$menu_id]['task'][$task_id]['clicks']++;
$_SESSION['menu'][$menu_id]['task'][$task_id]['done'] = 1;
$_SESSION['progress']++;
require_once('ask_q.php');
exit('CASE 3');
// Wenn gesuchte Kategorie noch nicht gefunden wurde Seite anzeigen
}elseif( $cat_current != $cat_wanted ){
echo 'Cat Wantet: ' . $cat_wanted . ' != ' . $cat_wanted . ' :Cat
Current';
$_SESSION['menu'][$menu_id]['task'][$task_id]['clicks']++;
require_once($_SESSION['menu'][$menu_id]['file']);
exit('CASE 4');
}else{
exit('CASE 5');
}
The weird thing is, that at the right point its including the ask_q.php
file (Case 3) but also Case 4. I'm wondering because I exited after
including by require_once(). And it's even more weird, that the stuff from
Case 4 which is included is invisible. I only recognized it in firebug
that the content and some included files are changing the optics.
A nother crazy thing is that in Case 4 I give out the conditions in a
string and they dont match with the condition :(
AND if i watch at the normal sourcecode it only matches with the file
which should be not included but not with the one which is included at all
I know all this sounds realy stupid but I never had a problem like this. I
allready checkt the includet files but its only depending on the main file
which is including all other files by conditions.
SO this is stuff from the ask_q.php:
<!DOCTYPE html>
<?php
/*
| Reihenfolge || Aufgabennummer |
-+--------------++--------------------+-
| TD | SP | R || T TD | T SP | T R |
-+----+----+----++------+------+------+-
| 1 | 2 | 3 || 1 | 2 | 3 |
| 1 | 3 | 2 || 2 | 3 | 1 |
| 2 | 1 | 3 || 3 | 1 | 2 |
| 2 | 3 | 1 || 1 | 3 | 2 |
| 3 | 1 | 2 || 2 | 1 | 3 |
| 3 | 2 | 1 || 3 | 2 | 1 |
Aufgabennummer:
Task1: Top-News -> Wirtschaft -> Reise -> Wissen -> Wirtschaft
Task2: Top-News -> Wissen -> Sport -> Netzwelt -> Wissen
Task3: Top-News -> Kultur -> Top-News -> Reise -> Kultur
*/
$_SESSION['initial'] = 0;
$menu_id = intval($_SESSION['progress']/3) + 1;
$task_id = $_SESSION['progress'] % 4;
?>
<html>
<head>
<title>Aufgabe <?php echo ($_SESSION['progress'] + 1);?></title>
<link href="css/bootstrap.no-icons.css" rel="stylesheet">
<link href="css/font-awesome.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="css/style.css">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta content='width=device-width, initial-scale=1.0,
maximum-scale=1.0, user-scalable=0' name='viewport' />
</head>
<body id="task">
<h2>Augabe <?php echo ($_SESSION['progress'] + 1);?></h2>
<p>Finde den Artikel <strong>"<?php echo
$_SESSION['menu'][$menu_id]['task'][$task_id]['article'];?>"</strong>
in der Kategorie <strong>"<?php echo
$_SESSION['menu'][$menu_id]['task'][$task_id]['category'];?>"</strong></p>
<form id="start_task" method="post" action="experiment.php">
<input type="hidden" name="start_time" value="1">
<input type="submit" value="Los gehts">
</form>
<?php echo '<pre style="clear:both;">'; print_r($_SESSION); echo
'</pre>';?>
</body>
</html>

No comments:

Post a Comment