lAZLf Posted March 6, 2010 Share Posted March 6, 2010 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 More sharing options...
harristweed Posted March 6, 2010 Share Posted March 6, 2010 You cant have html content before a header call. It will never work. Java Script will do the job for you. Link to comment https://forums.phpfreaks.com/topic/194357-sleep-not-working/#findComment-1022414 Share on other sites More sharing options...
lAZLf Posted March 6, 2010 Author Share Posted March 6, 2010 In that case could someone post how I would do that in Javascript? I only know the very very basics in JS. Link to comment https://forums.phpfreaks.com/topic/194357-sleep-not-working/#findComment-1022417 Share on other sites More sharing options...
lAZLf Posted March 6, 2010 Author Share Posted March 6, 2010 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.