Jump to content

Headers error unique not in the sticked thread


mike12255

Recommended Posts

Solution: Turns out the headers will not send unless all of the other code is behind an else userinfo.php?user=MikeH, possible addition to the sticked post?

 

 

So strictly speaking I dont have a header error because my script does not produce errors. However my script should be redirecting me to "notes.php?error=ad" but instead it just sends me back to the page I was previously at. My script is made to process a download via "tokens" and then redirect the user. That all works fine but what I am trying to do now is check if the user has already about the download and if they have redirect them to the error page letting them know. So in short the URL goes like this:

 

notes.php?viewn=2 -> purchase.php?user=MikeH&nid=2 (unseen page all processing) -> notes.php?error=ad

 

however what it is doing is:

 

notes.php?viewn=2 -> purchase.php?user=MikeH&nid=2 (unseen page all processing) -> notes.php?viewn=2

 

Here is the notes code:

 

<?php
}else if (isset($_GET['viewn'])){
	$cid = $_GET['viewn'];
	$query = "SELECT * FROM approvednotes WHERE cid =".$cid;
	$res = mysql_query($query) or die (mysql_error());
	$i=0;
	$r=1;
	?>
<h2>Programs:</h2>
<table summary="Summary Here" cellpadding="0" cellspacing="0">
<tr>
  <td><b>File Name</b></td>
  <td><b>Author</b></td>
  <td><b>Cost</b></td>
  <td><b>Buy</b></td>
</tr>
<?php
	echo "<tbody>";
	echo "<tr class= \"dark\">";
	while ($row = mysql_fetch_array($res)){


	if($i == 1){
		echo "</tr>";
		$r++;
		if($r% 1 == 0){
			echo "<tr class = \"light\">";

		$i=0;
		$r = 0;


	}else{
	echo "<tr class = \"dark\">";	
	$i=0;		
	}



}
echo "<td> ". $row['name']."</td><td>".$row['username']."</td><td>".$row['value']." <img src=\"images/money.png \" height=\"30px\" /></td><td><a href=\"purchase.php?user=".$session->username."&nid=".$row['id']."\"><img src=\"images/buy.png\" height=\"30px\"/></a></td>";
$i++;


	}

	echo "</table>";


}?>

 

 

Here is the purchase code:

 

 

<?php
include("include/session.php");

if($session->checkLogin()){


$user= $_GET['user'];

if ($user == $session->username){
$note = $_GET['nid'];

$query3 = "SELECT * FROM users_downloaded WHERE nid=$note AND username='$user'";
$res3 = mysql_query($query3) or die (mysql_error());
$pass = mysql_num_rows($res3);

if ($pass != 0){
header("Location: notess.php?error=ad");	

}



$nquery = "SELECT * FROM approvednotes WHERE id= ".$note;
$nres = mysql_query($nquery) or die (mysql_error());
//Get info about the file 
while ($nrow = mysql_fetch_assoc($nres)){
$price = $nrow['value'] ;
$location = $nrow['location'];	
}
//see if user even has enough credits for this

   function creditcheck($username){
   $usern= $_GET['user'];
   
   $query = "SELECT * FROM users WHERE username = '".$usern."'";

$res = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($res)){
$credits = $row['credits'];	
}
return $credits;
   }

$credits = creditcheck($user);
if($credits >= $price){
//user has enough credits to purchase note.
$newamount = $credits - $price;
$person = $session->username;
$query = "UPDATE users SET credits =".$newamount." WHERE username='$person'";
$res = mysql_query($query) or die (mysql_error());

$query2 = "INSERT INTO users_downloaded (nid, username) VALUES ('$note','$person')";
$res2 = mysql_query($query2) or die (mysql_error());

header("Location: download.php?f=".$location);
exit;



}else{
//error not enough money!!
header("Location: notes.php?error=ne");	

}
}

}else{
header ("Location: notes.php?error=nl");	
}






?>

 

 

 

  Quote
addition to the sticked post

 

No.

 

I don't know how many times this has been stated, but I'll do it again. YOU CANNOT OUTPUT ANY CHARACTERS to the browser before you use a header() statement, a setcookie() statement, or a session_start() statement.

 

If the code that you are referring to is the 8 lines of HTML in your post above, that code is made up of about 200+ characters.

  Quote

  Quote
addition to the sticked post

 

No.

 

I don't know how many times this has been stated, but I'll do it again. YOU CANNOT OUTPUT ANY CHARACTERS to the browser before you use a header() statement, a setcookie() statement, or a session_start() statement.

 

If the code that you are referring to is the 8 lines of HTML in your post above, that code is made up of about 200+ characters.

 

No characters where output before the header was sent so this was NOT the problem, was simply logic.

Since I only see one instance of the URL that you were having problems with on the redirect, would it be safe to assume that the misspelling in it isn't a good thing either? You also need to follow any header() immediately with an exit() to prevent further execution of the script.

 

header("Location: notess.php?error=ad");

 

 

Since you didn't bother to post the code that produces the error and the error message, it would be a little hard for anyone to directly help you.

 

Executing php code doesn't cause a header problem unless that code causes some character(s) to be output to the browser.

  Quote

Since you didn't bother to post the code that produces the error and the error message, it would be a little hard for anyone to directly help you.

 

Executing php code doesn't cause a header problem unless that code causes some character(s) to be output to the browser.

 

I did not have any errors as stated in my first post:

So strictly speaking I dont have a header error because my script does not produce errors. 

 

@pikachu yeah I know about the exit thanks for making me aware I forgot it. and yeah i was just testing somthing quickly thats why there was a second s guess i forgot to fix it before posting.

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.