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

    Join Date
    Jan 2017
    Posts
    761
    Rep Power
    0

    Question Why str_replace Failing ?


    Php Masters,

    I am continuing my 1yr old thread from sitepoint.com here as I got banned over there just for laughing at the answers the php seniors over there gave me on one of my other threads that is not the thread mentioned below. BIG MISTAKE on my part.

    Anyway, why is the str_replace failing ? I didn't get my answer at that forum (or I have forgotten what they replied over there) so trying my luck here with you kind folks.
    My thread over there attracted 247 posts in total! Let's see how many posts it attracts over here. Shall we ?
    https://www.sitepoint.com/community/...nts/264321/242

    I have grabbed my latest code from there:
    https://www.sitepoint.com/community/...nts/264321/242

    Let's continue working on it with you precious folks' help. Hopefully, you'll remove my confusions over there.

    My question is again: why is the str_replace failing ?

    I was trying to build my own web proxy using cURL. After it fetches your chosen page, it checks the links found on the page and tries proxifying them so when those links are clicked they go through this same one page proxy script.
    It's a one page script:

    proxied_page.php
    PHP Code:
    <?php
    //STEP 1: ERROR HANDLING
    declare(strict_types=1);
    ini_set('display_errors''1');
    ini_set('display_startup_errors''1');
    //For All Error, Warning and Notice
    error_reporting(E_ALL);
    E_DEPRECATED;
    /* STEP 2:
    The IF gets triggered as soon as the "submit" button is clicked in the ui text box labeled: Url
    Following IF code deals with GET method.
    */
    if(isset($_GET["url_to_proxify"]) === TRUE)
       {
            echo 
    "IF got triggered!";
            
    $url_to_proxify filter_input(INPUT_GET'url_to_proxify'FILTER_VALIDATE_URL);
            
    $ch curl_init();
            
    curl_setopt($chCURLOPT_URL"$url_to_proxify");
            
    curl_setopt($chCURLOPT_FOLLOWLOCATIONTRUE);
            
    curl_setopt($chCURLOPT_HEADER5);
            
    curl_setopt($chCURLOPT_RETURNTRANSFERTRUE);
            
    $curl_result curl_exec($ch);        
            
    $domain parse_url($url_to_proxifyPHP_URL_HOST);
            
    //echo var_dump($domain);
            //Add proxy link on all links present on proxified page
            
    $pattern = array("http://""https://""http://www.""https://www.""localhost");
            
    $replace = array("proxied_page.php?url_to_proxify=http://\".$domain\"""proxied_page.php?url_to_proxify=https://\".$domain\"""proxied_page.php?url_to_proxify=http://www.\".$domain\"""proxied_page.php?url_to_proxify=https://www.\".$domain\"""proxied_page.php?url_to_proxify=http://www.\".$domain\"");
            
    $string_replaced_data str_replace($pattern$replace$curl_result);
            
    //echo var_dump($string_replaced_data);
            //Add proxy link on all Image Links (Eg. Google Img File). Note the spaces before or after the equal sign. Note the variations.     
            
    $pattern = array('src="''src = "''src= "''src ="'"src='""src = '""src= '""src='");
            
    $replace = array('src="proxied_page.php?url_to_proxify=\".$domain\""''src = "proxied_page.php?url_to_proxify=\".$domain\""''src= "proxied_page.php?url_to_proxify=\".$domain\""''src ="proxied_page.php?url_to_proxify=\".$domain\""'"src='proxied_page.php?url_to_proxify=\".$domain\"'""src = 'proxied_page.php?url_to_proxify=\".$domain\"'""src= 'proxied_page.php?url_to_proxify=\".$domain\"'""src ='proxied_page.php?url_to_proxify=\".$domain\"'");
            
    $string_replaced_data str_replace($pattern$replace$curl_result);
            
    //echo var_dump($string_replaced_data);
            //Add proxy link on all links presented by the searchengine result pages (SERPS). Eg. Google Search Pages (SERPs)
            
    $pattern = array('action="''action = "''action= "''action ="'"action='""action = '""action= '""action='");
            
    $replace = array('action="proxied_page.php?url_to_proxify=\".$domain\""''action = "proxied_page.php?url_to_proxify=\".$domain\""''action= "proxied_page.php?url_to_proxify=\".$domain\""''action ="proxied_page.php?url_to_proxify=\".$domain\""'"action='proxied_page.php?url_to_proxify=\".$domain\"'""action = 'proxied_page.php?url_to_proxify=\".$domain\"'""action= 'proxied_page.php?url_to_proxify=\".$domain\"'""action ='proxied_page.php?url_to_proxify=\".$domain\"'");
            
    $string_replaced_data str_replace($pattern$replace$curl_result);
            
    //echo var_dump($string_replaced_data);
            
    print_r($curl_result);
            
    curl_close($ch);
        
                
    }
    else
        {
            echo 
    "ELSE got triggered!";
            
    //Html Form
            
    ?>
            <html>
                <body>   
                    <form action = "<?php echo $_SERVER['PHP_SELF']; ?>" method = "GET">
                    Url: <input type = "text" name = "url_to_proxify" />
                    <input type = "submit" />
          </form>      
       </body>
    </html>
    <?php
        
    }
    ?>
    In short, that code belongs to a page called "proxied_page.php".
    It shows you a url input text box. You input your url (the page you want the proxy to fetch or the page you want proxied) and it fetches your chosen page by reloading itself. Reloading proxied_page.php I mean.
    Every link found on the proxied page should be preceded by the likes of:
    proxied_page.php?url_to_proxify=

    So, if you input:
    Google
    then that page should be fetched.
    Now imagine that fetched page (eg. original google.com page) has the following links:

    <a href="http://www.google.com/contactus.html">Contact Us</a>
    <src='image.jpeg'>Click Image</a>


    On the proxied page (eg. 301 Moved Permanently), the links should show like this:

    <a href="http://mydomain.com/proxied_page.php?url_to_proxify=http://www.google.com/contactus.html">Contact Us</a>
    <http://mydomain.com/proxied_page.php?url_to_proxify=src='image.jpeg'>Click Image</a>


    That way, when the text link or the img link is clicked, they get proxified. Meaning, they load through this one page again: proxied_page.php?url_to_proxify=

    But guess what ? On the proxied page, when I click the text or the img link, I go direct to the links.
    I don't go to the proxied text link or the proxied img link.
    The str_replace is failing here. That is the problem.
    The guys at sitepoint.com failed to solve this issue (if I am not mistaken or have not forgotten things). Their suggestions have not worked for me. And so, let us see if you can do better.
    Any suggestions my friends Kicken ? Sepodati ? Catacaustic ? Barand ? Even Benanamen ?

    The script should work from both localhost and my website (remote server).
    Do check-out my code on your wamp/xamp/lamp to get an idea where I am stuck.
    When the proxied page loads, hover your mouse over the links. You will see the links are not preceded by:

    proxied_page.php?url_to_proxify=

    That is the issue with the str_replace here.

    Requinix welcome to provide valuable inputs too.

    PS - I see that, a year back, I was a better programmer than I am now!
    I have forgotten a lot of things over the months. Let us change this. Shall we ?
    Last edited by UniqueIdeaMan; May 2nd, 2018 at 11:11 AM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,437
    Rep Power
    652
    Did you bother with common debugging practices and echo $string_replaced_data? Why didn't you post that result?
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    761
    Rep Power
    0
    Originally Posted by gw1500se
    Did you bother with common debugging practices and echo $string_replaced_data? Why didn't you post that result?
    Don't you see I got my error codes up at the top of my script ?
    PHP Code:
    declare(strict_types=1);
    ini_set('display_errors''1');
    ini_set('display_startup_errors''1');
    //For All Error, Warning and Notice
    error_reporting(E_ALL); 
    Don't you see the line at 40 that echoes the result after str_replace ?
    PHP Code:
    print_r($curl_result); 
    I don't see errors. When I fetch a page. I hover my mouse over to the links found on the fetched page. I don't see the links getting proxied. Meaning, I don't see the following preceding the links found on the proxied page.
    proxied_page.php?url_to_proxify=

    That's the problem. The str_replace for some reason is not working for me. What is wrong ? preg_replace is not needed here.
    Really angering me! Maddended me 12 mnths back at sitepoint.com forum and now annoying me real bad tonight over here. Feeling really grumpy!
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,437
    Rep Power
    652
    Try rereading what I posted about what should be echoed.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    761
    Rep Power
    0
    Originally Posted by gw1500se
    Did you bother with common debugging practices and echo $string_replaced_data? Why didn't you post that result?
    Thanks man!
    I got your hint.
    I wrote like this:
    PHP Code:
    print_r($curl_result); 
    When it should have been like this on line 40:
    PHP Code:
    print_r($string_replaced_data); 
    But, guess what ? It still ain't working.
    And so, I switched to:
    PHP Code:
    echo "$string_replaced_data"
    And no luck.
    I get echoed: echo "IF got triggered!"
    So, I took this line out of line 15 by commenting it out. And then tested with both echo and printr and I see a complete white blank page.
    Trying to fetch yahoo.com on all these test rounds.

    Here's the final code now. Check the commented-out lines to see in what variety of ways I tested.
    PHP Code:
    <?php
    //STEP 1: ERROR HANDLING
    declare(strict_types=1);
    ini_set('display_errors''1');
    ini_set('display_startup_errors''1');
    //For All Error, Warning and Notice
    error_reporting(E_ALL);
    E_DEPRECATED;
    /* STEP 2:
    The IF gets triggered as soon as the "submit" button is clicked in the ui text box labeled: Url
    Following IF code deals with GET method.
    */
    if(isset($_GET["url_to_proxify"]) === TRUE)
       {
            
    //echo "IF got triggered!";
            
    $url_to_proxify filter_input(INPUT_GET'url_to_proxify'FILTER_VALIDATE_URL);
            
    $ch curl_init();
            
    curl_setopt($chCURLOPT_URL"$url_to_proxify");
            
    curl_setopt($chCURLOPT_FOLLOWLOCATIONTRUE);
            
    curl_setopt($chCURLOPT_HEADER5);
            
    curl_setopt($chCURLOPT_RETURNTRANSFERTRUE);
            
    $curl_result curl_exec($ch);        
            
    $domain parse_url($url_to_proxifyPHP_URL_HOST);
            
    //echo var_dump($domain);
            //Add proxy link on all links present on proxified page
            
    $pattern = array("http://""https://""http://www.""https://www.""localhost");
            
    $replace = array("proxied_page.php?url_to_proxify=http://\".$domain\"""proxied_page.php?url_to_proxify=https://\".$domain\"""proxied_page.php?url_to_proxify=http://www.\".$domain\"""proxied_page.php?url_to_proxify=https://www.\".$domain\"""proxied_page.php?url_to_proxify=http://www.\".$domain\"");
            
    $string_replaced_data str_replace($pattern$replace$curl_result);
            
    //echo var_dump($string_replaced_data);
            //Add proxy link on all Image Links (Eg. Google Img File). Note the spaces before or after the equal sign. Note the variations.     
            
    $pattern = array('src="''src = "''src= "''src ="'"src='""src = '""src= '""src='");
            
    $replace = array('src="proxied_page.php?url_to_proxify=\".$domain\""''src = "proxied_page.php?url_to_proxify=\".$domain\""''src= "proxied_page.php?url_to_proxify=\".$domain\""''src ="proxied_page.php?url_to_proxify=\".$domain\""'"src='proxied_page.php?url_to_proxify=\".$domain\"'""src = 'proxied_page.php?url_to_proxify=\".$domain\"'""src= 'proxied_page.php?url_to_proxify=\".$domain\"'""src ='proxied_page.php?url_to_proxify=\".$domain\"'");
            
    $string_replaced_data str_replace($pattern$replace$curl_result);
            
    //echo var_dump($string_replaced_data);
            //Add proxy link on all links presented by the searchengine result pages (SERPS). Eg. Google Search Pages (SERPs)
            
    $pattern = array('action="''action = "''action= "''action ="'"action='""action = '""action= '""action='");
            
    $replace = array('action="proxied_page.php?url_to_proxify=\".$domain\""''action = "proxied_page.php?url_to_proxify=\".$domain\""''action= "proxied_page.php?url_to_proxify=\".$domain\""''action ="proxied_page.php?url_to_proxify=\".$domain\""'"action='proxied_page.php?url_to_proxify=\".$domain\"'""action = 'proxied_page.php?url_to_proxify=\".$domain\"'""action= 'proxied_page.php?url_to_proxify=\".$domain\"'""action ='proxied_page.php?url_to_proxify=\".$domain\"'");
            
    $string_replaced_data str_replace($pattern$replace$curl_result);
            
    //echo var_dump($string_replaced_data);
            //print_r($string_replaced_data);
            
    echo "$string_replaced_data";
            
    curl_close($ch);            
    }
    else
        {
            echo 
    "ELSE got triggered!";
            
    //Html Form
            
    ?>
            <html>
                <body>   
                    <form action = "<?php echo $_SERVER['PHP_SELF']; ?>" method = "GET">
                    Url: <input type = "text" name = "url_to_proxify" />
                    <input type = "submit" />
          </form>      
       </body>
    </html>
    <?php
        
    }
    ?>
    You wanted me to echo the str_replace results and so I echoed it.
    You wanted me to provide what result I see on screen. I provided it.
    I hope I understood you this time.

    Thanks!

    EDIT: Tried even fetching this page but still a complete white blank page:
    https://www.sitepoint.com/community/...nts/264321/242
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,437
    Rep Power
    652
    I give up. Apparently you can't read either.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,437
    Rep Power
    652
    Arrgh!!! What did you get from the echo? Also echo the input variables.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    761
    Rep Power
    0
    Originally Posted by gw1500se
    Arrgh!!! What did you get from the echo? Also echo the input variables.
    I already told you I got echoed: "IF Got Triggered!"

    Anyway, here's my latest update:
    PHP Code:
    <?php
    //STEP 1: ERROR HANDLING
    declare(strict_types=1);
    ini_set('display_errors''1');
    ini_set('display_startup_errors''1');
    //For All Error, Warning and Notice
    error_reporting(E_ALL);
    E_DEPRECATED;
    /* STEP 2:
    The IF gets triggered as soon as the "submit" button is clicked in the ui text box labeled: Url
    Following IF code deals with GET method.
    */
    if(isset($_GET['url_to_proxify']) === TRUE)
       {
            echo 
    'Line 15-> IF got triggered!'?> <br> <?php 
            
    echo 'Line 16-> Echoing $_GET["url_to_proxify"]: '; echo $_GET["url_to_proxify"]; ?> <br> <?php 
            $url_to_proxify 
    filter_input(INPUT_GET'url_to_proxify'FILTER_VALIDATE_URL); 
            echo 
    'Line 17-> Echoing variable url_to_proxify = filter_input(INPUT_GET, url_to_proxify, FILTER_VALIDATE_URL);: '; echo "$url_to_proxify"?> <br> <?php 
            $ch 
    curl_init();
            
    curl_setopt($chCURLOPT_URL"$url_to_proxify");
            
    curl_setopt($chCURLOPT_FOLLOWLOCATIONTRUE);
            
    curl_setopt($chCURLOPT_HEADER5);
            
    curl_setopt($chCURLOPT_RETURNTRANSFERTRUE);
            
    $curl_result curl_exec($ch);        
            
    $domain parse_url($url_to_proxifyPHP_URL_HOST); 
            echo 
    'Line 26-> var_dump $domain: '; echo var_dump($domain); ?> <br> <?php 
            
    echo 'Line 27-> Echoing $domain: '; echo "$domain"?> <br> <?php 
            
    //Add proxy link on all links present on proxified page
            
    $pattern = array("http://""https://""http://www.""https://www.""localhost");
            
    $replace = array("proxied_page.php?url_to_proxify=http://\".$domain\"""proxied_page.php?url_to_proxify=https://\".$domain\"""proxied_page.php?url_to_proxify=http://www.\".$domain\"""proxied_page.php?url_to_proxify=https://www.\".$domain\"""proxied_page.php?url_to_proxify=http://www.\".$domain\"");
            
    $string_replaced_data str_replace($pattern$replace$curl_result);
            echo 
    'Line 33-> var_dump $string_replaced_data: '; echo var_dump($string_replaced_data); ?> <br> <?php 
            
            
    //Add proxy link on all Image Links (Eg. Google Img File). Note the spaces before or after the equal sign. Note the variations.     
            
    $pattern = array('src="''src = "''src= "''src ="'"src='""src = '""src= '""src='");
            
    $replace = array('src="proxied_page.php?url_to_proxify=\".$domain\""''src = "proxied_page.php?url_to_proxify=\".$domain\""''src= "proxied_page.php?url_to_proxify=\".$domain\""''src ="proxied_page.php?url_to_proxify=\".$domain\""'"src='proxied_page.php?url_to_proxify=\".$domain\"'""src = 'proxied_page.php?url_to_proxify=\".$domain\"'""src= 'proxied_page.php?url_to_proxify=\".$domain\"'""src ='proxied_page.php?url_to_proxify=\".$domain\"'");
            
    $string_replaced_data str_replace($pattern$replace$curl_result);
            echo 
    'Line 39-> var_dump $string_replaced_data: '; echo var_dump($string_replaced_data); ?> <br> <?php 
            
            
    //Add proxy link on all links presented by the searchengine result pages (SERPS). Eg. Google Search Pages (SERPs)
            
    $pattern = array('action="''action = "''action= "''action ="'"action='""action = '""action= '""action='");
            
    $replace = array('action="proxied_page.php?url_to_proxify=\".$domain\""''action = "proxied_page.php?url_to_proxify=\".$domain\""''action= "proxied_page.php?url_to_proxify=\".$domain\""''action ="proxied_page.php?url_to_proxify=\".$domain\""'"action='proxied_page.php?url_to_proxify=\".$domain\"'""action = 'proxied_page.php?url_to_proxify=\".$domain\"'""action= 'proxied_page.php?url_to_proxify=\".$domain\"'""action ='proxied_page.php?url_to_proxify=\".$domain\"'");
            
    $string_replaced_data str_replace($pattern$replace$curl_result);
            echo 
    'Line 45-> var_dump $string_replaced_data: '; echo var_dump($string_replaced_data); ?> <br> <?php 
            
    //print_r($string_replaced_data);
            
    echo 'Line 47: Echoing $string_replaced_data: '; echo "$string_replaced_data"?> <br> <?php 
            curl_close
    ($ch); 
        }
    else
        {
            echo 
    "Line 51: ELSE got triggered!";
            
    //Html Form
            
    ?>
            <html>
                <body>   
                    <form action = "<?php echo $_SERVER['PHP_SELF']; ?>" method = "GET">
                    Url: <input type = "text" name = "url_to_proxify" />
                    <input type = "submit" />
          </form>      
       </body>
    </html>
    <?php
        
    }
    ?>
    I am not seeing the inputted url fetched by cURL. Instead, here is what I see on my screen as the result (result with no errors):

    Line 15-> IF got triggered!
    Line 16-> Echoing $_GET["url_to_proxify"]: https://www.sitepoint.com/community/...nts/264321/242
    Line 17-> Echoing variable url_to_proxify = filter_input(INPUT_GET, url_to_proxify, FILTER_VALIDATE_URL);: https://www.sitepoint.com/community/...nts/264321/242
    Line 26-> var_dump $domain: string(17) "www.sitepoint.com"
    Line 27-> Echoing $domain: www.sitepoint.com
    Line 33-> var_dump $string_replaced_data: string(0) ""
    Line 39-> var_dump $string_replaced_data: string(0) ""
    Line 45-> var_dump $string_replaced_data: string(0) ""
    Line 47: Echoing $string_replaced_data:
    Last edited by UniqueIdeaMan; May 3rd, 2018 at 06:05 AM.
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,437
    Rep Power
    652
    Where did you echo $curl_result? This is debugging 101.

    Comments on this post

    • Catacaustic agrees : Hold on there.. We all know that debugging 101 is FAR to advanced...
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    761
    Rep Power
    0
    Originally Posted by gw1500se
    Where did you echo $curl_result? This is debugging 101.
    Ok, I did not quite echo it but I print_r it and from the looks of things from StackOverFlow they are the same.
    On my original post, my lines go like this:
    PHP Code:
    $string_replaced_data str_replace($pattern$replace$curl_result); 
            
    //echo var_dump($string_replaced_data); 
            
    print_r($curl_result); 
            
    curl_close($ch); 
    Anyway, I have updated my code now.
    I have echoed $curl_result but no luck.
    Look-out for these lines in my following update:
    PHP Code:
    echo 'Line 47: Echoing $curl_result: '; echo "$curl_result"; ?> <br> <?php 
            curl_close
    ($ch); 
        }
    else
        {
            echo 
    "Line 52: ELSE got triggered!";
            
    //Html Form
            
    ?>
            <html>
                <body>   
                    <form action = "<?php echo $_SERVER['PHP_SELF']; ?>" method = "GET">
                    Url: <input type = "text" name = "url_to_proxify" />
                    <input type = "submit" />
          </form>
    Full Update:
    PHP Code:
    <?php
    //STEP 1: ERROR HANDLING
    declare(strict_types=1);
    ini_set('display_errors''1');
    ini_set('display_startup_errors''1');
    //For All Error, Warning and Notice
    error_reporting(E_ALL);
    E_DEPRECATED;
    /* STEP 2:
    The IF gets triggered as soon as the "submit" button is clicked in the ui text box labeled: Url
    Following IF code deals with GET method.
    */
    if(isset($_GET['url_to_proxify']) === TRUE)
       {
            echo 
    'Line 15-> IF got triggered!'?> <br> <?php 
            
    echo 'Line 16-> Echoing $_GET["url_to_proxify"]: '; echo $_GET["url_to_proxify"]; ?> <br> <?php 
            $url_to_proxify 
    filter_input(INPUT_GET'url_to_proxify'FILTER_VALIDATE_URL); 
            echo 
    'Line 17-> Echoing variable url_to_proxify = filter_input(INPUT_GET, url_to_proxify, FILTER_VALIDATE_URL);: '; echo "$url_to_proxify"?> <br> <?php 
            $ch 
    curl_init();
            
    curl_setopt($chCURLOPT_URL"$url_to_proxify");
            
    curl_setopt($chCURLOPT_FOLLOWLOCATIONTRUE);
            
    curl_setopt($chCURLOPT_HEADER5);
            
    curl_setopt($chCURLOPT_RETURNTRANSFERTRUE);
            
    $curl_result curl_exec($ch);        
            
    $domain parse_url($url_to_proxifyPHP_URL_HOST); 
            echo 
    'Line 26-> var_dump $domain: '; echo var_dump($domain); ?> <br> <?php 
            
    echo 'Line 27-> Echoing $domain: '; echo "$domain"?> <br> <?php 
            
    //Add proxy link on all links present on proxified page
            
    $pattern = array("http://""https://""http://www.""https://www.""localhost");
            
    $replace = array("proxied_page.php?url_to_proxify=http://\".$domain\"""proxied_page.php?url_to_proxify=https://\".$domain\"""proxied_page.php?url_to_proxify=http://www.\".$domain\"""proxied_page.php?url_to_proxify=https://www.\".$domain\"""proxied_page.php?url_to_proxify=http://www.\".$domain\"");
            
    $string_replaced_data str_replace($pattern$replace$curl_result);
            echo 
    'Line 32-> var_dump $string_replaced_data: '; echo var_dump($string_replaced_data); ?> <br> <?php 
            
            
    //Add proxy link on all Image Links (Eg. Google Img File). Note the spaces before or after the equal sign. Note the variations.     
            
    $pattern = array('src="''src = "''src= "''src ="'"src='""src = '""src= '""src='");
            
    $replace = array('src="proxied_page.php?url_to_proxify=\".$domain\""''src = "proxied_page.php?url_to_proxify=\".$domain\""''src= "proxied_page.php?url_to_proxify=\".$domain\""''src ="proxied_page.php?url_to_proxify=\".$domain\""'"src='proxied_page.php?url_to_proxify=\".$domain\"'""src = 'proxied_page.php?url_to_proxify=\".$domain\"'""src= 'proxied_page.php?url_to_proxify=\".$domain\"'""src ='proxied_page.php?url_to_proxify=\".$domain\"'");
            
    $string_replaced_data str_replace($pattern$replace$curl_result);
            echo 
    'Line 38-> var_dump $string_replaced_data: '; echo var_dump($string_replaced_data); ?> <br> <?php 
            
            
    //Add proxy link on all links presented by the searchengine result pages (SERPS). Eg. Google Search Pages (SERPs)
            
    $pattern = array('action="''action = "''action= "''action ="'"action='""action = '""action= '""action='");
            
    $replace = array('action="proxied_page.php?url_to_proxify=\".$domain\""''action = "proxied_page.php?url_to_proxify=\".$domain\""''action= "proxied_page.php?url_to_proxify=\".$domain\""''action ="proxied_page.php?url_to_proxify=\".$domain\""'"action='proxied_page.php?url_to_proxify=\".$domain\"'""action = 'proxied_page.php?url_to_proxify=\".$domain\"'""action= 'proxied_page.php?url_to_proxify=\".$domain\"'""action ='proxied_page.php?url_to_proxify=\".$domain\"'");
            
    $string_replaced_data str_replace($pattern$replace$curl_result);
            echo 
    'Line 44-> var_dump $string_replaced_data: '; echo var_dump($string_replaced_data); ?> <br> <?php 
            
    //print_r($string_replaced_data);
            
    echo 'Line 46: Echoing $string_replaced_data: '; echo "$string_replaced_data"?> <br> <?php 
            
    echo 'Line 47: Echoing $curl_result: '; echo "$curl_result"?> <br> <?php 
            curl_close
    ($ch); 
        }
    else
        {
            echo 
    "Line 52: ELSE got triggered!";
            
    //Html Form
            
    ?>
            <html>
                <body>   
                    <form action = "<?php echo $_SERVER['PHP_SELF']; ?>" method = "GET">
                    Url: <input type = "text" name = "url_to_proxify" />
                    <input type = "submit" />
          </form>      
       </body>
    </html>
    <?php
        
    }
    ?>
    I see this result loading on screen on a white empty background:

    Line 15-> IF got triggered!
    Line 16-> Echoing $_GET["url_to_proxify"]: https://www.sitepoint.com/community/...nts/264321/242
    Line 17-> Echoing variable url_to_proxify = filter_input(INPUT_GET, url_to_proxify, FILTER_VALIDATE_URL);: https://www.sitepoint.com/community/...nts/264321/242
    Line 26-> var_dump $domain: string(17) "www.sitepoint.com"
    Line 27-> Echoing $domain: www.sitepoint.com
    Line 32-> var_dump $string_replaced_data: string(0) ""
    Line 38-> var_dump $string_replaced_data: string(0) ""
    Line 44-> var_dump $string_replaced_data: string(0) ""
    Line 46: Echoing $string_replaced_data:
    Line 47: Echoing $curl_result:
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,437
    Rep Power
    652
    So what do you see for $curl_result? What do you expect $str_replace to replace in that empty string? If you understood kindergarten debugging you would have figured out it is the curl that is the problem rather than str_replace before you even had to post here. Since you copy and paste examples that intentionally omit any error checking logic for simplicity rather than try to understand the code you would have found the error immediately in your error reporting and again before even asking here.

    I may need to change my signature line to:

    There are 11 kinds of people in the world. Those that understand binary, those that don't and UniqueIdeaMan.
    Last edited by gw1500se; May 4th, 2018 at 10:12 AM.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    761
    Rep Power
    0
    Originally Posted by gw1500se
    So what do you see for $curl_result? What do you expect $str_replace to replace in that empty string? If you understood kindergarten debugging you would have figured out it is the curl that is the problem rather than str_replace before you even had to post here. Since you copy and paste examples that intentionally omit any error checking logic for simplicity rather than try to understand the code you would have found the error immediately in your error reporting and again before even asking here.

    I may need to change my signature line to:

    There are 11 kinds of people in the world. Those that understand binary, those that don't and UniqueIdeaMan.
    Guoosey my dear, your signature would definitely make me laugh. Even if the cURL is copy & paste, it should work as the one who wrote the article did not leave anything out.
    Nevertheless, I got my answer from you. Something wrong with cURL. It's not fetching the page. Maybe encountering some page loading error like the error 404 and so and so I need to deal with that part.
    Saying all this, cheers for the haughty reply.

    EDIT: I have error reporting on and the gindergarten error reporting is giving no errors.
    The above code manages to fetch google homepage but it fails to fetch any other pages from other domains.
    Last edited by UniqueIdeaMan; May 4th, 2018 at 01:03 PM.
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,437
    Rep Power
    652
    There are 10 kinds of people in the world. Those that understand binary and those that don't.

IMN logo majestic logo threadwatch logo seochat tools logo