0

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);
segarci
  • 739
  • 1
  • 11
  • 19
con322
  • 1,119
  • 7
  • 16
  • 29
  • whats the question ? Is a redirect (header) inside a include possible? : yes – birdspider Nov 19 '14 at 17:04
  • @birdspider Sorry as usually I haven't phrased my question well, basically can I do a redirect(header) at the bottom of a php file as I need to generate the variable before passing it to the header location, – con322 Nov 20 '14 at 09:07
  • Maybe this so question can hel you http://stackoverflow.com/q/5595445/5476782 – Evhz Apr 23 '16 at 15:13

1 Answers1

1

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

birdspider
  • 3,034
  • 1
  • 16
  • 25