tags:

views:

243

answers:

3

Ok I'm at my work this friday setting up a table that will have data in it that will come from a separate file called values.php. When I write it like this, the divs turn up blank. I think I have the "include" written wrong, does an absolute path not work?

<?php include('http://www.nextadvisor.com/credit_report_services/values.php'); ?>

<div class="box_text">
      <div class="box_image">
       <a href="<?php echo $offer1link ?>" target="blank"><img src="<?php echo $offer1logo ?>" alt="<?php echo $offer1name ?>"></a></div>
       <div class="box_rating">
       Rating:<span class="star_rating"><img src="<?php echo $offer1star1 ?>" alt=""></span><br>
        <div class="rating_review"><a href="<?php echo $offer1link ?>" target="blank">Go to Site</a> | <a href="<?php echo $offer1anchor ?>">Review</a></div>       </div>


      <br style="clear: both;">
       </div>

Oh and thanks in advance for any help you can give. Anyone who has helps me is the greatest. I feel bad cause sometimes two people answer the question and I can't give the green check to both.

+2  A: 

Hello dude,

The type of include you are trying to do is blocked by default, not to say that it is dangerous. You are trying to include a remote file.

If your script is in the same machine as the "values.php" you should use an absolute path similar to "/var/www/nextadvisor.com/credit_report_services/values.php" or a relative path depending on the location of your file, instead of http://www.nextadvisor.com/credit_report_services/values.php

It doesn't seem to me that you are trying to include a remote file but if you still want to include a remote file you must set the following directives in your php.ini

allow_url_fopen = 1
allow_url_include = 1
fromvega
According to the manual its enabled by default, but that might be wrong. In which case it should be reported. Quote: If "URL fopen wrappers" are enabled in PHP (which they are in the default configuration), you can specify the file to be included using a URL
OIS
thanks. thanks OIS and tenebrous also for their help!
pg
The allor_url_include directive is disable by default since PHP 5.2.0
fromvega
http://www.php.net/manual/en/features.remote-files.php
fromvega
+1  A: 

Absolute filename is something like /path/to/file.php as you would access the file from anywhere in the file system hierarchy.

If its in the same dir, or relative to the same dir, you can use something like

include dirname(__FILE__) . '/file.php';
include realpath(dirname(__FILE__) . '/../dir') . '/file.php';
include realpath(dirname(__FILE__) . '/../dir/file.php');

You should probably make some constants like

define('BASEDIR', dirname(__FILE__));
define('LIBDIR', BASEDIR . '/lib');
OIS
+3  A: 

Since you're using a URL, PHP will send a request to the server for the file, and the server will parse it just as it would if a browser requested it. What you probably want to do is use a path relative to the script for your include. If the file you want to include is in the same folder, just use
include('values.php');

TenebrousX