duanfu6160 2017-03-22 09:08
浏览 81
已采纳

为什么PHP URL编码让我拒绝403访问

I'm trying to pass some $_GET information from one web page to another via an a href in a php (5.6.25) file. When I omit URLencoding, Apache/2.4.23 finds the URL just fine. With URLencoding, I'm denied access. The both versions of the href sit in the same file using the same server.

Without URLencoding but working:

<?php
    $url = "Manage_Cumulative_DEV.php";
    $url .= /*URLencode*/ ('?thread_ID='.$row['thread_ID']);
?>
<a href="<?php echo htmlspecialchars($url); 
?>">
<?php echo htmlspecialchars($display_text);
echo '<br>';
?>
</a>
<?php 

The successful link looks like this:

http://localhost/WS_map_code/Manage_Cumulative_DEV.php?thread_ID=437769

With URLencoding - and broken:

<?php
    $url = "Manage_Cumulative_DEV.php";
    $url .= URLencode('?thread_ID='.$row['thread_ID']);
?>
<a href="<?php echo htmlspecialchars($url); 
?>">
<?php echo htmlspecialchars($display_text);
echo '<br>';
?>
</a>
<?php 

When I run the URLencoded version, I get a 403 error code and this message: Forbidden You don't have permission to access /WS_map_code/Manage_Cumulative_DEV.php?thread_ID=437769 on this server. Apache/2.4.23 (Win64) PHP/5.6.25 Server at localhost Port 80 (Note how the error message quotes the same href that had worked successfully for me without URL encoding. It seems to know what I'm trying to say.)

The failed, URLencoded href (as copied from the address bar) looks like this and seems right: http://localhost/WS_map_code/Manage_Cumulative_DEV.php%3Fthread_ID%3D437769

I know I'm being thick, because I've poked, prodded and researched it for hours. I ask mercy of the thinner.

  • 写回答

1条回答 默认 最新

  • dongwei5740 2017-03-22 09:13
    关注
    $url = "Manage_Cumulative_DEV.php?thread_ID=";
    $url .= URLencode($row['thread_ID']);
    

    should do the trick. In your code you're URLencoding the ? which leads to an invalid request url

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

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试