Jump to content

sleep() not working


lAZLf

Recommended Posts

On my website I want the page to display "you have just commented" after you comment for a few seconds and then redirect the page back. I'm trying to do this with a delay using the sleep() function but it doesnt seem to be working. anyone know what's wrong?

 

<?php
session_start();
$page = $_GET['page'];
if($page == "portfolio") {
  if (isset($_GET['id'])) {

// dBase file
include "dbConfig.php";
$content = $_POST['comment'];

$date = date('M d, Y');
$id = mysql_real_escape_string($_GET['id']);
if (isset($_SESSION['valid_user'])) {
$poster = $_SESSION['valid_user'];
} else {
$poster = "anonymous";
}
$ip = getenv("REMOTE_ADDR") ; 

// Create query
$q = "INSERT INTO piccomments (topicid, date, content, poster, ip) VALUES ('$id', '$date', '$content', '$poster', '$ip')";
// Run query
mysql_query($q,$ms) or trigger_error (mysql_error());

echo'<h1>You Just Commented</h1>';
sleep(10);
$header = 'Location: '.$_SERVER['HTTP_REFERER'];
header ($header);

  }
}  else {
  if (isset($_GET['id'])) {

// dBase file
include "dbConfig.php";
$content = $_POST['comment'];

$date = date('M d, Y');
$id = mysql_real_escape_string($_GET['id']);
if (isset($_SESSION['valid_user'])) {
$poster = $_SESSION['valid_user'];
} else {
$poster = "anonymous";
}
$ip = getenv("REMOTE_ADDR") ; 

// Create query
$q = "INSERT INTO comments (topicid, date, content, poster, ip) VALUES ('$id', '$date', '$content', '$poster', '$ip')";
// Run query
mysql_query($q,$ms) or trigger_error (mysql_error());
echo'<h1>You Just Commented</h1>';
sleep(10);
$header = 'Location: '.$_SERVER['HTTP_REFERER'];
header ($header);

  }
}
?>

Link to comment
https://forums.phpfreaks.com/topic/194357-sleep-not-working/
Share on other sites

I'm trying to use this but it's still not work:

echo'<html><head><script type="text/Javascript">
function redirectuser() {
	  setTimeout("location.href=\''.$_SERVER['HTTP_REFERER'].'\'", 5000);
}
</script></head>
<body onLoad='redirectuser();'><h1>You Just Commented</h1><br />
<noscript><a href="'.$_SERVER['HTTP_REFERER'].'"><-- go back</a></noscript></body></html>';

 

EDIT: it works, 'just had problems with uploading the file.

Link to comment
https://forums.phpfreaks.com/topic/194357-sleep-not-working/#findComment-1022423
Share on other sites

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.