session - 关于php跳转页面给予提醒的问题
伊谢尔伦
伊谢尔伦 2017-05-16 13:10:58
0
4
503

请问,php执行用户操作的某一个操作之后(跳转执行的,非ajax执行)再跳转到上次页面或者其他页面 给用户返回执行结果的提醒,如何实现该提醒只在本次执行跳转请求有效,再次刷新本页面后不再存在该数据提醒。

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(4)
仅有的幸福

Execute the reminder first and then jump? Or jump to a transition page, and then jump to the target page after the reminder?

曾经蜡笔没有小新

Check whether SESSION exists before each jump. If it does not exist, jump. After the jump is successful, write SESSION.

$noticed = $_SESSION['noticed'];
if(isset($noticed)){
    //your code here
}
滿天的星座

php can get the connection to the source page:

$_SERVER[“HTTP_REFERER”]

You can get the link to the source page and compare it to see if it jumps from the page you executed. to make a judgment. Or you can append a parameter to the jump connection after successful execution. When there are parameters, it prompts that the execution is successful. There is no reminder for normal refresh.

But it is more recommended that you write a function. Enter the prompt and the page to jump to. For details, please refer to the tips of some frameworks.

刘奇

Based on the suggestions from the above people:

//跳转调用
function redirect($url,$message=false)
{
  if($message){
    foreach ($message as $key => $value) {
      if(is_array($value)){
        $_SESSION['RedirectMessage'][$key] = implode(',', urlencode($value));
      }else{
        $_SESSION['RedirectMessage'][$key] = urlencode($value);
      }
    }
  }
  header('location:'.$url);
}

//视图调用(在视图加判断)
function getMessage($key1)
{
  $data = explode(',',$_SESSION['RedirectMessage'][$key1]);
  $_SESSION['RedirectMessage'] = null;
  if(empty($data)){
    return false;
  }
  foreach ($data as $key => $value) {
    $data[$key] = urldecode($value);
  }
  if(count($data)==1){
    return $data[0];
  }else{
    return $data;
  }
}
/**
 * 参数是否存在
 */
function existsParam($key)
{
  if(isset($_SESSION['RedirectMessage'][$key])){
    return true;
  }else{
    return false;
  }
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!