Page 2 of 2 First 12
  • Jump to page:
    #16
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    318
    Rep Power
    1
    Originally Posted by Sepodati
    lol, no. Not even close. PHP gave you a notice that it was converting an array to a string and your code didn't work. So you decide to cast your array to a string, thus recreating the exact same condition that didn't work before.

    At least you admin to guessing because you don't have a ****ing clue what to do.

    What's the manual say for the parameters?

    I manage to fix my own code:

    PHP Code:
    if (!$urlIsValid) {
      die(
    "Error: The requested URL was disallowed by the server administrator.");
    }
    $response makeRequest($url);
    $rawResponseHeaders $response["headers"];
    $responseBody $response["body"];
    $responseInfo $response["responseInfo"];

    //SET THE BANNED WORDS.
    $banned_words = array("Prick","****","bull****","****","asshole");

    //SUBSTITUTE THE BANNED WORDS ON PROXIED PAGE (CONTENT FILTERING).
    if($responseInfo['http_code'] == '200' )
        {
         
            
    $regex '/\b';      // The beginning of the regex string syntax
            
    $regex .= implode('\b|\b'$banned_words);      // joins all the banned words to the string with correct regex syntax
            
    $regex .= '\b/i';    // Adds ending to regex syntax. Final i makes it case insensitive
            
    $substitute '****';
            
    $responseBody preg_replace($regex$substitute$responseBody);        
        } 
    I changed this:
    PHP Code:
    $url preg_replace($regex$substitute$response); 
    to this:

    PHP Code:
    $responseBody preg_replace($regex$substitute$responseBody); 
    Last edited by UniqueIdeaMan; October 20th, 2017 at 08:26 PM.
  2. #17
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    318
    Rep Power
    1
    Originally Posted by Catacaustic
    No. For so many reasons, no.

    You need to go back to the basics and learn about data structures, programming flow, proper use of functions, and all of the really boring generic stuff that we all have to learn at the start. Without that base you will never be able to write your own code properly (as evidenced here by your lack of understanding even simple concepts).

    As an example, you can't just cast an array as a string. That's just crazy, and will most likely end up with giving you wrong results because you don't know what you're actually passing in to that function.

    Before you say anything, this is not meant as an attack on you. This is meant as guidance. Don't start off over your head, which is what you are doing. It's great that you have all of these ideas, but unless you spend the time learning how to code properly from the ground up you'll never be able to do anything yourself.
    I knew this TypeCasting wass utterly wrong from the beginning. But, I went ahead with it understanding another programmer wrong when he said: "Try converting the array: $banned_words to a string and then continue from there.".

    What I should have done was this (probably) to turn the 3rd parameter into a string:

    PHP Code:
    $responseBody preg_replace($regex$substitute'$responseBody'); 
    instead of this:

    PHP Code:
    $cleanresponse preg_replace($regex$substitute, (string)$response); 
    Yes, I know. I know. That is still not following what the other programmer said as he mentioned nothing about the 3rd parameter but the $banned_words variable.
    I already read the php basics twice in 1.75yrs. But, I still sometimes forget the basics.
    Last edited by UniqueIdeaMan; October 20th, 2017 at 08:29 PM.
  4. #18
  5. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,814
    Rep Power
    4536
    Hey, lookie there. Blind squirrel found a nut.
    -- Cigars, whiskey and wild, wild women. --
  6. #19
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    318
    Rep Power
    1
    Originally Posted by Sepodati
    lol, no. Not even close. PHP gave you a notice that it was converting an array to a string and your code didn't work. So you decide to cast your array to a string, thus recreating the exact same condition that didn't work before.

    At least you admin to guessing because you don't have a ****ing clue what to do.

    What's the manual say for the parameters?
    Ah! So, I should not convert the array into a string ? I thought it was telling me to do it! Lol! I will have to familiarise this error and remember what it meant. I gave you a REP for bringing this to my attention that I wwas undersstanding the error mssge opposite to what it meant.
    Gave Catacaustic a REP too for making it clear that I'd get an error as I was doing it the wrong way when I TypeCasted an array.
  8. #20
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    318
    Rep Power
    1
    Just before I packup for the night, I want to ask a question.
    You know the $responseBody was carrying the html of the page. And, I was checking for banned words on the page and replacing the banned words with ****. Was doing all that, with this code:
    PHP Code:
    if($responseBody == 
    if(
    $responseInfo['http_code'] == '200' )
        {
         
            
    $regex '/\b';      // The beginning of the regex string syntax
            
    $regex .= implode('\b|\b'$banned_words);      // joins all the banned words to the string with correct regex syntax
            
    $regex .= '\b/i';    // Adds ending to regex syntax. Final i makes it case insensitive
            
    $substitute '****';
            
    $responseBody preg_replace($regex$substitute$responseBody);        
        } 
    Now, imagine that, I no longer want the filter to replace banned words but give alert to the user insttead that the banned words exist on the page (the page the user is currently viewing).
    How would I code it ?
    The Pseudo Code is this, which I need to convert to php:

    IF->$response->contains any of the array values;
    Then->Echo: Banned word "blah blah" is found!"".

    Here is my attempt:
    PHP Code:
    Run cURL (execute http request).
    $result curl_exec($curl);
    $response curl_getinfo$curl );

    if( 
    $response['http_code'] == '200' )
    {
        
    //Set banned words.
        
    $banned_words = array("blow""nut""bull****");

        
    //Separate each words found on the cURL fetched page.
        
    $word explode(" "$result);
        
       
    //var_dump($word);

        
    for($i 0$i <= count($word); $i++){
            foreach (
    $banned_words as $ban) {
                if (
    stripos($word[$i],$ban) !== FALSE){
                    echo 
    "word: $word[$i]<br />";
                    echo 
    "Match: $ban<br>";
                }else{
                    echo 
    "word: $word[$i]<br />";
                    echo 
    "No Match: $ban<br>";  
                }
            }
        }

    Now, it is your turn to find flaw in it and show me a correction.
    Last edited by UniqueIdeaMan; October 20th, 2017 at 08:53 PM.
  10. #21
  11. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,814
    Rep Power
    4536
    An actual programmer would go to the preg_* section of the manual and look for something related to preg_replace(), dumbass.
    -- Cigars, whiskey and wild, wild women. --
  12. #22
  13. Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2017
    Location
    Lithuania
    Posts
    22
    Rep Power
    0
    Originally Posted by UniqueIdeaMan
    Now, it is your turn to find flaw in it and show me a correction.
    Sure thing. How much will you pay?
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo