当前位置: 动力学知识库 > 问答 > 编程问答 >

php - How can achieve a clean URL redirect

问题描述:

So I have a form which when submitted executes a php file containing the following redirect.

echo '<meta http-equiv="refresh" content="0;url='.$nexturl.'" />';

As most people will know this isn't a clean/proffesional way of redirecting.

Is it possible to include a file just containing a redirect using header location, however I will require the variable that is created in my process.php file.

For example create using a php include:

<?php include (TEMPLATEPATH . '/redirect.php'); ?>

Then within redirect.php

header('Location: '.$newURL);

网友答案:

yes you can redirect (that is: set/reset/unset any header you want) as long as no output happend before

(none, not even whitespace or BOM (utf-8 byte order mark) - iirc)

in case you have output you can capture it via ob_start and output if afterwards

oddly enough: this is even made quite clear in the doc

分享给朋友:
您可能感兴趣的文章:
随机阅读: