Jump to content

header problem


Lassie

Recommended Posts

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]
<?php
require ('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]
Link to comment
https://forums.phpfreaks.com/topic/35806-header-problem/
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/35806-header-problem/#findComment-169912
Share on other sites

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();?>
<?php
require ('book_sc_fns.php');
session_start();
//the rest of the script
echo "$ok<br />\n";
echo "$hash";
ob_end_flush();
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/35806-header-problem/#findComment-169926
Share on other sites

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
Link to comment
https://forums.phpfreaks.com/topic/35806-header-problem/#findComment-170458
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.