Page 1 of 4 123 ... Last
  • Jump to page:
    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    232
    Rep Power
    1

    Smile cURL Experiments


    Ladies & Gentlemen!

    Oops! Let me try again:
    Gentle Ladies & Hard Men (after-all, it's the ladies who are gentle compared to men and men hard, rough & tough compared to the ladies)!
    And no, don't jest by saying "hard men" sounds like men having an erec**ion as some foolish men joked on other forums (busines/internet marketing) few months (or was it a yr back ?) back! :lol:
    Get used to me addressing you as "hard men" because that's how I'm gonna do it frequently. Lol!

    Anyway, this thread is about cURL.
    I will try building a unique script based on cURL. But, let's get rolling to learn first!
    I have some viral traffic & viral money earning ideas and cURL will impliment them. Stick around and see how deep the rabbit hole is and what comes out of it! (Not joking!).
    Last edited by UniqueIdeaMan; May 23rd, 2017 at 06:31 PM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    232
    Rep Power
    1
    cURL Sample 1:


    Why do you reckon the following code sample is not showing any page loading ? I see a complete blank page loading on my xampp.

    Code:
    <?php
    
    //This code was found on: http://www.binarytides.com/php-curl-tutorial-beginners/
    //gets the data from a URL
    function get_url($url) 
    {
        $ch = curl_init();
         
        if($ch === false)
        {
            die('Failed to create curl object');
        }
         
        $timeout = 5;
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        $data = curl_exec($ch);
        curl_close($ch);
        return $data;
    }
     
    echo get_url('http://www.apple.com/');
    ?>
    Last edited by UniqueIdeaMan; May 23rd, 2017 at 05:44 PM.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    232
    Rep Power
    1
    cURL Sample 2:

    Is it true that the following short code is just as good as the one mentioned on my previous post ?

    Code:
    <?php 
    
    //This code was found on: http://www.binarytides.com/php-curl-tutorial-beginners/
    //2nd Example
    //The above GET request to a url can be done in a much simpler way like this:
    
    //Make a HTTP GET request and print it (requires allow_url_fopen to be enabled)
    echo file_get_contents('http://www.apple.com/');
    
    ?>
    Last edited by UniqueIdeaMan; May 23rd, 2017 at 05:55 PM.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    232
    Rep Power
    1
    cURL Sample 3:

    Can you figure-out or atleast guess why the following code is better than the previous 2 ?
    What benefits do you see in it than the other 2 code samples ?
    No, I'm not testing you but trying to learn from you.

    Code:
    <?php 
    
    //3rd Option
    //This code was found on: http://www.binarytides.com/php-curl-tutorial-beginners/
    //Calling the curl_setopt function again and again to set the options is a bit tedious. There is a useful function called curl_setopt_array that takes an array of options and sets them all at once. Here is a quick example:
    //Make a HTTP GET request and print it (requires allow_url_fopen to be enabled)
    echo file_get_contents('http://www.apple.com/');
    curl_setopt_array($ch, array(
        CURLOPT_URL => $url ,
        CURLOPT_RETURNTRANSFER => 1,
        CURLOPT_CONNECTTIMEOUT => $timeout ,
    ));
    
    ?>
    And, what is meant by the following:
    "Calling the curl_setopt function again and again to set the options is a bit tedious. There is a useful function called curl_setopt_array that takes an array of options and sets them all at once.".
    Last edited by UniqueIdeaMan; May 23rd, 2017 at 06:21 PM.
  8. #5
  9. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,780
    Rep Power
    4536
    Why do you reckon the following code sample is not showing any page loading ?
    There's an error or $data is empty.
    Is it true ...
    Yes. You could of spent the 5 seconds to run the script and see that was the case.
    Can you ...
    No, there's no difference. "Better" is subjective. What characteristics are we comparing?
    And, what is meant by the following:
    "Calling the curl_setopt function again and again to set the options is a bit tedious. There is a useful function called curl_setopt_array that takes an array of options and sets them all at once.".
    It means that calling the curl_setopt function again and again can be a bit tedious as a programmer. Therefore you should use a useful function called curl_setopt_array that takes an array of options. This allows you to set the options all at once.

    -John

    Comments on this post

    • UniqueIdeaMan agrees : Suggestion agrees with a tutorial.
    -- Cigars, whiskey and wild, wild women. --
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    232
    Rep Power
    1
    Originally Posted by Sepodati
    There's an error or $data is empty.
    Mmm.

    Originally Posted by Sepodati
    Yes. You could of spent the 5 seconds to run the script and see that was the case.
    I did test both code blocks separately and they did redirect me to apple.com.
    I was just curious to learn why anyone would bother using the long version if the short version can do the same job.
    I got my answer from someone that the short version is risky. This is what I learnt:
    file_get_contents() using a URL is not guaranteed to work in all situations, as it depends on a configuration setting to allow it to use HTTP (which is sometimes disabled for security reasons).
    cURL, on the other hand, should normally work, as long as the PHP cURL extension is installed.



    Originally Posted by Sepodati
    No, there's no difference. "Better" is subjective. What characteristics are we comparing?
    I don't have anything specific in mind but how-about speed in performance ?

    Originally Posted by Sepodati
    It means that calling the curl_setopt function again and again can be a bit tedious as a programmer. Therefore you should use a useful function called curl_setopt_array that takes an array of options. This allows you to set the options all at once.
    -John
    Meaning writing the following for each and every url to fetch can be tedious. Right ?

    Code:
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    And so, best to url_setopt_array that takes an array of options and sets them all at once. Correct ?
    Last edited by UniqueIdeaMan; May 24th, 2017 at 04:16 PM.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    232
    Rep Power
    1
    Fellow Programmers,

    I did test both code blocks separately and they did redirect me to apple.com.

    Sample 1:


    Code:
        //gets the data from a URL
        function get_url($url) 
        {
            $ch = curl_init();
             
            if($ch === false)
            {
                die('Failed to create curl object');
            }
             
            $timeout = 5;
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
            $data = curl_exec($ch);
            curl_close($ch);
            return $data;
        }
         
        echo get_url('http://www.apple.com/');


    Sample 2:


    Code:
        // Make a HTTP GET request and print it (requires allow_url_fopen to be enabled)
        echo file_get_contents('http://www.apple.com/');

    I was just curious to learn why anyone would bother using the long version if the short version can do the same job.
    I got my answer from someone that the short version is risky. This is what I learnt:

    file_get_contents() using a URL is not guaranteed to work in all situations, as it depends on a configuration setting to allow it to use HTTP (which is sometimes disabled for security reasons).
    cURL, on the other hand, should normally work, as long as the PHP cURL extension is installed.



    I've also learnt now that, writing the following for each and every url to fetch can be tedious:

    Code:
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    And so, best to url_setopt_array that takes an array of options and sets them all at once. Like one programmer's contributed code sample below:

    Code:
    <?php
    function get_url($url) 
    {
        $ch = curl_init();
        if($ch === false)
        {
            die('Failed to create curl object');
        }
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
        $data = curl_exec($ch);
        curl_close($ch);
        return $data;
    }
    // get_url2 is the same as get_url except curl options are contained in an
    // array and set using curl_setopt_array
    function get_url2($url) 
    {
        $ch = curl_init();
        if($ch === false)
        {
            die('Failed to create curl object');
        }
        $curlOptions = array(CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => 1,
                             CURLOPT_CONNECTTIMEOUT => 5);
        curl_setopt_array($ch, $curlOptions);
        $data = curl_exec($ch);
        curl_close($ch);
        return $data;
    }
    // Call get_url or get_url2, but not both.  Comment and uncomment as needed to experiment.
    // Change $myUrl variable for different websites, see what comes back as a blank page. Note that
    // there is no guarantee that you'll always get the same blank and non-blank pages as I do or
    // the same results every time.  Lots of factors.
    $myUrl = 'http://www.google.com'; // non-blank, but incomplete page (no Google logo)
    //$myUrl = 'http://www.daniweb.com'; // blank page
    //$myUrl = 'http://www.apple.com'; // blank page
    // echo get_url($myUrl);
    echo get_url2($myUrl);
    ?>
    Thanks for everyone's inputs in this forum and others.
    I hope I remember them all!!! Don't blame me if I don't! Lol!
    Last edited by UniqueIdeaMan; May 24th, 2017 at 04:36 PM.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    232
    Rep Power
    1

    Question


    SedoPati,

    This is what I learnt tonight at another place:
    When you connect to the site, if it gives you a 301 header which is an indicator that the real address is something else. In this case:
    Electronics, Cars, Fashion, Collectibles, Coupons and More | eBay
    when you see error at:
    http://ebay.com


    Ok. I can see an improvement with their suggested code. Check it out yourself. Although, all that header stuff echoed at the top of the screen looks unclean. Doesn't it ?

    Code:
    <?php
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://ebay.com");
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($ch, CURLOPT_HEADER, 5);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    $result = curl_exec($ch);
    curl_close($ch);
    $result = preg_replace("#(<\s*a\s+[^>]*href\s*=\s*[\"'])(?!http)([^\"'>]+)([\"'>]+)#",'$1http://mydomain.com/$2$3', $result);
    echo $result
    ?>
    This is how I tested things. I wrote/copied cURL code from
    Php curl tutorial
    onto Note Pad++ and then viewed the file in the browser by calling the page html via cURL where Chrome opened the page via cURL (eg. google.com). That was in one tab. Hovering my mouse on some links I found they pointed to my localhost. And some I found pointed to google pages.
    I then opened another tab on Chrome and directly visited the page (in our case: eg. google.com). I then checked view source out of curiosity on that tab and found the links that pointed to my localhost were actually relative links while the others were absolute. That's how I figured-out the problem. Then, googled for php code samples to convert rel links to abs links. Found a few codes samples but they all had a litle flaws. I thought the simple preg_replace would be catch & miss and so stuck to the regex preg_replace lastnight.
    Tonight, however, I'm experiencing a new problem.
    The following was the oroginal code, from lastnight, that came from the tutorial mentioned on my first 4 posts at the top:

    Code:
        <?php
        
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "http://google.com");
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
        curl_setopt($ch, CURLOPT_HEADER, 5);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        $result = curl_exec($ch);
        curl_close($ch);
        
        ?>
    Then I added the following on line 10 & 11:

    Code:
        $result = preg_replace("#(<\s*a\s+[^>]*href\s*=\s*[\"'])(?!http)([^\"'>]+)([\"'>]+)#",'$1http://$url/$2$3', $result);
        echo $result
    And tonight, I see problems. To experience it yourself, Run the above code in your xampp/wamp.
    Notice the 4 links below the google buttons. Their links are shown like so:

    301 Moved
    301 Moved
    301 Moved

    Can you spot the extra "/" ? I believe the regex didn't do it's job properly.
    Anyway, tonight, I added the following on line 2:

    Code:
        $url = http://google.com
    And replaced 'google.com':
    Code:
        $result = preg_replace("#(<\s*a\s+[^>]*href\s*=\s*[\"'])(?!http)([^\"'>]+)([\"'>]+)#",'$1http://google,com/$2$3', $result);
    to $url:
    Code:
        $result = preg_replace("#(<\s*a\s+[^>]*href\s*=\s*[\"'])(?!http)([^\"'>]+)([\"'>]+)#",'$1http://$url/$2$3', $result);
    And now face a new problem.
    The links now show-up like this:

    http://%24url//intl/en/ads/
    http://%24url//services/

    Where the hell does the **"%24url"** come from ?

    I even changed the single quotes ('$url') to double quotes ("$url") but same result!

    Final Code that encountered above mentioned problem:
    Code:
    <?php
    $url = "http://google.com";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "$url");
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($ch, CURLOPT_HEADER, 5);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    $result = curl_exec($ch);
    curl_close($ch);
    $result = preg_replace("#(<\s*a\s+[^>]*href\s*=\s*[\"'])(?!http)([^\"'>]+)([\"'>]+)#",'$1http://$url/$2$3', $result);
    echo $result
    ?>
    Last edited by UniqueIdeaMan; May 25th, 2017 at 06:34 PM.
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    232
    Rep Power
    1

    Question


    Folks,

    I'm afraid the following preg_replace is not doing the job. Can you think of a better one ?
    Actually, if you can come-up with one that does the following then I'd appreciate it:

    1. Replace 'https://' with: 'http://mydomain.com'.
    2. Replace 'http://' with: 'http://mydomain.com'.
    3. Replace 'www.' with: 'http://mydomain.com'.
    4. Replace all subdomains and sub sub domains etc. with: 'http://mydomain.com'.
    eg1. Replace 'mail.domain.com' with 'http://mydomain.com'.
    eg2. Replace 'ny.mail.domain.com' with 'http://mydomain.com'.
    eg3. Replace 'europe.spain.mail.domain.com' with 'http://mydomain.com'.
    eg4. Replace 'west.europe.deutchland.mail.domain.com' with 'http://mydomain.com'.
    And so on. You get the picture.

    I tried the following code but it's not working. Instead of replacing things with 'http://mydomain.com' it is replacing with: '%24url//'. And that is a big No! No!

    PHP Code:

    <?php
    $url 
    "http://google.com";
    $ch curl_init();
    curl_setopt($chCURLOPT_URL"$url");
    curl_setopt($chCURLOPT_FOLLOWLOCATIONTRUE);
    curl_setopt($chCURLOPT_HEADER5);
    curl_setopt($chCURLOPT_RETURNTRANSFERTRUE);
    $result curl_exec($ch);
    curl_close($ch);
    $result preg_replace("#(<\s*a\s+[^>]*href\s*=\s*[\"'])(?!http)([^\"'>]+)([\"'>]+)#",'$1http://$url/$2$3'$result);
    echo 
    $result
    ?>
    Cheers!
    Last edited by UniqueIdeaMan; July 1st, 2017 at 09:17 AM.
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    232
    Rep Power
    1
    This code sort of does the job:

    PHP Code:

    <?php
    $url 
    "http://www.ebay.com";
    $ch curl_init();
    curl_setopt($chCURLOPT_URL"$url");
    curl_setopt($chCURLOPT_FOLLOWLOCATIONTRUE);
    curl_setopt($chCURLOPT_HEADER5);
    curl_setopt($chCURLOPT_RETURNTRANSFERTRUE);
    $result curl_exec($ch);
    curl_close($ch);
    $phrase  "$result";
    $pattern = array("localhost","https://""http://""www.");
    $replace   = array("http://mymydomain.com/tracker.php?""http://mymydomain.com/tracker.php?""http://mymydomain.com/tracker.php?""http://mymydomain.com/tracker.php?");
    $newphrase str_replace($pattern$replace$phrase);
    echo 
    $newphrase;
    ?>
    Last edited by UniqueIdeaMan; July 1st, 2017 at 09:18 AM.
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    232
    Rep Power
    1
    Php Buddies,

    Have a look at the following script and tell me what do you think ?

    PHP Code:

    <?php


    if(isset($_GET["url_to_proxify"]) === TRUE)
       {
        
    $url_to_proxify trim(mysqli_real_escape_string($conn,$_GET["url_to_proxify"]));
        echo 
    "Url to proxify = $url_to_proxify";
       }
    ?>

    <html>
       <body>   
          <form action = "<?php $_PHP_SELF ?>" method = "GET">
             Url: <input type = "text" name = "url_to_proxify" />
                  <input type = "submit" />
          </form>      
       </body>
    </html>

    <?php
    $url 
    $url_to_proxify;
    $ch curl_init();
    curl_setopt($chCURLOPT_URL"$url");
    curl_setopt($chCURLOPT_FOLLOWLOCATIONTRUE);
    curl_setopt($chCURLOPT_HEADER5);
    curl_setopt($chCURLOPT_RETURNTRANSFERTRUE);
    $result curl_exec($ch);
    curl_close($ch);

    $phrase  "$result";
    //Below change 'localhost' to "./".
    //eg: $pattern = array("./", "https://www.", "http://www.", "https://", "http://", "www.");
    $pattern = array("localhost""https://www.""http://www.""https://""http://""www.");
    $replace   = array("proxified_page.php?url_to_proxify=""proxified_page.php?url_to_proxify=""proxified_page.php?url_to_proxify=""proxified_page.php?url_to_proxify=""proxified_page.php?url_to_proxify=""proxified_page.php?url_to_proxify=");

    $newphrase str_replace($pattern$replace$phrase);

    echo 
    $newphrase;

    ?>
    It is a mini proxy that I am building with cURL.
    First of all, you will see a small html text box. In it you type the url you want the script to fetch. Type "ebay.com" and then click the "submit" button. You will see the script fetches ebay.com.
    Now, hover your mouse over any link and check what the browser shows the link to be.
    Hover it on "fashion" link. The original link is this:

    http://www.ebay.com/global/fashion

    I coded so that the following always gets preceded onto any link so that my tracker can track the link clicks:

    http://mymydomain.com/proxified_page...rl_to_proxify=

    And so, in this case, when you click the "Fashion" link, you should be taken to:

    http://mymydomain.com/proxified_page...global/fashion

    But instead, you are taken to:

    http://mymydomain.com/proxified_page...p/fashion-main

    Why is the script adding "rrp/" on every link ? I did not code it to do so. Check it out. It is a great mystery! Been trying to figure this out for 2 nights now but no luck. Hover your mouse over any link that is present on ebay.com that the script fetched and you will see they all contain "rrp/"!!!! Why is that ? Strange!!!
    Last edited by UniqueIdeaMan; July 1st, 2017 at 09:19 AM.
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    232
    Rep Power
    1
    Php Colleagues,

    I will tell you what I am upto. I am trying to have a web proxy track link clicks. That is the project.
    I grabbed MiniProxy and added my own code so that every proxified link clicks get tracked by my tracker. It worked but it started logging not only the proxified page that loaded on the user's screen but every link present on the page. That was a problem. For example, if the user is on ebay's homepage then I expect the homepage url to be logged onto my mysql db tbl and not all the links (inc img links) present on the homepage. Came across this dead-end and for the time being quit trying to add a tracker on a third party script as trying to figure-out which line of the code does what was becoming a nightmare.
    I thought I might aswell build my own basic web proxy and add the tracker on it. That way, if I encounter any problems then I'll know which part of the code is malfunctioning.

    Now look how far I got to ...

    I started off my coding with cURL. I got cURL to fetch ebay.com and precede a url from my own domain on all links present on the page. In this example: mymydomain.com/proxified_page.php?url_to_proxify=

    So, if ebay.com has these 2 links, for example:

    http://ebay.com/contactus.html
    http://ebay.com/item_image.jpeg

    then the cURL fetched ebay homepage (eg. proxified page) would list the links like so:

    mymydomain.com/proxified_page.php?url_to_proxify=http://ebay.com/contactus.html
    mymydomain.com/proxified_page.php?url_to_proxify=http://ebay.com/item_image.jpeg

    That way, all the links present on the proxified page (cURL fetched page) would be links pointing to my domain or page that lists the cURL webpage fetching code. In other words, the links present would be proxified links. Later-on, I can add my tracker links too so all proxified page gets logged and tracked. Like so:

    mymydomain.com/tracker/proxified_page.php?url_to_proxify=

    In short, the whole script can be one page script. The same page would use cURL to fetch the page (ebay.com) and that same one page script would have the tracker/logger code at the top of the script. Wallah! I added a tracker to the basic proxy.
    One experienced programmer (in another forum or maybe this one) said to me that, I cannot add my own tracker on proxified pages. In other words, I can put a link to a 3rd party site from my site and add a tracker so that I can track the click to the 3rd party domain page but once the visitor is on the 3rd party page or 3rd party domain then whatever links he finds and clicks on the 3rd party domain, I won't be able to track. Technically, impossible. That was his claim. I argued, I would be able to track my visitor on 3rd party pages (page after page) because all pages would be proxified. And so, technically "Mission Possible". He betted all his money currently then in his bank account. Offered me even his last few digits of his card, even though I told him I have already managed to add a tracking code onto MiniProxy. Shot himself in the foot. He did. Now, he's not replying to me nor responding to my threads. He used to regularly. I guess he got spooked that, I'd win the bet and make claim to his money. I wasn't really gonna do that. Instead, I was gonna ask him to help me out on where I get stick by building me a script with comments all over so I can learn from it and other newbies too as I was gonna release it as gpl. Anyway, we lost a good contributor. I hope he returns. He was a good contributor to my threads. One lesson to be learnt though is that: Never, ever make a bet. Especially, when someone says he has already managed to do what you say can't be done.
    I will disclose that MiniProxy script here one day after I have got rid of the hiccup on my tracker code. It is roaming in some other forum at the moment. Wait till it's finished with the help of others. Some other programmers at other forums said the same thing as the betting person. That, I cannot track visitors on 3rd party sites but I have proved every experienced programmer wrong, who were on the other side. I, a newbie, amateur. Not bragging.

    And so, here's the code so far of my own basic web proxy with cURL. This is not the code where I added my tracker onto MiniProxy (3rd party web proxy script). This is my own web proxy to be. It is cURL experiment so far:

    PHP Code:

    <?php

    $conn 
    mysqli_connect("localhost""root""""id");

    if (!
    $conn) {
        
    // message to use in development to see errors
        
    die("Database error : " mysqli_error($conn));

        
    // user friendly message
        // die("Database error.");
        
    exit();
    }

    if(isset(
    $_GET["url_to_proxify"]) === TRUE)
       {
        
    $url_to_proxify trim(mysqli_real_escape_string($conn,$_GET["url_to_proxify"]));
        echo 
    "Url to proxify = $url_to_proxify";
       }
    ?>

    <html>
       <body>   
          <form action = "<?php $_PHP_SELF ?>" method = "GET">
             Url: <input type = "text" name = "url_to_proxify" />
                  <input type = "submit" />
          </form>      
       </body>
    </html>

    <?php
    $url 
    $url_to_proxify;
    $ch curl_init();
    curl_setopt($chCURLOPT_URL"$url");
    curl_setopt($chCURLOPT_FOLLOWLOCATIONTRUE);
    curl_setopt($chCURLOPT_HEADER5);
    curl_setopt($chCURLOPT_RETURNTRANSFERTRUE);
    $result curl_exec($ch);
    curl_close($ch);

    $phrase  "$result";
    //Below change 'localhost' to "./".
    //eg: $pattern = array("./", "https://www.", "http://www.", "https://", "http://", "www.");
    $pattern = array("localhost""https://www.""http://www.""https://""http://""www.");
    $replace   = array("proxified_page.php?url_to_proxify=""proxified_page.php?url_to_proxify=""proxified_page.php?url_to_proxify=""proxified_page.php?url_to_proxify=""proxified_page.php?url_to_proxify=""proxified_page.php?url_to_proxify=");

    $newphrase str_replace($pattern$replace$phrase);

    echo 
    $newphrase;

    ?>
    Note that, the script is no longer tied to ebay.com. I added a text box so you can type any url and the cURL would fetch that page and precede my domain links onto the links residing on the fetched page. Turn all links present onto proxified links. Test it and see. On some links the:

    mymydomain.com/proxified_page.php?url_to_proxify=

    does not get preceded.

    Q1. Can you guess why that is ?

    Anyway, use that script and fetch google homepage and then do a search on google. It won't work. The google search result page (SERP) won't be proxified. Google would show a dead link. In other words, my coding has failed to precede my domain's url onto the links present on the proxified google page.
    I don't know how to solve this issue with cURL and so:

    2. Do you know how to solve it ? Any code samples most welcome.

    Anyway, this is a tutorial video on php (not cURL) that solves this issue. But, it does not precede my domain's url onto all links present on the proxified page.

    https://www.youtube.com/watch?v=P49w0E64MAA

    PHP Code:

    <?php

    //Below code from Basic Php Proxy Video and fix from: https://stackoverflow.com/questions/22255241/preg-replace-no-ending-matching-delimiter-gt/22255455#22255455

    $url "http://www.google.com";
    $page file($url);

    foreach(
    $page as $part)
    {
        
    $part preg_replace('/src="/''src="'.$url,$part);
    $part preg_replace('/action="/''action="'.$url,$part);

    echo 
    $part;

    }

    ?>
    So, as you can see. I got 2 sets of code.
    The 1st one is cURL that fetches your chosen page and proxifies it. It proxifies all the links present on the proxified page. But, if you conduct a search on the proxified page (in our example make a search on proxified google homepage) then you see error as it fails to proxify google SERPs.
    The 2nd script manages to search google and show google results without showing any error. But, it does not precede my domain url to the links present on the proxified page. That means, I cannot proxify the links present on the proxified page. Nor can I add my tracker onto these links.
    To sort this issue out, I tried mixing & matching both scripts. And this is the best I came-up with and it is no good. Any chance you guys can do better ?

    FIRST ATTEMPT (with cURL & Preg_Replace):

    PHP Code:

    <?php

    $conn 
    mysqli_connect("localhost""root""""id");

    if (!
    $conn) {
        
    // message to use in development to see errors
        
    die("Database error : " mysqli_error($conn));

        
    // user friendly message
        // die("Database error.");
        
    exit();
    }

    if(isset(
    $_GET["url_to_proxify"]) === TRUE)
       {
        
    $url_to_proxify trim(mysqli_real_escape_string($conn,$_GET["url_to_proxify"]));
        echo 
    "Url to proxify = $url_to_proxify";
       }
    ?>

    <html>
       <body>   
          <form action = "<?php $_PHP_SELF ?>" method = "GET">
             Url: <input type = "text" name = "url_to_proxify" />
                  <input type = "submit" />
          </form>      
       </body>
    </html>

    <?php
    $url 
    $url_to_proxify;
    $ch curl_init();
    curl_setopt($chCURLOPT_URL"$url");
    curl_setopt($chCURLOPT_FOLLOWLOCATIONTRUE);
    curl_setopt($chCURLOPT_HEADER5);
    curl_setopt($chCURLOPT_RETURNTRANSFERTRUE);
    $result curl_exec($ch);
    curl_close($ch);

    $phrase  "$result";
    //Below change 'localhost' to "./".
    //eg: $pattern = array("./", "https://www.", "http://www.", "https://", "http://", "www.");
    $pattern = array("localhost""https://www.""http://www.""https://""http://""www.");
    $replace   = array("proxified_page_2.php?url_to_proxify=""proxified_page_2.php?url_to_proxify=""proxified_page_2.php?url_to_proxify=""proxified_page_2.php?url_to_proxify=""proxified_page_2.php?url_to_proxify=""proxified_page_2.php?url_to_proxify=");

    $new_phrase str_replace($pattern$replace$phrase);


    //Below code from Basic Php Proxy Video and fix from: https://stackoverflow.com/questions/22255241/preg-replace-no-ending-matching-delimiter-gt/22255455#22255455

    foreach($page as $new_phrase)
    {
        
    //eg: $pattern = array("localhost", "./", "https://", "http://");


    $phrase preg_replace('/src="/''src="'.$url_to_proxify$new_phrase);
    $phrase preg_replace('/action="/''action="'.proxy.php?url_to_proxify=$url_to_proxify$new_phrase);

    echo 
    $phrase;

    ?>
    I get this error:


    **Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\id\proxy.php on line 32**


    SECOND ATTEMPT with php $page = file and Preg_Replace

    PHP Code:

    <?php

    $conn 
    mysqli_connect("localhost""root""""id");

    if(isset(
    $_GET["url_to_proxify"]) === TRUE)
       {
        
    $url_to_proxify trim(mysqli_real_escape_string($conn,$_GET["url_to_proxify"]));
        echo 
    "Url to proxify = $url_to_proxify";
       }
    ?>

    <html>
       <body>   
          <form action = "<?php $_PHP_SELF ?>" method = "GET">
             Url: <input type = "text" name = "url_to_proxify" />
                  <input type = "submit" />
          </form>      
       </body>
    </html>

    <?php

    $page 
    file($url_to_proxify);

    foreach(
    $page as $phrase)
    {
        
    //eg: $pattern = array("localhost", "./", "https://", "http://");


    $phrase preg_replace('/src="/''src="'.$url_to_proxify$phrase);
    $phrase preg_replace('/action="/''action="'.proxy.php?url_to_proxify=$url_to_proxify$phrase);

    echo 
    $phrase;

    }

    ?>
    I get same error as before:

    **Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\id\proxified_page_2.php on line 58**

    If I can get a proper reply to my post numbered 18 on the following thread then I guess I can make the final 2 codes (mentioned above) work.
    https://www.sitepoint.com/community/...blem/264750/16

    Q3. What do you think ?

    Anyway, I will try another 2 attempts with the following when I get the time:

    cURL & str_replace
    Php with php $page = file and str_replace

    You are welcome to demonstrate any code samples.


    Thank You!
    Last edited by UniqueIdeaMan; July 1st, 2017 at 09:21 AM.
  24. #13
  25. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,780
    Rep Power
    4536
    You sure pat yourself on the back a lot at the beginning of that post for someone who can't figure out a syntax error.

    PHP Code:
    $phrase preg_replace('/action="/''action="'.proxy.php?url_to_proxify=$url_to_proxify$phrase); 
    Last edited by Sepodati; June 29th, 2017 at 09:00 AM.
    -- Cigars, whiskey and wild, wild women. --
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    232
    Rep Power
    1
    I don't understand what you mean.
    Anyway, a programmer at another forum helped me out on this and so I changed it to:

    PHP Code:
    $phrase preg_replace('/action="/''action="proxy.php?url_to_proxify=' .$url_to_proxify$phrase); 
    From:

    PHP Code:
    $phrase preg_replace('/action="/''action="'.proxy.php?url_to_proxify=$url_to_proxify$phrase); 

    However, I faced other error problems (not due to his code suggestion but due to my own mistakes such as not defining variable etc.) and so re-arranged the code and the errors are gone.
    But a new problem. The code does not trigger after I click the "submit" button.
    Strange.

    PHP Code:

    <html>
        <body>   
            <form action = "<?php $_PHP_SELF ?>" method = "GET">
            Url:<input type = "text" name = "url_to_proxify" />
                <input type = "submit" />
            </form>      
        </body>
    </html>
            
    <?php

    $conn 
    mysqli_connect("localhost""root""""id");

    if (
    $_SERVER['REQUEST_METHOD'] == "POST")
       {
            
    $url_to_proxify trim(mysqli_real_escape_string($conn,$_GET["url_to_proxify"]));
            
    //WHY IS NOT THE FOLLOWING BEING ECHOED ?
            
    echo $url_to_proxify;
            
            
    //WHY IS NOT THE FOLLOWING CODE GETTING TRIGGERED AFTER SUBMIT BUTTON HAS BEEN CLICKED ?
            
    $page file($url_to_proxify);

            foreach(
    $page as $phrase)
            {    
                
    //eg: $pattern = array("localhost", "./", "https://", "http://");
                
    $phrase preg_replace('/src="/''src="'.$url_to_proxify$phrase);
                
    $phrase preg_replace('/action="/''action="proxy.php?url_to_proxify=' .$url_to_proxify$phrase);
                echo 
    $phrase;
            }        
        }
    else
        {
        }

    ?>
    Neither this rearrangement works:

    PHP Code:

    <?php

    $conn 
    mysqli_connect("localhost""root""""id");

    ?>    

    <html>
        <body>   
            <form action = "<?php $_PHP_SELF ?>" method = "GET">
            Url:<input type = "text" name = "url_to_proxify" />
                <input type = "submit" />
            </form>      
        </body>
    </html>

    <?php

    if ($_SERVER['REQUEST_METHOD'] == "POST")
       {
            
    $url_to_proxify trim(mysqli_real_escape_string($conn,$_GET["url_to_proxify"]));
            
    //WHY IS NOT THE FOLLOWING BEING ECHOED ?
            
    echo $url_to_proxify;
            
            
    //WHY IS NOT THE FOLLOWING CODE GETTING TRIGGERED AFTER SUBMIT BUTTON HAS BEEN CLICKED ?
            
    $page file($url_to_proxify);

            foreach(
    $page as $phrase)
            {    
                
    //eg: $pattern = array("localhost", "./", "https://", "http://");
                
    $phrase preg_replace('/src="/''src="'.$url_to_proxify$phrase);
                
    $phrase preg_replace('/action="/''action="proxy.php?url_to_proxify=' .$url_to_proxify$phrase);
                echo 
    $phrase;
            }        
        }
    else
        {
        }

    ?>

    Finally tried with this arrangement but no luck either. No pages get proxified. Clicking "submit" button gives no response!

    PHP Code:

    <?php

    $conn 
    mysqli_connect("localhost""root""""id");

    if (
    $_SERVER['REQUEST_METHOD'] == "POST")
       {
            
    $url_to_proxify trim(mysqli_real_escape_string($conn,$_GET["url_to_proxify"]));
            
    //WHY IS NOT THE FOLLOWING BEING ECHOED ?
            
    echo $url_to_proxify;
            
    ?>    

    <?php
            
    //WHY IS NOT THE FOLLOWING CODE GETTING TRIGGERED AFTER SUBMIT BUTTON HAS BEEN CLICKED ?
            
    $page file($url_to_proxify);
            foreach(
    $page as $phrase)
        {    
            
    //eg: $pattern = array("localhost", "./", "https://", "http://");
            
    $phrase preg_replace('/src="/''src="'.$url_to_proxify$phrase);
            
    $phrase preg_replace('/action="/''action="proxy.php?url_to_proxify=' .$url_to_proxify$phrase);
            echo 
    $phrase;
        }        
    }
    else
        {
        }
    ?>

    <html>
       <body>   
          <form action = "<?php $_PHP_SELF ?>" method = "GET">
             Url: <input type = "text" name = "url_to_proxify" />
                  <input type = "submit" />
          </form>      
       </body>
    </html>
    Today's problem really started as soon as I changed the 3rd line of the code (regarding the 'submit' button) to the following:

    PHP Code:

    if ($_SERVER['REQUEST_METHOD'] == "POST")

    [/
    code]

    from
    if(isset($_GET["url_to_proxify"]) === TRUE)

    [/php]
    Last edited by UniqueIdeaMan; July 9th, 2017 at 05:16 PM.
  28. #15
  29. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,780
    Rep Power
    4536
    Jesus Christ, dude. You have no ****ing clue what you are doing and just stabbing your **** around hoping to hit something. You're submitting your form using GET and then looking for POST. Do you even have an idea what those words mean? What's the difference between them?

    The first ****ing thing you do is realize your IF condition is failing if you don't see an echo result, so a normal person would take a look in $_SERVER to see what's going on. Well, a normal person would understand the basics by this point and know what POST and GET mean.

    I know you're trying to learn, man, but you keep coming in here with syntax errors. You have no understanding of the basics.
    -- Cigars, whiskey and wild, wild women. --
Page 1 of 4 123 ... Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo