Jump to content

Headers already sent


heinkasner

Recommended Posts

I have this code snippet:

 

echo "<script language='javascript'>alert('FreeExam database backed up successfully');</script>";

header('Location: Admin.php');

exit();

 

When I take the first line out, it works fine, but when running this, it gives me the following error: 'Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\FreeExam\Selector.php:209) in C:\xampp\htdocs\FreeExam\Selector.php on line 210' . I need to display a message to the user before redirecting to the Admin.php page.

 

Any help would be greatly appreciated!!

Link to comment
https://forums.phpfreaks.com/topic/264821-headers-already-sent/
Share on other sites

(And Pikachu2000 has helped me a million times on this board, it seems.  Best to listen to his advice :) )

 

And yet you only have 204 posts ;)

 

 

You could try something like this:

 

header("Refresh: 5; Admin.php");
echo "<script language='javascript'>alert('FreeExam database backed up successfully');</script>";

(And Pikachu2000 has helped me a million times on this board, it seems.  Best to listen to his advice :) )

 

And yet you only have 204 posts ;)

 

 

You could try something like this:

 

header("Refresh: 5; Admin.php");
echo "<script language='javascript'>alert('FreeExam database backed up successfully');</script>";

 

 

Post count is not directly proportional to skill, knowledge or number of times a user has been helped, or has helped others.

 

 

As you've proven time and time again ;)

Personally, I wouldn't do it that way, I'd do this:

 

 

// do whatever you need to do
header('location: Admin.php?backup=true');
exit;

 

//Admin.php

<?php
if ( isset($_GET['backup']) )
{
   // do whatever?
   $backupMessage = 'FreeExam database backed up successfully';
}
?>
// html
<?php echo isset($backupMessage) ? $backupMessage : ''; ?>

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.