Jump to content

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 : ''; ?>

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.