ArizonaJohn Posted June 11, 2009 Share Posted June 11, 2009 Hello, The code below prints "Topic Declined" if $_POST['name'] contains a porn word from a function called "check_porn_terms." I would like the code below to do a re-direct to a page called indexdeclined.php (header("Location:indexdeclined.php"); ) if $_POST['name'] contains a porn word. How do I do this? Thanks in advance, John if(!check_porn_terms($_POST['name'])) die("<p class=\"topic2\">Topic Declined.</p>"); Link to comment https://forums.phpfreaks.com/topic/161768-solved-header-function-triggered-by-die/ Share on other sites More sharing options...
cunoodle2 Posted June 11, 2009 Share Posted June 11, 2009 In your code you have a "!" at the beginning of your if statement which would tell me if there was NOT a swear word then echo "Topic Declined" to the screen. Is it supposed to be like that? Can you just do something like this... <?php if(check_porn_terms($_POST['name'])) { echo "Topic declined. You be redirected in 5 seconds to another page.<br />\n"; echo "<meta http-equiv=\"REFRESH\" content= \"3;url=http://www.YourSiteHere.com/indexdeclined.php\">"; die(); } //put everything here that you would like displayed if there was NOT a swear word... ?> Link to comment https://forums.phpfreaks.com/topic/161768-solved-header-function-triggered-by-die/#findComment-853575 Share on other sites More sharing options...
ArizonaJohn Posted June 11, 2009 Author Share Posted June 11, 2009 Sorry, Here is all the code: <?php function check_porn_terms($input){ $porn_terms = array("porn", "sex", "tits", "cock", "penis", "vagina", "pussy", "itakeithard", "hard_cock", "really_hard_cock", "suckmydickbitch", "fuck"); //add terms here foreach($porn_terms as $term){ if(substr_count($input, $term) > 0) return false; } return true; } if(!check_porn_terms($_POST['name'])) die("<p class=\"topic2\">Topic Declined.</p>"); Link to comment https://forums.phpfreaks.com/topic/161768-solved-header-function-triggered-by-die/#findComment-853581 Share on other sites More sharing options...
cunoodle2 Posted June 11, 2009 Share Posted June 11, 2009 Did you try my code at all? Use this... <?php if(!check_porn_terms($_POST['name'])) { echo "Topic declined. You be redirected in 5 seconds to another page.<br />\n"; echo "<meta http-equiv=\"REFRESH\" content= \"3;url=http://www.YourSiteHere.com/indexdeclined.php\">"; die(); } //put everything here that you would like displayed if there was NOT a swear word... ?> Link to comment https://forums.phpfreaks.com/topic/161768-solved-header-function-triggered-by-die/#findComment-853582 Share on other sites More sharing options...
haku Posted June 11, 2009 Share Posted June 11, 2009 Meta refreshes are frowned upon by search engines. I would suggest rewriting that as this: if(check_porn_terms($_POST['name'])) { header('refresh: 5; url=http://www.example.com'); echo "Topic declined. You be redirected in 5 seconds to another page.<br />\n"; die(); } //put everything here that you would like displayed if there was NOT a swear word... ?> This will refresh the page in 5 seconds (its the number after 'refresh: ') to example.com. Change this to whatever URL you want them to be redirected to. Link to comment https://forums.phpfreaks.com/topic/161768-solved-header-function-triggered-by-die/#findComment-853584 Share on other sites More sharing options...
ArizonaJohn Posted June 11, 2009 Author Share Posted June 11, 2009 Thanks for the answers, I ended up going with cunoodle2's response since it worked. I changed the 3 to 0... and there is still a split second delay. Is there any way to make the redirect instantaneous? Link to comment https://forums.phpfreaks.com/topic/161768-solved-header-function-triggered-by-die/#findComment-853587 Share on other sites More sharing options...
trq Posted June 11, 2009 Share Posted June 11, 2009 Yes, just use the header function. if(!check_porn_terms($_POST['name'])) { header("Location: http://www.YourSiteHere.com/indexdeclined.php"); die(); } Link to comment https://forums.phpfreaks.com/topic/161768-solved-header-function-triggered-by-die/#findComment-853623 Share on other sites More sharing options...
ArizonaJohn Posted June 11, 2009 Author Share Posted June 11, 2009 Thanks, thorpe. I just remembered that to use the header() function, you also have to put this code at the top of your page: <?php ob_start(); ?> Link to comment https://forums.phpfreaks.com/topic/161768-solved-header-function-triggered-by-die/#findComment-854000 Share on other sites More sharing options...
trq Posted June 12, 2009 Share Posted June 12, 2009 No you don't. You just can't output anything to the browser before calling header. If you think about it though, there is no point outputting anything if all your going to do is redirect anyway. Link to comment https://forums.phpfreaks.com/topic/161768-solved-header-function-triggered-by-die/#findComment-854298 Share on other sites More sharing options...
haku Posted June 12, 2009 Share Posted June 12, 2009 Using ob_start() is almost always a sign of bad programming structure/logic. There are exceptions (or it wouldn't exist), but you are better off restructuring your code so that any headers and cookies are set before any output to the browser. Link to comment https://forums.phpfreaks.com/topic/161768-solved-header-function-triggered-by-die/#findComment-854364 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.