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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.