0

Here is my project. I'm trying to load a website's content onto mine. I do not have access to the website's files that I am trying to retrieve. I'm trying to bypass CORS with some PHP proxies but the problem is that the website has a Basic Authentication Box that pops up upon visiting it, and I believe that is preventing me from loading the website correctly. I do have the login information, however, I'm not sure if I'm inputting it correctly into the CORS proxy. Here are a few of the things that I have tried.

proxy.php

<?php
    header("Access-Control-Allow-Origin: *");

    echo get_page($_GET['url']);
    //echo get_page("http://www.google.com");
    function get_page($url){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,$url);
        /*
        $proxy = 'http://proxy.company.com:8080';
        $proxyauth = 'domain\proxy_username:proxy_password';
        curl_setopt($ch, CURLOPT_PROXY, $proxy);
        curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
        */
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        $data = curl_exec($ch);
        curl_close($ch);
        return $data;
    }
?>

index.html

 <!DOCTYPE html>
<html>

<head>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

    <script>
        $(document).ready(function(){
            $( "#result" ).load( "http://mywebsite.com/proxy.php?url=https://externalwebsite.com/index.php" );
        });
        </script>

</head>

<body>

    <h1> Test Page Index </h1>

    <div id="result"></div>

</body>

</html>

Upon loading that into my div element, I get a blank page. I've tried adding the following so that it gets past the basic authentication:

$username = myusername;
$password = mypassword;
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");

Even after adding that, I get a blank page. I know the PHP works because I am able to load google with the following:

 <!DOCTYPE html>
<html>

<head>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

    <script>
        $(document).ready(function(){
            $( "#result" ).load( "http://mywebsite.com/proxy.php?url=http://google.com" );
        });
        </script>

</head>

<body>

    <h1> Test Page Index </h1>

    <div id="result"></div>

</body>

</html>
chunterb
  • 301
  • 2
  • 11
  • It is still a bit confusing, you should try to split the question into smaller ones that define clearly what you are trying to achieve, what you have tried so far, and where it fails. – Raul Sauco Mar 17 '18 at 00:58
  • I revised the post completely. Please let me know if it is understandable now. Thanks for the tip. @RaulSauco – chunterb Mar 17 '18 at 19:55

0 Answers0