session - Issues regarding reminders for php jump pages
伊谢尔伦
伊谢尔伦 2017-05-16 13:10:58
0
4
547

Excuse me, after PHP executes a certain operation performed by the user (jump execution, non-ajax execution), it then jumps to the last page or other pages to remind the user to return the execution result. How to achieve this reminder only this time? The execution of the jump request is valid, and the data reminder will no longer exist after refreshing this page again.

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学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