mmarif4u Posted August 22, 2007 Share Posted August 22, 2007 Hi all. I have site where some time i update the database details according to server and my local pc. Now i want a function that will redirect the user if database name or username or password is wrong. i dont want that the site show in the middle of page " cannot connect to database", i want that i redirect the user if some problem occur in the database config. Hope some will have a good idea. Thanks Link to comment https://forums.phpfreaks.com/topic/66099-solved-function-to-redirect-site-to-error-page/ Share on other sites More sharing options...
teng84 Posted August 22, 2007 Share Posted August 22, 2007 your prob is weird lol i think thats easy just put a condition like if success connection then put the header file whats the problem with that Link to comment https://forums.phpfreaks.com/topic/66099-solved-function-to-redirect-site-to-error-page/#findComment-330589 Share on other sites More sharing options...
Hypnos Posted August 22, 2007 Share Posted August 22, 2007 The text book way to connect, with an error. $link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); if (!$link) { die('Could not connect: ' . mysql_error()); } What you can use instead: $link = @mysql_connect('localhost', 'mysql_user', 'mysql_password'); if (!$link) { header('Location: http://www.google.com'); } Replace google with where you want it to go. There are many ways to solve the deeper problem here. One way is to have a "sql.php" file on each server, with the "mysql_connect" and "mysql_select_db" functions filled out for that server. You can also do if/else matches against the $_SERVER vars. Link to comment https://forums.phpfreaks.com/topic/66099-solved-function-to-redirect-site-to-error-page/#findComment-330593 Share on other sites More sharing options...
mmarif4u Posted August 22, 2007 Author Share Posted August 22, 2007 sorry for dumb post i got it using function. Link to comment https://forums.phpfreaks.com/topic/66099-solved-function-to-redirect-site-to-error-page/#findComment-330597 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.