How to Build an Ajax Proxy PHP

Ajax is used with web development to create different web applications for online servers. When an Internet user wants to download an Ajax application from your site, he accesses the server directly. This can be a problem if the user has malicious intent. You can resolve this problem by setting a proxy. This software will use Hypertext Preprocessor (PHP) to allow the user to access your website securely. You can create this proxy with just a few pieces of coding.

Instructions

    • 1

      Log into your server and click on the “Terminal” icon from the “Applications” folder.

    • 2

      Wait for a new Terminal window to appear.

    • 3

      Paste the following code into the Terminal window:

      <?
      ob_start();

      function logf($message) {
      $fd = fopen('proxy.log', "a");
      fwrite($fd, $message . "\n");
      fclose($fd);
      }

      ?>
      <?
      $url = $_REQUEST['url'];
      logf($url);
      $curl_handle = curl_init($url);
      curl_setopt($curl_handle, CURLOPT_HEADER, 0);
      curl_setopt($curl_handle, CURLOPT_FOLLOWLOCATION, 1);
      curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($curl_handle, CURLOPT_USERAGENT, "Owen's AJAX Proxy");

      $content = curl_exec($curl_handle);
      $content_type = curl_getinfo($curl_handle, CURLINFO_CONTENT_TYPE);
      curl_close($curl_handle);
      header("Content-Type: $content_type");
      echo $content;
      ob_flush();
      ?>

    • 4

      Press the “Enter” button to use the proxy.

    • 5

      Exit the Terminal window.

Related Searches:

References

Comments

Related Ads

Featured