简体   繁体   English

上次访问页面(COOKIE)和php中当前搜索页面的逻辑错误

[英]logical error in last visited page(COOKIE) and current search page in php


I have a page ( index.php ) where i display latest events fetched from db and a search box on the top of page, if someone search any event then all events regarding search displayed with name and link on page . 我有一个页面( index.php ),其中显示了从db获取的最新事件,并且在页面顶部显示了一个搜索框,如果有人搜索任何事件,那么所有与搜索有关的事件都会在页面上显示名称和链接。 now what i need 现在我需要

  1. if we search some event and go to that event page and come back (index.php) then last search result should be displayed...right now if i go back then display latest event. 如果我们搜索某个事件并转到该事件页面并返回(index.php),则应显示上一个搜索结果...如果现在返回,则显示最新事件。
  2. if we go to specific event and close browser at that time ( or go back and close ) and if open that site again i need to display last visited event page link on index.php 如果我们转到特定事件并在那时关闭浏览器(或返回并关闭),并且如果再次打开该站点,则需要在index.php上显示上次访问的事件页面链接
  3. if we first time come to page ( or after cookie expire) then all latest events ( right now only 4 latest event)should display. 如果我们是第一次访问该页面(或Cookie过期后),则应显示所有最新事件(目前只有4个最新事件)。
  4. if we search and that is not found then display "NO event found" and request to search again. 如果我们搜索并且找不到,则显示“未找到事件”,并请求再次搜索。

    currently point 2 and point 4 is covered successfully, but point 3 is not done, please suggest my logical conditions in proper way and also suggest what do i do for point 1 当前点2和点4已成功覆盖,但点3未完成,请以正确的方式建议我的逻辑条件,并建议我对点1的处理

below if main code of my page 下面是我页面的主要代码

index.php index.php

<form action="<?=$_SERVER['PHP_SELF'];?>" method="get" accept-charset="utf-8">              
    <input type="text"  name="keyword" id="keyword"  placeholder="Search for Event" value="">           
    <input type="submit" name="submit" id="submit" value="Search" >     
</form>

if(empty($_GET['keyword']) && !isset($_SERVER['HTTP_REFERER'])) {
   if(!empty($_COOKIE['LAST_EVENT_ID'])) { ?>
       <div class="module list">
        <ul id="people">
            <li>
            <a href="eventinfo.php?evt_id=<?=$_COOKIE['LAST_EVENT_ID'];?>&evt_name=<?=$_COOKIE['LAST_VISITED_EVENT'];?>">           
            <h2><?=$_COOKIE['LAST_VISITED_EVENT']?></h2>                    
                </a>
            </li>
         </ul>
       </div>
<?php } } 
// Note count($eventItems)==4 ( by default latest events)       
    else if(count($eventItems) == 0) { ?>       
       <h2>No Events found, please Search again</h2>
<?php } 
      else { 
 ?> 
     <div class="module list">
     <ul id="people">
<?php    foreach($eventItems as $value) { ?>
         <li>
            <a href="eventinfo.php?evt_id=<?=$value->event_id?>&evt_name=<?=$value->name?>">            
            <h2><?=$value->name?></h2>                  
            </a>
         </li>          
 <?php      } ?> 
   </ul>
  </div>

eventinfo.php eventinfo.php

<?php ob_start();
$evt_id=$_GET['evt_id'];
$evt_name=$_GET['evt_name'];
define('SITE_PATH','http://localhost/hello_world/');    
define('EVENT_ID',$evt_id);
/* first remove old cookie value */
//setcookie("LAST_EVENT_ID",EVENT_ID, time()-3600*24*7);
//setcookie("LAST_VISITED_EVENT", $evt_name, time()-3600*24*7);

setcookie("LAST_EVENT_ID", EVENT_ID, time()+3600*24*7);
setcookie("LAST_VISITED_EVENT", $evt_name, time()+3600*24*7);

if (is_dir($evt_name)){
    header("location:".EVENT_PATH);
}
else{
    header("location:event_detail.php");
}


?>

please tell me how do i modify my if else condition to fulfill all above points 请告诉我如何修改我的“ if if else”条件以实现上述所有要点

Thanks 谢谢

UPDATE 更新

i also create truth table for all situation, plz help me to develop logic.. here is the link for truth table 我也为所有情况创建真值表,请帮助我开发逻辑..这是真值表的链接

Change 更改

<li>
    <a href="eventinfo.php?evt_id=<?=$_COOKIE['LAST_EVENT_ID'];?>&evt_name=<?=$lastEventDetail['name'];?>">         
        <h2><?=$lastEventDetail['name']?></h2>                  
    </a>
</li>

to

<li>
    <a href="eventinfo.php?evt_id=<?=$_COOKIE['LAST_EVENT_ID'];?>&evt_name=<?=$_COOKIE['LAST_VISITED_EVENT'];?>">         
        <h2><?=$_COOKIE['LAST_VISITED_EVENT']; ?></h2>                  
    </a>
</li>

Their is no value for $lastEventDetail['name'] .. the last event name is in the cookie 对于$ lastEventDetail ['name']来说,它们是没有值的。.最后一个事件名称在cookie中

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

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