一次可以在函数中使用两个变量吗?

The function check_porn_terms below checks to see if a variable contains terms that are not family friendly, and it it does, then re-directs the user back to the main page.

As listed below, it checks to see if the variable $title has non-family friendly terms. I would like to perform this check on another variable, $cleanurl. Could I just replace check_porn_terms($title) below with check_porn_terms($title, $cleanurl) or something like that? If not, how should I do it?

Thanks in advance,

John

if(!check_porn_terms($title))
{

   session_write_close();
   header("Location:http://www.domain.com/index.php");
   exit;

}

You just need to call the function twice (combined with the "or" || operator) to check each variable:

if(!check_porn_terms($title) || !check_porn_terms($cleanurl))
{
    session_write_close();
    header("Location:http://www.domain.com/index.php");
    exit;
}

If you wrote the function yourself, redefine it to check_porn_terms() (no args), and then inside the function, loop over func_get_args and check if each of the arguments are "clean".

But yes, you could have it take two arguments instead, if you wanted to. My point is, why stop at two? Let it take any number of arguments.

While you're at it, you could try actually reading the page, and scan the entire body of the page for dirty words.

If you wanted to pass in additional parameters to check_porn_terms, you'd need to redefine the function

 function check_porn_terms($first_term, $second_term)
 {
     //code to check both terms here
 }

You could also rewrite the function to accept an array for parameters and then foreach over them, or get really fancy with func_get_args()

What you probably want to do, and can do without redefining the function, is to call the function twice

// the || means "or"
if(!check_porn_terms($title) || !check_porn_terms($cleanurl))
{
}