{"id":2604,"date":"2022-05-06T20:18:30","date_gmt":"2022-05-06T18:18:30","guid":{"rendered":"https:\/\/digitalia.culturanuova.net\/blog\/?p=2604"},"modified":"2022-05-07T08:16:40","modified_gmt":"2022-05-07T06:16:40","slug":"how-to-switch-a-php-variable-according-to-the-server-address","status":"publish","type":"post","link":"https:\/\/digitalia.culturanuova.net\/blog\/?p=2604","title":{"rendered":"How to switch a php variable according to the server address"},"content":{"rendered":"\n<p>I managed to switch my websites links (containing a php variable: $root) according to the server address. If they are in localhost the variable begins with: <code>http:\/\/localhost<\/code> ,  if they are on remote the variable is the remote address.<\/p>\n\n\n\n<p>The php code is quite simple:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if ($_SERVER&#91;'SERVER_NAME'] == \"localhost\")\n{$root_yourwebsiteA = \"http:\/\/localhost\/your path\/yourwebsiteA\/\";\n $root_yourwebsiteB = \"http:\/\/localhost\/your path\/yourwebsiteB\/\";\n $root_yourwebsiteC = \"http:\/\/localhost\/your path\/yourwebsiteC\/\";\n}\nelse \n{$root_yourwebsiteA = \"http:\/\/remote path\/yourwebsiteA\/\";\n $root_yourwebsiteB = \"http:\/\/remote path\/yourwebsiteB\/\";\n $root_yourwebsiteC = \"http:\/\/remote path\/yourwebsiteC\/\";\n}<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I managed to switch my websites links (containing a php variable: $root) according to the server address. If they are in localhost the variable begins with: http:\/\/localhost , if they are on remote the variable is the remote address. The php code is quite simple:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[751,1,566],"tags":[294,750],"class_list":["post-2604","post","type-post","status-publish","format-standard","hentry","category-php","category-senza-categoria","category-webmaster","tag-localhost","tag-variable"],"_links":{"self":[{"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2604","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2604"}],"version-history":[{"count":8,"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2604\/revisions"}],"predecessor-version":[{"id":2612,"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2604\/revisions\/2612"}],"wp:attachment":[{"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2604"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2604"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2604"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}