Jump to content

[SOLVED] header() function triggered by die()


ArizonaJohn

Recommended Posts

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

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...

?>

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>");

 

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...

?>

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.

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.