PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Im having trouble getting my script to do what i want it to do. I upload a file to a newsboard. when i select upload a script does some sql and then i want to return back to that page. the code i use is
<?php
//script written with the help of chapter 26 PHP & Web Development by Luke Welling 04/02/2005
require('page.inc');
require_once('news_fns.php');
$link_id = db_connect();
$now = time();
$story = $_GET['story'];
$query = "update stories set published = $now
where story_id = $story";
$result = mysql_query($query, $link_id);
header('Location: '.$HTTP_SERVER_VARS['HTTP_REFERER']);
exit;
?>
You can only use the header() function if no output has been sent. It looks like page.inc is sending output. If you can, try moving require('page.inc') below the code that handles the redirect.
yeah, there may be some blank lines you don't realize are being sent by the time the header call is being made. Also beware that some browsers/devices don't send the referer information. When I need to know where in the site they came from, I pass the location information along through multiple means, but typically try to keep it outside the user's submission.. so the session variable space is used most often.
Going along with this question, I have a question.
In the php.ini file you can turn on output_buffering and you can use headers after there has been output. Can some one tell me why you wouldn't want to do this? Does it just slow down PHP a little?
keiths wrote: Does it just slow down PHP a little?
yes. depending on various factors, it could speed things up, or slow them down. usually it slows it down a bit though.
if your pages are relatively small, the performance hit is very small. but if you have some pages that are very large, and take a while to process(like this forum would be a prime example) output buffering would slow things down.