dqrfdl5708 2014-10-21 20:23
浏览 24

如何检查变量是否设置而不是NULL / Empty并将其保存以供下一页继续使用?

I've got an application which has an embedded IE6 browser. On opening it inside the application, it sends a $_POST variable: $_POST['VARIABLE'].

What's the best way to check in the start of my script that if this variable isn't sent (security check to make sure it's opening only via the application) and save it to use it on the next page?

I use sessions on my website since I store account ids, email, password, so I believe I can use it to save this variable too. Please let me know.

  • 写回答

2条回答 默认 最新

  • douhezi2285 2014-10-21 20:29
    关注

    You could do something like this:

    if(!array_key_exists('VARIABLE',$_POST))
    {
       //this variable is not set in post - proceed accordingly
    }
    else
    {
      //value is sent from POST, lets put it in session if its not already there,
      //or if a previous POST value is still in session - lets update that
      if(!array_key_exists('VARIABLE',$_SESSION) || 
      $_SESSION['VARIABLE'] != $_POST['VARIABLE'])
      {
         $_SESSION['VARIABLE'] = $_POST['VARIABLE'];
      }
    }
    
    // ...in the rest of the code check $_SESSION['VARIABLE'] and act accordingly.
    
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?