Page 1 of 1

Redirect

Posted: Tue Jul 06, 2004 7:36 am
by dave_c00
I would like to simply run an if statement and if the condition is met goto another web page. Do i use the header function??

I am getting all sorts of errors when i use that.

Thanks

Dave

Posted: Tue Jul 06, 2004 7:41 am
by launchcode
Yes use the header function (as shown below) but notice this will only work if you have not output any headers already (which could be anything from a space in your file to an echo statement, etc). Basically this will only work if no other output has already been sent to the browser.

Code: Select all

<?
Header('Location: http://www.site.com/page.html');
exit;
?>

Posted: Tue Jul 06, 2004 7:48 am
by dave_c00
this is the error i am getting..

Warning: Cannot modify header information - headers already sent by (output started at /home/sites/site12/web/NewCustCosyData.php:15) in /home/sites/site12/web/NewCustCosyData.php on line 3

How can i get around it??

Thanks

Dave

Posted: Tue Jul 06, 2004 7:51 am
by malcolmboston
launchcode wrote: but notice this will only work if you have not output any headers already (which could be anything from a space in your file to an echo statement, etc). Basically this will only work if no other output has already been sent to the browser.

Posted: Tue Jul 06, 2004 7:52 am
by launchcode
Like I said (thanks Malcolm! :) ) - you are already outputting something in your script - some HTML or a space, whatever - it's causing the Header to fail.

Posted: Tue Jul 06, 2004 9:20 am
by dave_c00
Sorry for being such a novice but i need a page that simply opens up a new page if the value in the text field is correct and if is not just remains on the same page with an error message.

I have tried a number of different avenues and am getting quite annoyed.

Thanks

Dave

Posted: Tue Jul 06, 2004 9:23 am
by launchcode
Post your script - if you don't understand what "don't output any HTML before calling the Header function" means, then perhaps we can actually show you instead?

Posted: Tue Jul 06, 2004 9:36 am
by dave_c00
Initially I read a text file into an array:-

Code: Select all

&lt;?php 
$file = implode("",file("Eng_Internet_query.txt"));  
preg_match_all('/^(.*?),"(.*?)","(.*?)","(.*?)","(.*?)","(.*?)","(.*?)","(.*?)","(.*?)","(.*?)","(.*?)","(.*?)","(.*?)"/ms',$file,$matches);
$worksord = $_POST&#1111;'worksord'];
?&gt;
Then i have a form to read in the works order number.

Code: Select all

&lt;div align="center"&gt;
  &lt;form action="&lt;?php print $PHP_SELF?&gt;"&gt;
  &lt;input type="text" name="worksord"&gt;
  &lt;input type="submit" value="Submit!"&gt;
  &lt;/form&gt;
  &lt;/div&gt;
Now i simply check the array for the worksord and if it is recognized i want to redirect to another page.

Code: Select all

<?php
if (in_array($worksord,$matches[3])){
Header("Location: http://www.website.com");
}else
{
print "Works Order number not found.";
}
?>
At what stage am i outputting headers??

Thanks

Dave



feyd | use

Code: Select all

and

Code: Select all

tags next time. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Tue Jul 06, 2004 9:39 am
by d3ad1ysp0rk
<div align="center">
<form action="<?php print $PHP_SELF?>">
<input type="text" name="worksord">
<input type="submit" value="Submit!">
</form>
</div>

Posted: Tue Jul 06, 2004 10:16 am
by launchcode
At what stage am i outputting headers??
Outputting HTML automatically outputs a header. Your entire DIV Form block is HTML, ergo you've output headers.

Swap around the sequence - do the Header check BEFORE you output the Form.

Posted: Tue Jul 06, 2004 12:43 pm
by qads

Code: Select all

<?php
ob_start();
?>
put that at the top of page, for more info, read [php_man]ob_start[/php_man]