snorky Posted May 4, 2009 Share Posted May 4, 2009 I can't get the header() function to work correctly. on datamine2.php there is a form after a bunch of stuff happens. That part works as expected. <form name="end_of_report" action="datamine4.php"> <input type="radio" name="nextone" value="Quit" />Quit<br /> <input type="radio" name="nextone" value="Another" />Run Another Report<br /><br /> <input type="submit" value="go!" /> </form> when the user selects "Quit' or "Another" from the form, datamine4.php opens and runs datamine4.php has no HTML and therefore no display The following is all of the code in datamine4.php <?php global $nextone; // create a var $chosen1 = "another"; // get input from form on datamine2.php $chosen2 = $_GET["nextone"]; So far, so good. // test input from datamine2.php and run another report (datamine1.php) or quit if ($chosen1==$chosen2) { header("location:http://www.mysite.net/bbp/reports/datamine1.php"); exit; } else { header("location:http://www.mysite.net/index.shtml"); exit; } ?> I know that the if/else and the variables are correct, because [*]if $chosen is "Another" a blank screen appears with the URL http://ww2.ohsd.net/bbp/reports/datamine4.php?nextone=another [*]if $chosen is "Quit" a blank screen appears with the URL http://ww2.ohsd.net/bbp/reports/datamine4.php?nextone=quit datamine4.php does the if/else part, but doesn't execute either header() call I know that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. That is exactly what the manual says. However, there is no HTML there are no other files opened and therefore no blank lines PHP doesn't send any other output before calling either of the header() commands The PHP manual gives this example: <?php header("Location: http://www.example.com/"); /* Redirect browser */ /* Make sure that code below does not get executed when we redirect. */ exit; ?> Quote Link to comment https://forums.phpfreaks.com/topic/156830-solved-header-function/ Share on other sites More sharing options...
Maq Posted May 4, 2009 Share Posted May 4, 2009 Put this at the top of your page, it will tell you what the error is: ini_set ("display_errors", "1"); error_reporting(E_ALL); You may have a whitespace issue. NOTE: Please use the built in tags around you code for proper formatting/syntax highlighting. Quote Link to comment https://forums.phpfreaks.com/topic/156830-solved-header-function/#findComment-826051 Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 This is a real effort! I acknowledge you for taking your time to style your post that way. It's more than what most people do when asking for help. But please do use the code tags. Quote Link to comment https://forums.phpfreaks.com/topic/156830-solved-header-function/#findComment-826055 Share on other sites More sharing options...
matt.sisto Posted May 4, 2009 Share Posted May 4, 2009 I know this is very simple, but whenever I use header location, location has capital L. This might not be the issue but from my experience its the little mistakes that go unnoticed. header("Location: addeventform.php"); exit(); Quote Link to comment https://forums.phpfreaks.com/topic/156830-solved-header-function/#findComment-826063 Share on other sites More sharing options...
snorky Posted May 4, 2009 Author Share Posted May 4, 2009 I know this is very simple, but whenever I use header location, location has capital L. This might not be the issue but from my experience its the little mistakes that go unnoticed. header("Location: addeventform.php"); exit(); You're right about the little mistakes. In this case, however, "L" didn't help. Quote Link to comment https://forums.phpfreaks.com/topic/156830-solved-header-function/#findComment-826075 Share on other sites More sharing options...
Maq Posted May 4, 2009 Share Posted May 4, 2009 What about the error_reporting? Did it output anything? Are you sure you don't have any HTML whitespace seeping through? Quote Link to comment https://forums.phpfreaks.com/topic/156830-solved-header-function/#findComment-826078 Share on other sites More sharing options...
ionik Posted May 4, 2009 Share Posted May 4, 2009 What do these pages output that u are redirecting to....and if error_reporting(E_ALL) does not work try error_reporting(E_ALL ^ E_STRICT); see if you get anything. Also try redirecting to another blank test page and see if it produces anything. Quote Link to comment https://forums.phpfreaks.com/topic/156830-solved-header-function/#findComment-826085 Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 Also, you got $chosen1 wrong. Capital A? Quote Link to comment https://forums.phpfreaks.com/topic/156830-solved-header-function/#findComment-826086 Share on other sites More sharing options...
cringe Posted May 4, 2009 Share Posted May 4, 2009 I know this is very simple, but whenever I use header location, location has capital L. This might not be the issue but from my experience its the little mistakes that go unnoticed. header("Location: addeventform.php"); exit(); Headers are case insenstive. You could use LoCaTiOn: if you really wanted. But yes, I'd use Location: cause it just looks better. Quote Link to comment https://forums.phpfreaks.com/topic/156830-solved-header-function/#findComment-826095 Share on other sites More sharing options...
snorky Posted May 4, 2009 Author Share Posted May 4, 2009 Put this at the top of your page, it will tell you what the error is: ini_set ("display_errors", "1"); error_reporting(E_ALL); You may have a whitespace issue. NOTE: Please use the built in tags around you code for proper formatting/syntax highlighting. Those were already set globally to On & 1 respectively. Adding or removing from this script made no difference: I still don't see error messages. Quote Link to comment https://forums.phpfreaks.com/topic/156830-solved-header-function/#findComment-826103 Share on other sites More sharing options...
snorky Posted May 4, 2009 Author Share Posted May 4, 2009 What about the error_reporting? Did it output anything? Are you sure you don't have any HTML whitespace seeping through? There is no white space. I even tried removing the comments. Quote Link to comment https://forums.phpfreaks.com/topic/156830-solved-header-function/#findComment-826106 Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 Can you put this after $chosen2? var_dump($chosen2); What did you get? Quote Link to comment https://forums.phpfreaks.com/topic/156830-solved-header-function/#findComment-826109 Share on other sites More sharing options...
snorky Posted May 4, 2009 Author Share Posted May 4, 2009 What do these pages output that u are redirecting to....and if error_reporting(E_ALL) does not work try error_reporting(E_ALL ^ E_STRICT); see if you get anything. Also try redirecting to another blank test page and see if it produces anything. I attempted to redirect to a different (blank) page. Same result. Cleared IE cache and tried in FireFox (which had never seen that site). Same error: Warning: Cannot modify header information - headers already sent by (output started at /home/.sites/28/site1/web/bbp/reports/datamine4.php:1) in /home/.sites/28/site1/web/bbp/reports/datamine4.php on line 8 Quote Link to comment https://forums.phpfreaks.com/topic/156830-solved-header-function/#findComment-826138 Share on other sites More sharing options...
Maq Posted May 4, 2009 Share Posted May 4, 2009 That's due to output/whitespace before you call the header function. Please post the code from the last header call to the top of the page, in tags. Here's a sticky for an in depth explanation: http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Quote Link to comment https://forums.phpfreaks.com/topic/156830-solved-header-function/#findComment-826144 Share on other sites More sharing options...
snorky Posted May 4, 2009 Author Share Posted May 4, 2009 Can you put this after $chosen2? var_dump($chosen2); What did you get? string(7) "another" + Warning: Cannot modify header information - headers already sent by (output started at /home/.sites/28/site1/web/bbp/reports/datamine4.php:1) in /home/.sites/28/site1/web/bbp/reports/datamine4.php on line 9 Quote Link to comment https://forums.phpfreaks.com/topic/156830-solved-header-function/#findComment-826146 Share on other sites More sharing options...
ionik Posted May 4, 2009 Share Posted May 4, 2009 disregard......... Quote Link to comment https://forums.phpfreaks.com/topic/156830-solved-header-function/#findComment-826149 Share on other sites More sharing options...
snorky Posted May 4, 2009 Author Share Posted May 4, 2009 That's due to output/whitespace before you call the header function. Please post the code from the last header call to the top of the page, in tags. I don't see what qualifies as output/whitespace: <?php error_reporting(E_ALL ^ E_STRICT); global $nextone; $chosen1="another"; $chosen2=$_GET["nextone"]; var_dump($chosen2); if ($chosen1==$chosen2) { header("Location:http://ww2.ohsd.net/bbp/reports/datamine1.php"); exit; } else { exit; } ?> Here's a sticky for an in depth explanation: http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Quote Link to comment https://forums.phpfreaks.com/topic/156830-solved-header-function/#findComment-826153 Share on other sites More sharing options...
Maq Posted May 4, 2009 Share Posted May 4, 2009 Whitespace: error_reporting(E_ALL ^ E_STRICT); global $nextone; $chosen1="another"; $chosen2=$_GET["nextone"]; // var_dump($chosen2); DON'T NEED THIS if ($chosen1==$chosen2) { header("Location:http://ww2.ohsd.net/bbp/reports/datamine1.php"); exit; } Quote Link to comment https://forums.phpfreaks.com/topic/156830-solved-header-function/#findComment-826156 Share on other sites More sharing options...
snorky Posted May 4, 2009 Author Share Posted May 4, 2009 Also, you got $chosen1 wrong. Capital A? The value passed from the form is all lower case: "another" <form name="end_of_report" action="datamine4.php"> <input type="radio" name="nextone" value="quit" />Quit<br /> <input type="radio" name="nextone" value="another" />Run Another Report<br /><br /> <input type="submit" value="go!" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/156830-solved-header-function/#findComment-826159 Share on other sites More sharing options...
snorky Posted May 4, 2009 Author Share Posted May 4, 2009 And the winner is..... Whitespace: <?php // move this in error_reporting(E_ALL ^ E_STRICT); global $nextone; $chosen1="another"; $chosen2=$_GET["nextone"]; // var_dump($chosen2); DON'T NEED THIS if ($chosen1==$chosen2) { header("Location:http://ww2.ohsd.net/bbp/reports/datamine1.php"); exit; } I changed the depth of the indentation. Not eliminated, just reduced the overall indentation until there was zero whitespace in front of <?php. Thanks to all. I learned several techniques in this exercise, and I made it through without resorting to my meds. Quote Link to comment https://forums.phpfreaks.com/topic/156830-solved-header-function/#findComment-826209 Share on other sites More sharing options...
Maq Posted May 4, 2009 Share Posted May 4, 2009 What's my prize? Quote Link to comment https://forums.phpfreaks.com/topic/156830-solved-header-function/#findComment-826210 Share on other sites More sharing options...
snorky Posted May 4, 2009 Author Share Posted May 4, 2009 What's my prize? You get some of the meds I didn't need... or a cold beer @Toby's (on the waterfront) Quote Link to comment https://forums.phpfreaks.com/topic/156830-solved-header-function/#findComment-826213 Share on other sites More sharing options...
Maq Posted May 4, 2009 Share Posted May 4, 2009 What's my prize? You get some of the meds I didn't need... or a cold beer @Toby's (on the waterfront) I'm there! Quote Link to comment https://forums.phpfreaks.com/topic/156830-solved-header-function/#findComment-826220 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.