Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

Using MySQL database to protect server directories


  • Please log in to reply

#1
Dan - Phoenix

Dan - Phoenix

    Member

  • Member
  • PipPip
  • 11 posts
Hello,

Im a web developer and would like to know if there is any way of using MySQL to add a password to my website download area. I had the files in my folder for less than an hour and people i didnt know were logged downloading them. So i would like to know if anyone can help me out...

Im using a server package called xampp which can be found at www.apachefriends.org i think...

it comes with apache, mysql php etc

any help would be greatly appreciated

dan :tazz:
  • 0

Advertisements


#2
Magosis

Magosis

    Retired Staff

  • Retired Staff
  • 190 posts
<?php
								//connect to database
		$link = mysql_connect('localhost', 'Username', 'Password');
		mysql_select_db('nlstudio');
													  //check if they are already logged in
			 	if ($_COOKIE['logged'] == true) {
					
													  //what to show if they are logged in
					
													  //check if they were attempting to login
				} elseif ($_POST['uname'] == true) {
													  //find username and password in database
					$query = "SELECT * FROM users WHERE user = '{$_POST['uname']}' AND pass = '{$_POST['pas']}'";
					$result = mysql_query($query) or die(mysql_error());
					while ($arr = mysql_fetch_assoc($result)) {
						$name = $arr['user'];
					}
													   //check if usename is valid
					if ($name == true) {
													   //sets the login cookie
						setcookie("logged",$name,0,'/',"nlstudio.nl.funpic.org");
													   //shows the valid login message
						echo "<table cellspacing='0'><tr><td class='borderback' bgcolor='#999999' align='left'>Welcome back $name</td></tr><tr><td class='whitetext' colspan=2 bgcolor='#000000'>You are logged in, <a href='admin.php'>Click here</a> to go back to the Administration page.</td></tr></table><p>";
					} else {
													   //shows the invalid login message
						echo "<table cellspacing='0'><tr><td class='borderback' bgcolor='#999999' align='left'>Error</td></tr><tr><td class='whitetext' colspan=2 bgcolor='#000000'>Un-able to log in, check you username and password, then <a href='admin.php'>try again</a></td></tr></table><p>";
					}
				} else {
													   //shows the login prompt if they are not logged in
					echo "<table cellspacing='0'><tr><td class='borderback' bgcolor='#999999' align='left'>Log In</td></tr><tr><td class='whitetext' colspan=2 bgcolor='#000000'><form action='admin.php' method='post'>Username <input type='text' name='uname'><br>Password  <input type='password' name='pas'><br><input type='submit' value='Log In'></form></td></tr></table><p>";
				}
		?>

here is the basic login code I use. I find it works quite well.

Edited by Magosis, 13 December 2005 - 02:38 PM.

  • 0

#3
Dan - Phoenix

Dan - Phoenix

    Member

  • Topic Starter
  • Member
  • PipPip
  • 11 posts

[code=auto:0]<?php
//connect to database
$link = mysql_connect('localhost', 'Username', 'Password');
mysql_select_db('nlstudio');


wow cheers m8, have u got an sql script which would complie that database???

would be very handy

cheers
dan
  • 0

#4
Dan - Phoenix

Dan - Phoenix

    Member

  • Topic Starter
  • Member
  • PipPip
  • 11 posts
ive sorted it now, not using mysql, instead i used the .htaccess attributes within apache web server.

but id still like to know how to do it this way so i can have multiple users logging in

Dan
  • 0

#5
Magosis

Magosis

    Retired Staff

  • Retired Staff
  • 190 posts
SQL query:
CREATE TABLE `users` (
`user` TEXT NOT NULL ,
`pass` TEXT NOT NULL
) TYPE = MYISAM ;
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP