Jump to content

Replacing one word for entire site depending on the URL.


Ty44ler

Recommended Posts

I have two domains. I'd like to replace a word depending on the URL the user has typed in.

 

For example:

Original site is all about red pens. Well I want to make another domain that is bluepens.com, but when they enter in bluepens.com it uses the same pages from red pens except wherever the word 'red' is found it is changed to blue pens making it a whole new site.

 

I know I can use str_replace() for certain instances, but how would you do it for an entire website using the url?

 

Thanks!

Link to comment
Share on other sites

Create another include file and call it something like "includes.php" or "pagename.php"

 

On every page where you would want to define this just "require_once includes.php;"

 

have a variable in there called $site_name and set it based upon the URL of the current page.

 

On every page just have "echo $site_name" and that will display what you are looking for.

Link to comment
Share on other sites

You can set up a session variable to be either red or blue.  For example $_SESSION['colour']="red";

 

Then you can use all the same site.  Instead of having a sentence as "this is a red pen"  use "this is a $colour pen"  This will then change the text within the site depending on what the user has done. 

 

Possibly the best way would be to just have one site called "Pens" with a form on the opening page asking if the user wants blue or red pens.  Then POST their reply back to the Session Variable.

 

This way you only use 1 URL and you are cusomizing the site on the fly for the user.  It also gives you scope to run IF statements against the SESSION variable to change pictures, prices etc without having to write 2 complete sites.  The session variable will also stay in place as they move from page to page

Link to comment
Share on other sites

I would take a slightly different approach. Instead of calling the same include() file over and over, have a script that defines a variables or variables (no need to run the same code over and over). Most likely you will really need more than just a single name to be different. You may need to define different images, singular/plural differences, different cases of the name. different URLs, etc.

 

So, have a script that determines the current domain and defines all those variables. Then simply use those variables where you need them. You should be able to use $_SERVER['SERVER_NAME'] to determine the site.

Link to comment
Share on other sites

Those are good answers. I already have a standard include file for the site so I may go that route since it's already halfway in place.

 

I'm not actually selling pens. It's actually a sort of directory for technicians to sign up looking for jobs, but for different technicians. I just thought the red vs blue would be a simpler analogy.

 

One more question, how would I deal with upper and lower case values? Some would need to be upper case, while others would be lower case?

Link to comment
Share on other sites

One more question, how would I deal with upper and lower case values? Some would need to be upper case, while others would be lower case?

 

Like I said in my example, you would define different variables as needed. You could either define different variables for different "cases" of the name or you could programatically change the case in the code where those variables are displayed.

 

Example #1

//Include file logic
if($site=='red')
{
    $sitenameLowercase = 'red';
    $sitenameLowercase = 'RED';
    $sitenameSentenceCase = 'Red';
    $siteURL = 'myredsitelogo.jpg';
}
else
{
    $sitenameLowercase = 'blue';
    $sitenameLowercase = 'BLUE';
    $sitenameSentenceCase = 'Blue';
    $siteURL = 'mybluesitelogo.jpg';
}

Then just use those variables in the appropriate places on your pages

 

Example #2

//Include file logic
if($site=='red')
{
    $sitename = 'red';
    $siteURL = 'myredsitelogo.jpg';
}
else
{
    $sitename = 'blue';
    $siteURL = 'mybluesitelogo.jpg';
}


//Page logic
echo "Welcome to the " . ucwords($sitename) . " site.";
//Output: Welcome to the Blue site.

Link to comment
Share on other sites

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.