0

So I'm trying to load a page with a URL as a GET variable. Unfortunately, I keep getting a 404 from apache. Using JQuery, my syntax for the request is the following:

$.ajax({
    type: "GET",
    url: "page.php&url="+theURL,
    dataType: "xml",
    success: function(xml){
        loadFeed(xml);
    }
});

and the php for page.php is as follows:

<?php

domain="localhost";

header('Content-type: application/xml');

referer=$_SERVER['HTTP_REFERER'];

if(!stripos($referer, $domain)){
    print("BAD REQUEST");
    return;
}

$handle = fopen($_GET['url'], "r");
if ($handle) {
    while (!feof($handle)) {
        $buffer = fgets($handle, 4096);
        echo $buffer;
    }
    fclose($handle);
}
?>

Not sure what i'm doing wrong here.

display-name-is-missing
  • 4,424
  • 5
  • 28
  • 41
JaySee
  • 351
  • 3
  • 14
  • 2
    Your javascript can't find your PHP file, hence the 404 error. – Charlie Feb 07 '14 at 00:48
  • 3
    Your PHP file is missing some $ on variables. It probably doesn't even compile. – developerwjk Feb 07 '14 at 00:50
  • Apart from @Ibu's answer, you probabaly also need to encode the url in javascript: http://stackoverflow.com/questions/332872/how-to-encode-a-url-in-javascript – jeroen Feb 07 '14 at 00:51

1 Answers1

3

YOu have an error in your url:

$.ajax({
    type: "GET",
    url: "page.php&url="+theURL,  // Here
    dataType: "xml",
    success: function(xml){
        loadFeed(xml);
    }
});

should be:

$.ajax({
    ...
    url: "page.php?url="+theURL,  // Here
    ...
});

Note I used a question mark instead of ampersand. Also this might be a typo but you are missing the $ in front of variables

Ibu
  • 42,752
  • 13
  • 76
  • 103