Ty44ler Posted October 25, 2011 Share Posted October 25, 2011 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! Quote Link to comment Share on other sites More sharing options...
cunoodle2 Posted October 25, 2011 Share Posted October 25, 2011 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. Quote Link to comment Share on other sites More sharing options...
Nodral Posted October 25, 2011 Share Posted October 25, 2011 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 Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 25, 2011 Share Posted October 25, 2011 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. Quote Link to comment Share on other sites More sharing options...
Ty44ler Posted October 25, 2011 Author Share Posted October 25, 2011 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? Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 25, 2011 Share Posted October 25, 2011 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.