I have several websites and I plan to use the same php file to notify my updates in all the sites.
But in this way I have the problem that I can’t use, as I did so far, a relative path, given the fact that my websites are hosted in different remote server.
So I wonder if there is in php a way to switch the $root variable from a (relative) local address (http://localhost) to a remote one (https://myremotewebsite), according to the fact to be called from a local server or from a remote one.
The variable to switch is one: $root. What is the $root value? In localhost something, in remote other.
Thank you.
EDIT
maybe using (also) CSS: to show or hide a content (according to its “class”).
But using also $_SERVER, I guess… to switch from a class to another…
Sorry, but I have found a quite simpler solution: define, in a file linked with my home (where are the links to the updated or added pages) as many $root_other_sites variables as necessary.
F.e. in my website A $root_A is the root folder (regardless for local or remote), and another my website has as root the $root_B variable (the absolute remote path), and $root_A = $root in website A, and in website B $root = $root_B.
It works and with very few code.
Thank you any way!
@web148 ,
If you have a mirror image of your online domains yu may be interested in the following utility that creates RSYNC scripts to be copied and pasted into your Command Box:
Please give examples to your support your argument.
Having code generate a dynamic URL is beneficial instead of hard-coding the URL multiple times especially if the domain is moved from a Sandbox to a live server.
I use the following script that manages to determine the exact domain. It works for localhost, http, https, https://www, and even sub-domains
For what do you need the URL? You can start any script with relative path like
“./myscriptonsamefolder”,
“…/myscxriptonparentfolder”,
“…/sub/myscript on subfolderinparentfolder”
…
So you never need a absolute url to run any other script from your page and you do not need to know the root at any time and it works on any server instance doesn’t matter where it is installed
so in the file shared between A and B I can use, as link, $root_A and $root_B as content of their url and each website knows what that variable mean exactly (website A knows that $root_A is its $root, and website B knows that $root_B is its $root).
My aim was to have only one (php) file for my several websites to notify the new or updated webpages and to have links (within that php file, pointing to several my websites) working correctly in all my websites.
My solution works.