1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Include external file PHP

Discussion in 'PHP' started by jakomo, Jan 7, 2008.

  1. #1
    Hello friends!

    Maybe someone can help me :)

    I've hosting A and hosting B.. , I'm trying to include in hosting A a remote file of of hosting B but really I cannot, I have tried include ("http://url.com/file.php), but as I read this is not possible, also I have treid with fopen but the file in B have <? ?> and values, and I need to read the values of B in A.

    Anyone here know how to do it? :)

    Best and thanks for the time,
    Jakomo
     
    jakomo, Jan 7, 2008 IP
  2. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #2
    you can write a seperate php program which outputs the values of file.php from site B and then fopen read those content to your current php file

    Regards

    Alex
     
    kmap, Jan 7, 2008 IP
  3. jakomo

    jakomo Well-Known Member

    Messages:
    4,262
    Likes Received:
    82
    Best Answers:
    0
    Trophy Points:
    138
    #3
    Hello,
    This is a good idea, but I need to get get connection values, I dont like to get the connection values (password, hosting, username) in the server A.

    Thanks,
    Jakomo
     
    jakomo, Jan 7, 2008 IP
  4. legend2

    legend2 Well-Known Member

    Messages:
    1,537
    Likes Received:
    74
    Best Answers:
    0
    Trophy Points:
    115
    #4
    It's a very bad idea.
    Including an external php file means that file will not be processed by the server and thus the content can be read.
    If you have to do it, simply rename the .php file to a different extension so that the other server does not process it (remember, php is server-side).
     
    legend2, Jan 7, 2008 IP
  5. jakomo

    jakomo Well-Known Member

    Messages:
    4,262
    Likes Received:
    82
    Best Answers:
    0
    Trophy Points:
    138
    #5
    Hello,
    thanks! If I reneneme the file, it will show the information as data in the browser :(

    Best,
    Jakomo
     
    jakomo, Jan 7, 2008 IP
  6. legend2

    legend2 Well-Known Member

    Messages:
    1,537
    Likes Received:
    74
    Best Answers:
    0
    Trophy Points:
    115
    #6
    Isn't that what you wanted?
    when you say include in php, it means include php code, so it is unprocessed code. what did you want exactly?
     
    legend2, Jan 7, 2008 IP
  7. jakomo

    jakomo Well-Known Member

    Messages:
    4,262
    Likes Received:
    82
    Best Answers:
    0
    Trophy Points:
    138
    #7
    Hello,

    Yes, sound wrong.. , sorry

    This is what I have:

    Hosting A
    FILE: test.php
    <? //include_once("http://www.hostingB.com/conexion.php"); <<---- NO RUN, I hope :)

    if ($fp = fopen('http://www.hostingB.com/conexion.php', 'r')) {
    $content = '';
    // keep reading until there's nothing left
    while ($line = fread($fp, 1024)) {
    $content .= $line;
    }
    }

    eval('?>' .$content. '<?php ');

    $sql="SELECT * FROM table";

    $result = mysql_query($sql,$conexion); //$conexion come from B
    if (mysql_num_rows($result)>0)
    {
    $row = mysql_fetch_assoc($result);
    }

    echo ucfirst($row['title']);
    ?>

    Hosting B
    FILE: conexion.php
    <?
    $conexion = @mysql_connect("IP:pORT","username","password") or die("ERROR: Could not connect to database!");
    $connect=mysql_select_db("db",$conexion);
    ?>
     
    jakomo, Jan 7, 2008 IP
  8. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #8
    hey you just need to specify the DB security restictions of site A put the IP of site B .

    And then you can access the db of site A from site B

    This is what you want i guess

    Regards

    Alex
     
    kmap, Jan 8, 2008 IP