Jump to content

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.
Link to comment
https://forums.phpfreaks.com/topic/13357-define-a-url-for-include/
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);

?>
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.