php include files - brand newbie

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
CordLaFond
Forum Newbie
Posts: 1
Joined: Fri Oct 30, 2009 12:46 pm

php include files - brand newbie

Post by CordLaFond »

I have an application which I want to use on multiple sites.
Within a single site I use <?php include("filename.inc.php"); ?> and things work fine.

I have tried accessing the same file from a different site using <?php include("http://url.com/filename.inc.php"); ?> - no success
One source suggested removing the parentheses. I tried - no success?

I am brand new to php and don't know where to look or what to ask. I am going to start wading through some tutorials, but in the mean time, if someone could help me I would be very grateful.

Q1: How do I access an include file from a different website?
Q2: Can anyone recommend a good beginner's book or online tutorial to get familiar with basic php principles and code?

Thank You
User avatar
akuji36
Forum Contributor
Posts: 190
Joined: Tue Oct 14, 2008 9:53 am
Location: Hartford, Connecticut

Re: php include files - brand newbie

Post by akuji36 »

take a look at this link:

http://www.youtube.com/watch?v=SxQp7fUuMhY

thanks

Rod
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: php include files - brand newbie

Post by social_experiment »

Hey there,

The best way to start is to get the php manual. Use "download php manual" with Google and you should be able to download the manual.

The following example is from the php manual

Code: Select all

 
<?php 
/* This example assumes that http://www.example.com is configured to parse .php
* files and not .txt files. Also, 'Works' here means that the variables
* $foo and $bar are available within the included file. */
 
// Won't work; file.txt wasn't handled by http://www.example.com as PHP
include 'http://www.example.com/file.txt?foo=1&bar=2';
 
// Won't work; looks for a file named 'file.php?foo=1&bar=2' on the
// local filesystem.
include 'file.php?foo=1&bar=2';
 
// Works.
include 'http://www.example.com/file.php?foo=1&bar=2';
 
$foo = 1;
$bar = 2;
include 'file.txt';  // Works.
include 'file.php';  // Works.
 
?>
 
And the text below is also from the manual ( it precedes the example ).

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 (via HTTP or other supported wrapper - see List of Supported Protocols/Wrappers for a list of protocols) instead of a local pathname. If the target server interprets the target file as PHP code, variables may be passed to the included file using a URL request string as used with HTTP GET. This is not strictly speaking the same thing as including the file and having it inherit the parent file's variable scope; the script is actually being run on the remote server and the result is then being included into the local script.

Hope this helps
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply