Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem you had is that you've got your regular expression check within the <code>get_magic_quotes_gpc()</code> call, Joel's code also has <code>reg_replace</code> as a typo, otherwise that would have worked (if you'd have put it outside of the magic quotes check.</p> <p>Here's a fully updated script for you to try.</p> <pre><code>&lt;?php ob_start(); // check if the review form has been sent if(isset($_POST['review_content'])) { if(isset($_POST['review_recipient'])) { $content = $_POST['review_content']; $review_recipient = $_POST['review_recipient']; //We remove slashes depending on the configuration if(get_magic_quotes_gpc()) { $content = stripslashes($content); $review_recipient = stripslashes($review_recipient); } $regex = "/(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w\.-]*)*\/?/"; $replacement = "[blocked url]"; $review_recipient = preg_replace($regex,$replacement,$_POST['review_recipient']); //$profile_id = intval($_POST['profile_id']); //dont know how you get this $content = preg_replace($regex,$replacement,$_POST['review_content']); //We check if all the fields are filled if($_POST['review_content']!='') { if($_POST['review_recipient']!='') { $sql = "INSERT INTO ptb_reviews (id, from_user_id, from_guest, to_user_id, content) VALUES (NULL, '-1', '".$review_recipient."', '".$profile_id."', '".$content."');"; mysql_query($sql, $connection); $_SESSION['message']="&lt;div class=\"infobox-wallpost\"&gt;&lt;strong&gt;Thank You&lt;/strong&gt; - Your review has been sent and is awaiting approval.&lt;/div&gt;&lt;div class=\"infobox-close4\"&gt;&lt;/div&gt;"; header("Location: {$_SERVER['HTTP_REFERER']}"); } } } } ?&gt; </code></pre> <p>If you want to block specific words you can also add something like this:</p> <pre><code>$regex2 = "/(.*)\b(word1|word2|word3)\b(.*)/"; $replacement2 = "[blocked word]"; </code></pre> <p>Then change your <code>preg_replace</code> to something like this:</p> <pre><code>$content = preg_replace(Array($regex, $regex2),Array($replacement, $replacement2),$_POST['review_content']); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload