PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Thu Nov 23, 2017 6:06 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Mon Sep 18, 2017 6:21 pm 
Offline
Forum Contributor

Joined: Wed Jan 18, 2017 4:43 pm
Posts: 177
Php Folks!

I am trying to do the following with cURL:

* Keyword Search on Google.

So, basically, when you do a keyword search on google, then cURL is supposed to fetch the google search result page (SERP) showing you the search results on a proxied page (cURL fetched page). But, cURL is showing an invalid google SERP. Why is that ?
Can you spot any errors in my code ?

Syntax: [ Download ] [ Hide ]

<?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($ch, CURLOPT_URL, "$url_to_proxify");
                curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
                curl_setopt($ch, CURLOPT_HEADER, 5);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
                $curl_result = curl_exec($ch);         
                $domain = parse_url($url_to_proxify, PHP_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("proxified_page_test.php?url_to_proxify=http://\".$domain\"", "proxified_page_test.php?url_to_proxify=https://\".$domain\"", "proxified_page_test.php?url_to_proxify=http://www.\".$domain\"", "proxified_page_test.php?url_to_proxify=https://www.\".$domain\"", "proxified_page_test.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)              
                $pattern = array('src="', 'src = "', 'src= "', 'src ="', "src='", "src = '", "src= '", "src='");
                $replace = array('src="proxified_page_test.php?url_to_proxify=\".$domain\""', 'src = "proxified_page_test.php?url_to_proxify=\".$domain\""', 'src= "proxified_page_test.php?url_to_proxify=\".$domain\""', 'src ="proxified_page_test.php?url_to_proxify=\".$domain\""', "src='proxified_page_test.php?url_to_proxify=\".$domain\"'", "src = 'proxified_page_test.php?url_to_proxify=\".$domain\"'", "src= 'proxified_page_test.php?url_to_proxify=\".$domain\"'", "src ='proxified_page_test.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="proxified_page_test.php?url_to_proxify=\".$domain\""', 'action = "proxified_page_test.php?url_to_proxify=\".$domain\""', 'action= "proxified_page_test.php?url_to_proxify=\".$domain\""', 'action ="proxified_page_test.php?url_to_proxify=\".$domain\""', "action='proxified_page_test.php?url_to_proxify=\".$domain\"'", "action = 'proxified_page_test.php?url_to_proxify=\".$domain\"'", "action= 'proxified_page_test.php?url_to_proxify=\".$domain\"'", "action ='proxified_page_test.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
        }
?>
 


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Bing [Bot] and 19 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group