#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    845
    Rep Power
    0

    Stop cURL Loading Banned Worded Page


    Folks,

    Look at this code:

    PHP Code:
    <?php 

    //RESULT: Code Working!

    //1). Set Banned Words.
    $banned_words = array("blow""nut""bull****");

    // 2). $curl is going to be data type curl resource.
    $curl curl_init();

    // 3). Set cURL options.
    curl_setopt($curlCURLOPT_URL'https://www.buzzfeed.com/mjs538/the-68-words-you-cant-say-on-tv?utm_term=.xlN0R1Go89#.pbd18dYm3X');
    curl_setopt($curlCURLOPT_SSL_VERIFYPEERfalse);
    curl_setopt($curlCURLOPT_RETURNTRANSFERtrue);

    // 4). Run cURL (execute http request).
    $result curl_exec($curl);

    if (
    curl_errno($curl))
    {
        echo 
    'Error:' curl_error($curl);
    }

    $response curl_getinfo$curl );

    if(
    $response['http_code'] == '200' )
    {   
        
    $regex '/\b';
        
    $regex .= implode('\b|\b'$banned_words);
        
    $regex .= '\b/i';
        
    $substitute '****';
        
    $cleanresult preg_replace($regex$substitute$result);
        echo 
    $cleanresult;
    }

    curl_close($curl);

    ?>
    Guess what it does ? Yep! You've guessed it! cURL fetches a page and checks for banned words and then substitutes the words with asterisks.
    Now, I need to convert this page to another script. When the script finds a banned word on the fetched page, instead of replacing the banned words, I want it to give an alert that such and such band word has been found on the page. Or, when it finds a banned word on the fetched page then it should not check for any more banned words from it's banned words list. Immediately after finding a single banned word, it should give alert to the user that so banned word has been found and the page should not load on the user's screen. Is this possible ? I mean, get cURL to fetch the page and give alert of the banned word and exit() the process so the page no longer loads on the user's screen ?
    And, is it possible to get the script to start checking for banned word as the page data is coming through ?
    Meaning, let's say that, the fetched page is 1MB. Now, let's say the page takes 10 secs to load on your screen based on your internet connection speed. Now, the script should start to get to work on the very 1st sec checking for banned words. So, if it spots the first banned word on the 5th sec then that means 50% of the page has been fetched and a banned word has been found. Here, I want the script to halt the loading. No good wasting bandwidth loading a banned worded page. Now, how to do all this ? Which functions to use ?
    And ofcourse, may we newbies see some examples from your end ? I showed you my best shot!

    Any code you can muster would be most appreciated. Give us your best shot!
    I gave you mine. I came upto that point in the coding after a few months of struggling from forum to forum. So, you're now looking at a piece of work that went under many bridges (forums) and saw the light of many days from east to west and south to north bouncing between preg_replace and str_replace based on different programmers different suggestions on different forums. This forum is now likely to be the final stop as I am now reviving an old project that was halted for about 6 mnths now.
    Now, let's see something thrown from your end to resurrect the project using mysqli procedural style!

    Thanks!
    Last edited by UniqueIdeaMan; March 22nd, 2018 at 03:49 PM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    845
    Rep Power
    0
    Guys.

    If you got a few hundred or a thousand banned words then to list them this way looks messy:
    $banned_words = array("blow", "nut", "bull****");
    I've only listed 3. Try listing a few hundred like that. The page is likely to load real slow to the user. Any chance I can better the code and clean it up ? Neaten it up ? What should I be looking into ?
    Check my original post for my original code.
    How would you go about doing things ? Let's see some examples from your end.

    Cheers!
    Last edited by UniqueIdeaMan; March 22nd, 2018 at 04:29 PM.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    845
    Rep Power
    0
    You know, this line is doing all the replacing:
    PHP Code:
    if($response['http_code'] == '200' )
    {   
        
    $regex '/\b';
        
    $regex .= implode('\b|\b'$banned_words);
        
    $regex .= '\b/i';
        
    $substitute '****';
        
    $cleanresult preg_replace($regex$substitute$result);
        echo 
    $cleanresult;

    I am stuck on how to change this part to achieve what I want mentioned in my original post about not getting the banned words substituted but getting the script to find one banned word and give alert to user that the page contains so banned word and then halt the script (kill it!).
    What lines of codes must I use to substitute the above mentioned code ?
    Folks, do remember to address all my posts up until now.

    Thanks
    Last edited by UniqueIdeaMan; March 22nd, 2018 at 05:41 PM.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    845
    Rep Power
    0
    No ideas ?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    845
    Rep Power
    0
    Bump!
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    845
    Rep Power
    0
    Mmm. I wonder why this thread is silent.

IMN logo majestic logo threadwatch logo seochat tools logo