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
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
Share on other sites

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.