otuatail Posted June 9, 2014 Share Posted June 9, 2014 (edited) <? // Bank Version 1.0.0 21-05-2014 Desmond O'Toole. include ("secure/SecureFunctions.php"); include ("secure/SecureFunctionsLibAdmin.php"); session_start(); Session_Init(); $page = "Bank_EE Doc"; define ('hostname16', 'xxx'); // Des-otoole.co.uk define ('username16', 'xxx'); define ('password16', 'xxx'); define ('database16', 'xxx'); function myErrorHandler($errno, $errstr, $errfile, $errline) { switch ($errno) { case E_USER_ERROR: $_SESSION['MyError'] = "Gotcha: <br>$errstr<br>$errfile<br>$errline"; mailtoX('Error', $errstr,$_SESSION['MyError']); $redirect = "Location: myerror.php"; header($redirect); exit(0); break; case E_USER_WARNING: echo "This is your last warning"; break; case E_USER_NOTICE: echo "This is your final warning"; break; default: echo "Just go away"; break; } /* Don't execute PHP internal error handler */ return true; } $old_error_handler = set_error_handler("myErrorHandler"); function connectDB($db) { $host = hostname16; $user = username16; $pass = password16; $data = database16; if(!$link = @mysql_connect($host, $user, $pass)) trigger_error('Can\'t connect to server: ('. $db . ')', E_USER_ERROR); if(!$database = @mysql_select_db($data, $link)) trigger_error('Can\'t select database on: (' . $db . ')', E_USER_ERROR); } connectDB(CURRENT_DB); echo "Hi there"; ?> Hi this coding works on another website although I have reduced it down here for clarity. I have had my website moved to another server and I can't connect now. If there is a better way? I was given this coding from someone on this website about 4 years ago. I didn't want to use a strait connect because when there was difficulty connecting to the database I received an error giving me and any hacker all the details of the database server. This was to be a more controlled access. Edited June 9, 2014 by ignace Quote Link to comment https://forums.phpfreaks.com/topic/289084-is-this-style-of-coding-considered-obsolete/ Share on other sites More sharing options...
Barand Posted June 9, 2014 Share Posted June 9, 2014 Don't publish passwords Quote Link to comment https://forums.phpfreaks.com/topic/289084-is-this-style-of-coding-considered-obsolete/#findComment-1482297 Share on other sites More sharing options...
otuatail Posted June 9, 2014 Author Share Posted June 9, 2014 (edited) Ok thanks but without the server and website stuff I think I am safe. I would not be safe if I used the standard MySQL connection which could result in a web page unable to connect to this database at this server . I need security really. sorry I didn't realise that I had shown the URL. This is very important to me and very urgent to get going. Edited June 9, 2014 by otuatail Quote Link to comment https://forums.phpfreaks.com/topic/289084-is-this-style-of-coding-considered-obsolete/#findComment-1482338 Share on other sites More sharing options...
otuatail Posted June 9, 2014 Author Share Posted June 9, 2014 (edited) This is just a basic query. I have no server networking experience so a little help might solve this. on my main website I can connect to the database using the code I supplied. I asked my provider for another sub domain and the same code does not connect to the database. Is this because a sub domain has to access the database different? Is it because the sub domain is on a different server from my main website and has not been set up Does the website have to be on the same server as the sub domain website This might sound stupid to you but it is the only idea I can come up with. As stated above I am desperate to get this working. PLEASE. Edited June 9, 2014 by otuatail Quote Link to comment https://forums.phpfreaks.com/topic/289084-is-this-style-of-coding-considered-obsolete/#findComment-1482341 Share on other sites More sharing options...
mac_gyver Posted June 9, 2014 Share Posted June 9, 2014 for debugging purposes, you would want your code to tell you (log) why it is failing. you can use mysql_error() to get the reason why the connection failed. Quote Link to comment https://forums.phpfreaks.com/topic/289084-is-this-style-of-coding-considered-obsolete/#findComment-1482344 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.