0

Well the problem is simple I need the javascript to get content of remote webpage, because there is no way to do it directly I am doing it from local php file and ajax in the java script just like this

The php file:

    "getpage.php?url=http://stackoverflow.com"   '  

The php code :

<?php
$htm = file_get_contents($_GET['url']);
echo $htm; ?>

This code get content of the html page I direct him too.

The AJAX code :

function makeAJAXObject() { 
        var ajaxRequest;  

    try {
        // Opera 8.0+, Firefox, Safari
        ajaxRequest = new XMLHttpRequest();
    } catch (e) {
        // Internet Explorer Browsers
        try {
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
                // Something went wrong
                return false;
            }
        }
    }
    return ajaxRequest;
}

'

And I call him latter in my script like this :

window.ajax = makeAJAXObject(); window.ajax.open("GET","getpage.php"+ queryString, true);

The problem is than I do

alert(window.ajax.responseText);

instead giving me the content of the url I asked him too Its give me the actual php script that I wrote above.

This script works on localhost just fine, but I need it to work form local computer without reuploading to any server, there is away to do it ?

Edit :

The php file is on the pc, I am building a win 8 app , it's not like I have a url or something.

  • Make sure `AddType` directive is enabled for `php` on the remote server. Something like `AddType application/x-httpd-php .php` – raina77ow Jun 01 '13 at 10:50
  • can you post some of your php.ini file? – imulsion Jun 01 '13 at 10:55
  • There is no php.ini file I am trying to get the php runing wouth the javascript as localfile becouse its not on any server even not on localhost just a php file on your computer (win 8 dev). – Daniel Iliaguev Harta Jun 01 '13 at 11:14

1 Answers1

0

You need to check your remote server configuration to make sure that PHP file are processed by the server. Make sure mod_php is installed in apache and you have the proper AddType to process php files.

See this question: why are my php files showing as plain text?

Also, this is a HUGE security issue, you need to check what is requested and/or whitelist it.

What if I call

getpage.php?url=/etc/passwd
getpage.php?url=/your/secret/file

Because you don't do any checks, you would simply return the results to me ...

Community
  • 1
  • 1
Lepidosteus
  • 11,779
  • 4
  • 39
  • 51
  • It won't return anything, because its called from local computer , I build a win 8 app and the php file is on the pc and not on the server, this is the problem. – Daniel Iliaguev Harta Jun 01 '13 at 11:03