Aureole Posted March 25, 2008 Share Posted March 25, 2008 I'll try and give you a realistic example: Let's say we have a website, but the database isn't working, but we have a backup server with another copy of the database. How could I dynamically append say "?secondary_db" to all URLs? <?php // Pseudo code... if there is an error connecting to the database append a string to all urls if the url contains the appended string connect to the secondary database instead ?> Quote Link to comment Share on other sites More sharing options...
discomatt Posted March 25, 2008 Share Posted March 25, 2008 Many, many ways to do this. 1: Attempt server1 every time, if it fails, attempt server2. -Problem: Could take seconds to timeout, making your page execution time annoyingly slow. 2: Trigger a flag in an external file. You would check this file on every page execution, and if the flag is set, use server2. You could then set a cron that continually checks if server1 is up, and when successful, remove the flag from the file -Problem: Requires reading an external file at every page call, and additional code. Also requires a cron, or external script to remove flag. 3: Attempt to connect to server1, if failed, store flag in session. If flag is present, use server2 -Problem: Kinda redundant unless you have a session already started, will attempt to connect to server1 again when session expires Quote Link to comment Share on other sites More sharing options...
Aureole Posted March 25, 2008 Author Share Posted March 25, 2008 I know there are multiple ways of doing this, but what I was looking for was a way to dynamically append something to the end of URLs... just like PHPSESSID is, if cookies are disabled... Quote Link to comment Share on other sites More sharing options...
eddierosenthal Posted March 25, 2008 Share Posted March 25, 2008 not that this has anything to do with php - but you could look into using the .htaccess file using rewrite_mod and rewrite_mod rules. you could for example have a rule that says to append a literal string to a url with a pattern matching algorithm. not tested: RewriteEngine On RewriteRule ^my-literal-page-name\.html$ /my-literal-page-name/anystringyouwanthere [L] the apache rewrite mod has to be loaded for this to work. but you won't have to restart apache if you use the .htaccess method. hope that helps 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.