/    Sign up×
Community /Pin to ProfileBookmark

security php-mysql

Hi , my connect.php code which i use to connect to my mysql database is like below

<?php
$link = mysql_connect(‘localhost’, ‘root’, ‘34730’);
if (!$link) {
die(‘Could not connect: ‘ . mysql_error());
}
echo ‘Connected successfully<br>’;

$db_selected = mysql_select_db(‘sports’, $link);
if (!$db_selected) {
die (‘Can’t use : ‘ . mysql_error());
}
?>

i simply include connect.php to my other pages and it works perfectly .

However ,obviously if i run my website like this on the net , i will have security troubles for sure ..
Can anyone tell me a better and more sequre way of connecting to my database?
thanks

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@SheldonJun 10.2007 — try [code=php]<?php
//connect.php
if(basename(__FILE__) == basename($_SERVER['PHP_SELF'])){
header("Location: http://domain.com/login.php");
}else{
mysql_connect ("localhost", "*****", "*****") or die ("I cannot connect to the database because: " . mysql_error());
mysql_select_db("inboxdesign");
}
die;
?>[/code]
Copy linkTweet thisAlerts:
@barantamerauthorJun 11.2007 — thanks for the reply , can you explain me this line please ?

if(basename(__FILE__) == basename($_SERVER['PHP_SELF'])){
Copy linkTweet thisAlerts:
@SheldonJun 11.2007 — That is comparing the actual file name and the name of which script is being called.

http://php.net/basename
Copy linkTweet thisAlerts:
@niconel_comJun 11.2007 — I dont know that much, but I read the other day, to make things more secure, save your php connection script outside your document root.
×

Success!

Help @barantamer spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...