duanou9739 2009-10-15 00:51
浏览 43

PHP标头重定向问题(不,不是那个常见问题)

Firstly, this is not the headers already sent' problem.

I have an include file, that does the redirect. This works on every server I have tried it on except the production server, which runs windows.

When I run it on the production server, it only redirects the include file, not the entire page.

I have the main file, index.php:

<?php include('red.php'); ?>
<html ....
>

And I do the redirect to another page in red.php. Then the redirected page will show up at the top of the index.php page, with the rest of the index.php html file after this page.

Have the mess up some setting in php.ini?

After some more investigation, the problem is when I use a full URL rather than a relative URL. The first will only redirect the included file. (the problem I discovered above)

while the second works correctly

red2.php:


header("Location: http://example.com/newfile.php"); header("Location: newfile.php");'

  • 写回答

2条回答 默认 最新

  • douwei2713 2009-10-15 00:58
    关注

    When I run it on the production server, it only redirects the include file, not the entire page.

    That's a funny thing to say because it's not really possible. Only a single blob of data is presented to the browser you can't "redirect" part of it but you can include from multiple files in order to produce a composite blob.

    Perhaps, this is what you're doing. Perhaps you're doing an include instead of a redirect. Remember a redirect is done like this:

    header('Location: file.php');
    exit;
    

    The exit at the end is recommended so execution doesn't continue unnecessarily.

    评论

报告相同问题?

悬赏问题

  • ¥15 依据报错在原代吗格式的基础上解决问题
  • ¥15 在虚拟机中安装flash code
  • ¥15 单片机stm32f10x编写光敏电阻调节3.3伏大功率灯亮度(光强越大灯越暗,白天正常光强灯不亮,使用ADC,PWM等模块)望各位找一下错误或者提供一个可实现功能的代码
  • ¥20 verilog状态机方法流水灯
  • ¥15 pandas代码实现不了意图
  • ¥15 GD32H7 从存储器到外设SPI传输数据无法重复启用DMA
  • ¥25 LT码在高斯信道下的误码率仿真
  • ¥45 渲染完成之后将物体的材质贴图改变,自动化进行这个操作
  • ¥15 yolov5目标检测并显示目标出现的时间或视频帧
  • ¥15 电视版的优酷可以设置电影连续播放吗?