Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    May 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    php file include is not working

    I want to inclide file with URL
    i tried with following ways
    include 'domain.com/file.php';
    include('domain.com/file.php');
    both cases not working suggest me

  • #2
    Regular Coder
    Join Date
    Sep 2011
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts
    You cannot include files from another source. So if you are trying to do that, that won't work. If you are trying to include from your own, then you shouldn't use the absolute path. Short example is following.

    Assuming you are on domain.com/index.php.

    PHP Code:
    <?php
    include('file.php');
    ?>

  • #3
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,108
    Thanks
    2
    Thanked 326 Times in 318 Posts
    I recommend reading the documentation for what you are trying to do - PHP: include - Manual

    It explains and has examples showing the difference between using a file system path (the normal case) and a url, what settings must be on for a url to work, and what Internet protocols can be used in a url.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,358
    Thanks
    61
    Thanked 530 Times in 517 Posts
    Quote Originally Posted by Krentenbol View Post
    You cannot include files from another source.
    I've seen mud thats clearer than that explanation.

    @ shindesharad71: The reason it does not work is because you re trying to include a file from a URL. This means that php will try to obtain it via a http connection via the webserver at that address. When that webserver gets a http request it will run the php file through the php program which will strip out any php code and only output any html that is not within the <?php ?> tags. Thus if you call a remote php file from a webserver it will contain no php code.

    You can only include a local php file using a local file system path. If you must include a remote file via a url then you either need to ensure that the file extension of the remote path is not .php (or any other executable file extension) or have the php script actually print itself out to the http request.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #5
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Quote Originally Posted by tangoforce View Post
    You can only include a local php file using a local file system path. If you must include a remote file via a url then you either need to ensure that the file extension of the remote path is not .php (or any other executable file extension) or have the php script actually print itself out to the http request.
    Quote Originally Posted by Krentenbol View Post
    You cannot include files from another source.
    Actually you can include files from a URL, but that feature is disabled by default for security reasons.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •