Lassie Posted January 26, 2007 Share Posted January 26, 2007 I have the following piece of code which is designed to test for a $_GET compare with the database value and if ok redirect to a new page.If I dont insert the header line the program matches the var and all is well.If I insert the header line i generate 'there was an error message'.I have an errors array to catch the errors and print them after the header function is called.I dont get a headers sent warning.Anyone see where I go wrong?[code]<?phprequire ('book_sc_fns.php');session_start();include("misc.inc");$connection = mysql_connect($host,$user,$password) or die ("$connection:".mysql_error($connection));$db = mysql_select_db($database,$connection) or die ("$db:".mysql_error($connection));$errors = array();//retrieve the hash if (isset($_GET['pur_id'])){ $hash = $_GET['pur_id']; }else{ $errors[]= "there was an error";//message I get if header line left in} //query db for match $query = "SELECT hash FROM pick_up WHERE hash='$hash'"; $result = mysql_query($query)or die(mysql_error()); if (@mysql_num_rows($result) == 1) { // header('Location:http://xxxxxxxxxxxxxxx/e_cart9/pick_up.php'); $ok = "Match Made"; } else{ $errors[] = "No Match made"; } If(!empty($errors)) { echo '<h1>Error!</h1> <p>The following error occured:<br />'; foreach ($errors as $msg) { echo " - $msg<br />\n"; } } echo "$ok<br />\n"; echo "$hash";exit();?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/35806-header-problem/ Share on other sites More sharing options...
spfoonnewb Posted January 26, 2007 Share Posted January 26, 2007 Try this at the top of your script.[code]<?php ob_start(); ?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/35806-header-problem/#findComment-169741 Share on other sites More sharing options...
Lassie Posted January 26, 2007 Author Share Posted January 26, 2007 Hi,Thanks. I tried that and still get the same error.What does the function aim to do? Quote Link to comment https://forums.phpfreaks.com/topic/35806-header-problem/#findComment-169908 Share on other sites More sharing options...
wildteen88 Posted January 26, 2007 Share Posted January 26, 2007 Add ob_end_flush(); at the end of your script too (before the closing PHP tag (?>)ob_start starts output buffering. Meaning PHP will not out anything until the script has been parsed. You need to call ob_end_flush which turns off output buffering which will release the buffered contents. Quote Link to comment https://forums.phpfreaks.com/topic/35806-header-problem/#findComment-169912 Share on other sites More sharing options...
Lassie Posted January 26, 2007 Author Share Posted January 26, 2007 Thanks. Again I tried it and get the same error.I dont understand this as I have verified that the $_GET does have the variable, yet this is the area where my code gives the error message, but the header seems to be the villan in the piece.I will add below the top and bottom of the scriprt as it now is if you have any more advice.Thank you.[code]<?php ob_start();?><?phprequire ('book_sc_fns.php');session_start();//the rest of the script echo "$ok<br />\n"; echo "$hash";ob_end_flush(); ?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/35806-header-problem/#findComment-169926 Share on other sites More sharing options...
wildteen88 Posted January 26, 2007 Share Posted January 26, 2007 Add session_start() before the require. Quote Link to comment https://forums.phpfreaks.com/topic/35806-header-problem/#findComment-169928 Share on other sites More sharing options...
Lassie Posted January 27, 2007 Author Share Posted January 27, 2007 Tried it again with that amendment and still no joy.I also need to create a session var just before the redirect so the code now has an addition as follows.[code]if (@mysql_num_rows($result) == 1) { $hash = $hash."/"; $_SESSION['hash']= $hash; header('Location:http://217.46.159.226/e_cart9/Downloads/index.php'); $ok = "Match Made"; }[/code]Does this break any rules?Is there another way of approaching this. I need to pass the variables to effect a download script.Since the visitor arrives at the the current page from an email link i dont want put a form or link in.Any thoughts appreciated.Lassie Quote Link to comment https://forums.phpfreaks.com/topic/35806-header-problem/#findComment-170458 Share on other sites More sharing options...
Lassie Posted January 27, 2007 Author Share Posted January 27, 2007 Problem solved. I re did the script on a new page and it know works.The only error i found was the redirection url was wrong. so may be that was it along with the other points made in the discussion.Thanks everybody for your help.Lassie Quote Link to comment https://forums.phpfreaks.com/topic/35806-header-problem/#findComment-170474 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.