普通网友 2015-03-16 20:43
浏览 34
已采纳

这种方法使用GET方法错了吗?

There is something I've been working and I ran into a problem that I could only solve doing this

header("Location:messages.php?ID_Conversation=$row[ID]");

Is this "wrong"?

  • 写回答

1条回答 默认 最新

  • dskld5423 2015-03-16 20:54
    关注

    This is not wrong exactly. You are redirecting to a resource and passing information to that resource as part of the URL, and this is perfectly acceptable.

    However, the part that is wrong is the way the URL is structured. If you are going to be doing this with any regularity, you will want to get into the habit of setting the location as precisely as possible.

    At the very least this is to say that you should set the full path relative to the domain root:

    header("Location:/any_directories/messages.php?ID_Conversation=$row[ID]");
    

    And at the best, this means including the domain and protocol as well:

    header("Location:https://yourdomain.com/any_directories/messages.php?ID_Conversation=$row[ID]");
    

    To simplify this, create a helper function or object to handle this kind of redirect.

    function redirect($url) {
        header("Location:https://yourdomain.com/$url");
    }
    
    redirect("any_directories/messages.php?ID_Conversation=$row[ID]");
    

    Obviously there are other considerations in the above function, passing data for the GET query as an array maybe, discovering the domain and/or protocol, etc, and it should not be used as it is written, but the idea is sound.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 关于#qt#的问题:Qt代码的移植问题
  • ¥50 求图像处理的matlab方案
  • ¥50 winform中使用edge的Kiosk模式
  • ¥15 关于#python#的问题:功能监听网页
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化