2

I have this code on php document

<?php echo '<script type="text/javascript">
        document.write( geoip_city() );
      </script>' ?>

after open in browser it returns your city name but on

WebClient client = new WebClient();

            string client2 = client.DownloadString("http://www.mywebsite/ip2.php");

            MessageBox.Show(client2);

it returns the source code. Why does this happen?

I am using this script for geolocation.

durron597
  • 31,968
  • 17
  • 99
  • 158
Federal09
  • 639
  • 4
  • 9
  • 25
  • 1
    Perhaps your server is not setup to parse PHP? Try creating a single script that looks like this: " phpinfo(); ?>" and open it on your browser. If it shows a long list of information about your PHP setup, then this isn't the issue. If it just shows " phpinfo(); ?>" in the browser, then your web server isn't interpreting, and it'd be a web server configuration issue. – Nick Coons Jul 28 '13 at 17:54
  • You need to download the file from the live server. If it is hosted on the same computer, you need to use `client.DownloadString("127.0.0.1/mydocument/ip2.php");` Make sure you have PHP setup properly too. – Dave Chen Jul 28 '13 at 18:06
  • the file is on server with php and code work but in c# after download string return only source code – Federal09 Jul 28 '13 at 18:55
  • WebClient does not runs javascript code see: http://stackoverflow.com/questions/5372277/webclient-runs-javascript – cske Jul 29 '13 at 13:59
  • i have tested with webbrowser. webbrowser.navigate("http//www.mysite/ip2.php") string city = webbrowser.Documenttext.Tostring(); retunr always all source code same the webclient – Federal09 Jul 29 '13 at 22:19
  • try a simple script that returns hello world, see if it returns source code, if so, you web server may not be setup properly to handle php as mentioned above – Aaron Gong Sep 08 '13 at 17:08

1 Answers1

0

It sounds like you do not have PHP set up correctly on the server.

When you go to the page ( http://www.mywebsite/ip2.php ) does the source code show up there as well? What server software are you running?

Tim Groeneveld
  • 8,739
  • 3
  • 44
  • 60