Jump to content

Archived

This topic is now archived and is closed to further replies.

tomfmason

define a url for include()

Recommended Posts

I am wanting to define a url in a seperate file, say constant.php and call that when needed.

Here is an example
[code]<?php
include("../includes/constant.php");
?>
<?php
$filename = "('$url')/products/index.php";  //I am not sure if this is the right way
$title = "Products";                                    // or not
?>
<?php
include("$url/includes/construct.php");  //or maybe this would be better?
include("$url/includes/main.php")
?>[/code]

Here is an example of the constant file

[code]<?php
$url = "http://www.owpt.biz"
?>[/code]

I know that it would be easier, for now , to just use include("http://www.owpt.biz/includes/main.php")
but I am going to be using this on more then one site and I don't want to have to go back and update all of the files.

Share this post


Link to post
Share on other sites
Put the url in a function then include that file, then call the function to that file.


example:


//please not that php dosent like to use include(""); x amount times,
so use the function page to add all common codes and return the funtion to the page.

test.php

<?php

//make a function

function email($email_address) {

// varable name to the url

$email_address="www.phpfreaks.com";
echo $email_address;
}
?>

test_result.php

<?php

// include the page where the function is

include("test.php");

// call the function name and use anywere within the script.

email($email_address);

?>

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.