hello, im new to all of this i have php embeded in html and saved as index.php, in html part of it i want to connect to an external PHP script located in my friend's webspace i use the <script> tag both doesnt work. <script src="http://domain.com/filename.php"></script> and <script type="text/javascript" src="http://domain.com/filename.php"></script> i just want to simply output the result of that php script in the certain part of my site. my php scripts are working, but this part im having prob. with am i using the correct method?
You can not do anything as far as the code is concerned, because that would be a major security concern. Also, I suggest using <?php?> tags instead of the script tags. To just display the contents of that page you need to use something like this: <?php $thisFile = file_get_contents("http://domain.com/filename.php"); echo $thisFile; ?> //or <script type="text/php"> $thisFile = file_get_contents("http://domain.com/filename.php"); echo $thisFile; </script> PHP:
thanks the method above worked! i was able to connect to my friend's external php script. but i have new prob. when i try to connect to another external script provided by [hostip.info] ex. http://api.hostip.info/get_html.php when you try to visit the exact url it worked by giving the visitors location but when you try to use it with <?php $thisFile = file_get_contents("http://api.hostip.info/get_html.php"); echo $thisFile; ?> //or <script type="text/php"> $thisFile = file_get_contents("http://api.hostip.info/get_html.php"); echo $thisFile; </script> in the site it will just show Country: (Unknown Country?) (XX) City: (Unknown City?) any idea why?
That is because it's PHP getting the page, so hostip will find the information for whatever server the PHP is being run on. Not the user loading your site.
If you want to find you're visitors country/city, there are plenty of free ip to country scripts on the net!
your best using javascript <script type="text/javascript" src="http://api.hostip.info/get_html.php"></script> if that doesn't work, you need to look at the html source as your script is removing it or altering the code. if you had access the the country code you could change it to accept an ip address input, but including a remote file by url at run time is very slow in any case.
You need to be using it in the format. http://api.hostip.info/get_html.php?ip=12.215.42.19 PHP: Use the $_SERVER array to get their IP