简体   繁体   English

PHP会话显示以前的会话值

[英]php session displaying previous session values

I am calling a console application from php which gives me some output. 我正在从php调用控制台应用程序,这给了我一些输出。 I have to display the output in a div after the console application is executed. 执行控制台应用程序后,我必须在div中显示输出。 I have passed the output from the console application as a SESSION to another page to display it. 我已经将控制台应用程序的输出作为SESSION传递给另一个页面以显示它。 I have used ajax and javascript in my webpage too which make it more complicated. 我也在网页中使用过ajax和javascript,这使其变得更加复杂。 Now when I print the output the output in the div is the previous value of the SESSION.My code is as follows: 现在当我打印输出时,div中的输出是SESSION的先前值。我的代码如下:

The main page: 主页:

<!DOCTYPE html>
<html>
    <head>

                    $('#file').live('change', function()    
                    { 
                    $("#preview").html('');
                    $("#preview").html('<img src="images/loader.gif" alt="Uploading...."/>');
                    $("#imageform").ajaxForm(
                    {
                    target: '#preview'
                    }).submit();

                    <script type="text/javascript">
                    function myfunction()
                    {
                    $("#display").html('');
                    $("#display").html('<img src="images/loader.gif" alt="Uploading...."/>');
                    $("#retrieveimageform").ajaxForm(
                    {
                    target: '#display'
                    }).submit();

                     $('#tags').html('<?php include 'Tagsdisplay.php';?>');  
 %I want to include this only after it goes through the retrieveimage1.php page
 where the console application is called and the session is created but this is
 not happening the tags div is shown before the console application is called 
 and the other results are displayed on the display div
                     $('#tags').show();
                    };


                    </script>

        <title></title>
    </head>
    <body>
        <div id="maindiv">
                <div id="banner">
                <?php
                include 'Header.php';

                ?>
                 </div>
                <div id="wrapper">

                        <div id="imageupload">
                    <form action="uploadimage.php" method="post"
                         enctype="multipart/form-data" id="imageform">
                         <label for="file">Upload your image:</label>
                       <input type="file" name="file" id="file"><br>

                    </form>
                        </div>
                       <div id='preview'>  
                        </div>
                    <div id='tags'>

                    </div>

                       <div class="clear"></div>

                    <form action="retrieveimage1.php" method="post"
                           id="retrieveimageform">

                       ................................   

                         <input type="submit" name="search" value="Search" id="btnSearch" onclick="myfunction()">

                    </form>
     <div id="display"></div>

                 </div>

The retrieveimage.php where the console app is called and session is created: 调用控制台应用程序并创建会话的retrieveimage.php:

          session_start();
          $start_time=  microtime(true);
        if (isset($_SESSION['img']))
        {   
                $image=$_SESSION['img'];
                $_SESSION['coarselbl1']=" ";
                $_SESSION['coarselbl2']=" ";
                $_SESSION['coarselbl3']=" ";
                $_SESSION['finelbl1']=" ";
                $_SESSION['finelbl2']=" ";
                $_SESSION['finelbl3']=" ";
                $_SESSION['finelbl4']=" ";
                $_SESSION['category']=" ";
                    if($_POST['cat']=='handbag')
                            {
                                 $_SESSION['category']="Bag";
                                 $cwt=$_POST["slider1"];
                                $fwt=$_POST["slider2"];
                                $twt=$_POST["slider3"];
                                $swt=$_POST["slider4"];

                                $addr="handbags31_fourth.exe $image $cwt $fwt $swt $twt";
                                  exec($addr,$data);

                                  $_SESSION['coarselbl1']=$data[2];
                                  $_SESSION['coarselbl2']=$data[3];
                                  $_SESSION['coarselbl3']=$data[4];
                   }

The TagsDisplay.php where the tags are displayed: 显示标签的TagsDisplay.php:

<?php
        session_start();
        echo $_SESSION['category']."<br/>";
   if($_SESSION['category']=="Bag")
    {
        echo "Coarse Color:   ".$_SESSION['coarselbl1'].",".$_SESSION['coarselbl2'].",".$_SESSION['coarselbl3']."<br/>";
        unset($_SESSION['coarselbl1']);
        unset($_SESSION['coarselbl2']);
        unset($_SESSION['coarselbl3']);


    }


?>

The problem here is when I click the search button the myfunction is called and the tags div is displayed before the display div and the value printed are the previous session value. 这里的问题是,当我单击搜索按钮时,将调用myfunction,并且在显示div和打印的值是前一个会话值之前显示标签div。 I want the tag div to come only after the display div is shown and the new session are assigned. 我希望标签div仅在显示div显示并分配了新会话之后才出现。 How can I achieve that? 我该如何实现?

Fix the jquery line 修复jQuery行

$('#tags').html('<?php include 'Tagsdisplay.php';?>'); 

to this: 对此:

$('#tags').html('<?php include "Tagsdisplay.php";?>'); 

(note the quotes) because you are not even including the file that unsets the previous session's values. (请注意引号),因为您甚至没有包含用于取消设置前一会话值的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM