Page 1 of 1

Target in php header refresh

Posted: 07 Mar 2018, 09:12
by JanMolendijk
Dear Admin sorry I post twice questions into few hours
but I try to add a target="shout" into this code what I did went all wrong
I realy hope you have a sugestion for me `thanks for your support`

Code: Select all

if($stmt->execute())
{
  $successMSG = "You succesfully Shouted...";
  header("refresh:5;Show-Shout-Reply.php?id=$users[id]&id_2=$_GET[notice_id]"); // redirects image view page after 5 seconds.
}
else
{
  $errMSG = "error while inserting....";
}
This is wrong but for example

Code: Select all

refresh:5;Show-Shout-Reply.php?id=$users[id]&id_2=$_GET[notice_id];target:shout

Target in php header refresh

Posted: 08 Mar 2018, 07:00
by Admin
Hello,
From what i know, there is no "target" option to the php header('refresh') function.
The correct sintax for header('refresh') is:

Code: Select all

header('Refresh:5; url=page_url.php');
echo 'Refresh in 5 seconds.';

If the target you want to refresh is an <iframe> you should rethink the code to use javascript.
For example, this code refreshes an <iframe to specified page-url after 5 seconds;

Code: Select all

<script>
window.setTimeout("refreshIFrame();", 5000);
function refreshIFrame() {
 document.getElementById('iframe_id').src='your_page_url.php';
}
</script>

Target in php header refresh

Posted: 08 Mar 2018, 13:32
by JanMolendijk
Thanks for the explain, stupid question why after 5 seconds refreshIFrame ?
is it a problem if I set this to 1 second ?

Target in php header refresh

Posted: 09 Mar 2018, 05:24
by Admin
You can put the time you want, in javascript the time is in miliseconds (1000 =1 second, 500 =0.5 seconds).