how to connect to external php script??

Discussion in 'PHP' started by Javver, Oct 8, 2007.

  1. #1
    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?
     
    Javver, Oct 8, 2007 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    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:
     
    jestep, Oct 8, 2007 IP
  3. Javver

    Javver Active Member

    Messages:
    72
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #3
    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?
     
    Javver, Oct 8, 2007 IP
  4. tamen

    tamen Peon

    Messages:
    182
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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.
     
    tamen, Oct 8, 2007 IP
  5. Javver

    Javver Active Member

    Messages:
    72
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #5
    hmmm this is sad, so i mean that i cant get that to work?
     
    Javver, Oct 8, 2007 IP
  6. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #6
    If you want to find you're visitors country/city, there are plenty of free ip to country scripts on the net!
     
    nabil_kadimi, Oct 8, 2007 IP
  7. ndreamer

    ndreamer Guest

    Messages:
    339
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #7
    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.
     
    ndreamer, Oct 9, 2007 IP
  8. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #8
    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 ;)
     
    Danltn, Oct 9, 2007 IP