0

嗨,我有一个疯狂的问题。

我尝试根据条件包含不同的文件。代码是experiment.php的以下代码:

    <?php session_start();
/*

MO = Menu-Order

TD = Top-Down-Menu
SP = Side-Pull-Menu
R  = Radial-Menu

   | Reihenfolge  || Aufgabennummer     |
---+--------------++--------------------+-
MO | TD | SP |  R || T TD | T SP |  T R |
---+----+----+----++------+------+------+-
 1 |  1 |  2 |  3 ||    1 |    2 |    3 |
 2 |  1 |  3 |  2 ||    2 |    3 |    1 |
 3 |  2 |  1 |  3 ||    3 |    1 |    2 |
 4 |  2 |  3 |  1 ||    1 |    3 |    2 |
 5 |  3 |  1 |  2 ||    2 |    1 |    3 |
 6 |  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

*/

    //echo '<pre>'; print_r($_SESSION); echo '</pre>';

    $task_1 = array(
        0 => array(
            'category' => 'Wirtschaft',
            'article'  => 'Faule Kredite steigen auf Rekordniveau',
            'done'     => 0,
            'clicks'   => 0,
            'start_time' => 0,
            'end_time'   => 0
        ), 
        1 => array(
            'category' => 'Reise',
            'article'  => 'Die Haxen des Bösen',
            'done'     => 0,
            'clicks'   => 0,
            'start_time' => 0,
            'end_time'   => 0
        ), 
        2 => array(
            'category' => 'Wissen',
            'article'  => 'Kulante Eltern haben kulante Kinder',
            'done'     => 0,
            'clicks'   => 0,
            'start_time' => 0,
            'end_time'   => 0
        ), 
        3 => array(
            'category' => 'Wirtschaft',
            'article'  => 'Schweiz stoppt Skilift-Lieferung an Kim Jong Un',
            'done'     => 0,
            'clicks'   => 0,
            'start_time' => 0,
            'end_time'   => 0
        )
    );


    $task_2 = array(
        0 => array(
            'category' => 'Wissen',
            'article'  => 'Delfinsterben bleibt Rätselhaft',
            'done'     => 0,
            'clicks'   => 0,
            'start_time' => 0,
            'end_time'   => 0
        ), 
        1 => array(
            'category' => 'Sport',
            'article'  => 'Almaty bewirbt sich um Winterspiele 2022',
            'done'     => 0,
            'clicks'   => 0,
            'start_time' => 0,
            'end_time'   => 0
        ), 
        2 => array(
            'category' => 'Netzwelt',
            'article'  => 'Samsung kürt geklautes Bild zum Siegerfoto',
            'done'     => 0,
            'clicks'   => 0,
            'start_time' => 0,
            'end_time'   => 0
        ), 
        3 => array(
            'category' => 'Wissen',
            'article'  => 'Kulante Eltern haben kulante Kinder',
            'done'     => 0,
            'clicks'   => 0,
            'start_time' => 0,
            'end_time'   => 0
        )
    );

    $task_3 = array(
        0 => array(
            'category' => 'Kultur',
            'article'  => 'Spanische Rentnerin soll an Einnahmen beteiligt werden',
            'done'     => 0,
            'clicks'   => 0,
            'start_time' => 0,
            'end_time'   => 0
        ), 
        1 => array(
            'category' => 'Top-News',
            'article'  => 'Unfallserie blockiert Rhein in Köln',
            'done'     => 0,
            'clicks'   => 0,
            'start_time' => 0,
            'end_time'   => 0
        ), 
        2 => array(
            'category' => 'Reise',
            'article'  => 'Verkehrschaos in der Lagune',
            'done'     => 0,
            'clicks'   => 0,
            'start_time' => 0,
            'end_time'   => 0
        ), 
        3 => array(
            'category' => 'Kultur',
            'article'  => 'Schlaflos mit Schlingel',
            'done'     => 0,
            'clicks'   => 0,
            'start_time' => 0,
            'end_time'   => 0
        )
    );

    $sp = 'index-sidepull.php';
    $r  = 'index-radial.php';
    $td = 'index-topdown.php';


    $menu_order = 1;

    // Fortschritts Variablen setzen wenn nicht gesetzt

    if(!isset($_SESSION['progress']) or !isset($_SESSION['initial'])){
        $_SESSION['progress'] = 0;
        $_SESSION['initial']  = 1;
    }

    // Fortschritt initialisieren wenn nicht vorhanden

    if($_SESSION['progress'] == 0){

        $_SESSION['menu'][1]['done'] = 0;
        $_SESSION['menu'][2]['done'] = 0;
        $_SESSION['menu'][3]['done'] = 0;

        /*
         *
         * Menüreihenfolgen bestimmen
         *
         */ 

        if($menu_order == 1){

            $_SESSION['menu'][1]['file'] = $td;
            $_SESSION['menu'][2]['file'] = $sp;
            $_SESSION['menu'][3]['file'] = $r;

            $_SESSION['menu'][1]['task'] = $task_1;
            $_SESSION['menu'][2]['task'] = $task_2;
            $_SESSION['menu'][3]['task'] = $task_3;


        }elseif($menu_order == 2){

            $_SESSION['menu'][1]['file'] = $td;
            $_SESSION['menu'][2]['file'] = $r;
            $_SESSION['menu'][3]['file'] = $sp;

            $_SESSION['menu'][1]['task'] = $task_2;
            $_SESSION['menu'][2]['task'] = $task_3;
            $_SESSION['menu'][3]['task'] = $task_1;

        }

    }




    // Anhand des aktuellen Fortschritts Menü und Aufgabe herausfinden

    $menu_id = intval($_SESSION['progress']/3) + 1;
    $task_id = $_SESSION['progress'] % 4;

    $cat_wanted  = strtolower($_SESSION['menu'][$menu_id]['task'][$task_id]['category']);
    $cat_current = str_replace('-', '', $_GET['topic']);

    // Wenn aufgabenstellung gelesen und auf start geklickt wurde

    if($_SESSION['initial'] == 1){
        //exit();
        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;
        //exit();
        require_once($_SESSION['menu'][$menu_id]['file']);
        break;
        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');
    }


?>

奇怪的是,它在正确的位置包括了 ask_q.php 文件(案例 3)以及案例 4。我想知道,因为我在包含 require_once() 后退出了。更奇怪的是,案例 4 中包含的东西是看不见的。我只在萤火虫中认识到内容和一些包含的文件正在改变光学。

另一个疯狂的事情是,在案例 4 中,我给出了字符串中的条件,但它们与条件不匹配:(

如果我看普通的源代码,它只与不应该包含的文件匹配,但与根本不包含的文件不匹配

我知道这一切听起来很愚蠢,但我从来没有遇到过这样的问题。我已经检查了包含文件,但它仅取决于按条件包含所有其他文件的主文件。

所以这是来自 ask_q.php 的东西:

<!DOCTYPE html> 
<?php

$_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>

这是另一个文件的源代码:

<!DOCTYPE html >
<html>
    <head>
        <title>World News</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">
        <link rel='stylesheet' href='http://fonts.googleapis.com/css?family=UnifrakturCook:700|Rye|UnifrakturMaguntia' type='text/css'>
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
        <script src="js/jquery.js" type="text/javascript"></script>
        <!--<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>!-->
        <script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
        <script src="js/topdown.js" type="text/javascript"></script>
        <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>

            <div data-role="page">
                <nav id="topdown">
                    <div id="menu-items">
                        <?php require_once('nav-topdown.php');?>
                    </div>
                </nav>


                <header>
                    <?php require_once('header.php');?>
                </header>

                <div id="main-topdown">
                     <div style="height:43px"></div>
                    <?php require_once('content.php');?>
                    <?php //echo 'Cat Wantet = ' . $cat_wanted;?>
                </div>
                <?php echo '<pre style="clear:both;">'; print_r($_SESSION); echo '</pre>';?>
            </div>


            <div data-role="dialog" id="dialogPage">
                <div data-role="header">
                    <h2>Aufgabe</h2>
                </div>
                <div data-role="content">
                    <p>Finde den Artikel <strong>"<?php echo $_SESSION['menu'][$i]['task'][$j]['article'];?>"</strong> 
                    in der Kategorie <strong>"<?php echo $_SESSION['menu'][$i]['task'][$j]['category'];?>"</strong></p>
                    <a id="start" data-theme="b" data-rel="back" data-role="button" href="#" data-corners="true" data-shadow="true" data-iconshadow="true" data-wrapperels="span" data-transition="pop" data-direction="reverse">
                    Los gehts!
                </a>
                </div>

            </div>

        <script>

            function initResize(){
                $('#topdown').hide();
            }

            $(document).ready(function(){

                initResize();

                var category = "<?php echo $_SESSION['menu'][$i]['task'][$j]['category']; ?>";
                var article  = "<?php echo $_SESSION['menu'][$i]['task'][$j]['article']; ?>";

                //alert('Aufgabe', 'Finde den Artikel <strong>"' + article + '"</strong> in der Kategorie <strong>"' + category + '"</strong>');

                $("#start").click(function(){
                   $.ajax({
                      type: "POST",
                      url: "ajax.php",
                      data: {task_start: new Date().getTime()},
                      success: function(){
                           $('.ui-dialog').dialog('close');
                      }
                   });

                   return false;
                });

                //console.log($('#main').css('height')); 
                $('#menu-link').click(function(){

                    if( $('#topdown').css('display') != 'block'){

                        $('#topdown').fadeIn();
                    }else{
                        $('#topdown').hide();
                    }
               });


            });

            $(window).resize(function(){
                //initResize();
            });

        </script>

    </body>
</html>

实际上,我只认识到存在问题,因为我看到了 ask_q.php 的内容,但还包含 jquery-mobile,这显然不包含在 ask_q.php 中。如果我打开源代码,它只会向我显示另一个文件的源代码(不是 ask_q.php),但是当我只是在浏览器中观看它时,它根本不会显示任何内容。

4

2 回答 2

0

我无法发表评论,因为我的声誉不够高。就我个人而言,我认为还有其他一些我们没有看到的导致问题的原因。

明显的问题是:

  • $cat_wanted 和 $cat_current 在哪里设置和更改?- 我们看不到
  • 您给出的代码周围的其余代码在哪里?
  • 您提供的代码本身是否包含在内?
  • 当不 ask_q.php 时,您包含的文件的位置是什么?我们看不到他们的名字。
  • 如果其中一个文件正在运行然后调用 ask_q.php 怎么办?

观察

  • 你不需要最后一个 elsif。只需将其设为 ELSE。如果 $cat_wanted != $cat_current 那么你不必再计算它是否 ==
  • 不必经常引用 $_SESSION['menu'][$menu_id]['task'][$task_id] 只需设置 $_s =& $_SESSION['menu'][$menu_id]['task'][ $task_id]; 并改用 $_s 。
于 2013-08-29T13:13:00.877 回答
0

为了找到一个解决方案,我刚刚退出了 jquery-mobile,一切正常。源代码看起来不错,一切都很好。

仍然不知道为什么这不起作用。在检查了你所有的答案后,没有任何帮助:(((

于 2013-08-29T15:20:09.710 回答