Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

PHP 

Different <div> based on which domain is being used.

I have about 14 domains pointed to a primary hosting account, some of them are different by name completely.

I have different divs calling different logos based on what nav is called up.

PHP Code

<?php 
        
if ($_GET['nav'] == 'test' || $_GET['nav'] == 'test1' || $_GET['nav'] == 'test2' || $_GET['nav'] == 'test3') {
 
                echo "<div id=\"logo-test\"></div>";
 
        }
 
        else if ($_GET['nav'] == 'testy'|| $_GET['nav'] == 'testy1' || $_GET['nav'] == 'testy2') {
 
                echo "<div id=\"logo-testy\"></div>";
 
        }
 
        else {
 
                echo "<div id=\"logo\"></div>";
         } 

That script works fine, and if the http://domain1.tld/testy and http://domain2.tld/testy loads the proper logo on the designated page no problem.


What I Want to do now, is enable it so if I access a page from

http://domain1.tld <-- It will show the Domain 1 Logo
http://domain2.tld <-- It will show the Domain 2 Logo

I didnt know if there was a GET for HTTP address.

Thank you for your help
[Image: linksig.png]
I haven't personally done this before, but to check what site a user came from you probably need the $_SERVER superglobal.

This is a question very similar to yours that has been answered:

https://stackoverflow.com/questions/1061...rom-google

http://php.net/manual/en/reserved.variables.server.php
[Image: K2c6AfR.png]
The best way is to create a configuration file for each domain and create a variable where you can identify each domain. The most common way is to use $_SERVER['HTTP_HOST'] or $_SERVER['SERVER_NAME'] but I don't recommend that since it can be generally unsafe.
Here's why transfer.sh/3Xbiz/file.mp4
I recommend seeing this too stackoverflow.com/questions/6474783/which-server-variables-are-safe.
Here's an example for both using $_SERVER and using configuration file.

using configuration

config.php
PHP Code

<?php
       $domain 
= "domain1.tld";
 
      /* Other Configurations */ 

PHP Code

<?php 
        require 
"config.php";
 
        if ($domain == "domain1.tld") {
 
                echo "<div id=\"logo-test\"></div>";
 
        }
 
        else if ($domain == "domain2.tld") {
 
                echo "<div id=\"logo-testy\"></div>";
 
        }
 
        else {
 
                echo "<div id=\"logo\"></div>";
 
        } 

and if you don't care about security
using $_SERVER
PHP Code

<?php 
        $domain 
= $_SERVER['HTTP_HOST'];
 
        if ($domain == "domain1.tld") {
 
                echo "<div id=\"logo-test\"></div>";
 
        }
 
        else if ($domain == "domain2.tld") {
 
                echo "<div id=\"logo-testy\"></div>";
 
        }
 
        else {
 
                echo "<div id=\"logo\"></div>";
 
        } 

or even better
PHP Code

<?php 
        $myDomains 
= array("domain1.tld", "domain2.tld");
 
        $domain = $_SERVER['HTTP_HOST'];
 
        if( in_array(strtolower($domain), $myDomains) )
 
                 switch ($domain) {
 
                     case "domain1.tld":
 
                         echo "<div id=\"logo-test\"></div>";
 
                         break;
 
                     case "domain2.tld":
 
                         echo "<div id=\"logo-testy\"></div>";
 
                         break;
 
                     default:
 
                         echo "<div id=\"logo\"></div>";
 
                 }
 
        } 
$_SERVER['HTTP_HOST'] is the key. It contains the hostname that was used to navigate to your server.
/* No comment */
Does, HTTP_HOST, reflect if someone visits from http://domain1.tld and http://www.domain1.tld?
[Image: linksig.png]
if you visited from domain1.tld, HTTP_HOST will be domain1.tld but if you visited from w w w.domain1.tld it'll be w w w.domain1.tld. If you want it to always be only either one you can add a .htaccess rule to do that.
Redirect non-www to www: stackoverflow.com/questions/12050590/redirect-non-www-to-www-in-htaccess/36807965
Redirect www to non-www: stackoverflow.com/questions/234723/generic-htaccess-redirect-www-to-non-www
However if you want to use both this is a little trickier. You can obviously add the www domain to the accepted Domains but for a better approach you need to get what is after www there are many ways to do this. Here's one.

PHP Code

<?php 
$domain 
= explode('.', $_SERVER['HTTP_HOST'], 2);
if( 
$domain[0] == "www" && in_array(strtolower($domain), $domain[1]) ) {
 
       //Add lcon
}
// Other checks 
Right on, thanks! You are a gentleman and a scholar.
[Image: linksig.png]


Possibly Related Threads...
Thread / Author Replies Views Last Post
[PHP] by B00B5Jun 2, 2024 07:42 AM 12 466 Jun 2, 2024 07:42 AM
Last Post: SilentNuke
[Javascript]  by ОЯВІТOct 27, 2022 03:26 PM 4 205 Oct 27, 2022 03:26 PM
Last Post: Shellcode™
[Javascript]  by bevcJun 24, 2020 11:54 PM 3 194 Jun 24, 2020 11:54 PM
Last Post: bevc