NameSilo

Username & Password Protected

Spaceship Spaceship
Watch

Sohil

VIP Member
Impact
7
Hello all,
I was wondering is there a script/way to make a certain page which can be only accessed by a username and password. I would like to make more than one username and password so please let me know if this is possible.
Thank you.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
.US domains.US domains
Which are you more fond of? PHP or JavaScript ? :gl:
 
0
•••
SecondVersion said:
Which are you more fond of? PHP or JavaScript ? :gl:

PHP but anything will work right now..
 
0
•••
1
•••
0
•••
No prob. :)
 
0
•••
A question,
When I am trying to access admin area it is giving me following error,
Warning: mysql_connect(): Access denied for user: 'your_name@localhost' (Using password: YES) in /home/bwsongs/public_html/include/database.php on line 24
Access denied for user: 'your_name@localhost' (Using password: YES)
even though I can access the user page. I looked at all the files but I am not getting anywhere. Would you happen to know why?
 
0
•••
In that page, in constants.php, you need to make some changes to that file, especially the following:

define("DB_USER", "your_name");
define("DB_PASS", "your_pass");
define("DB_NAME", "your_dbname");


Replace your_name with your database username, your_pass with your database password, and your_dbname with the name of your database.

Check the rest of that file, there might be some other things you need to change as well.

Joe
 
0
•••
gamex said:
In that page, in constants.php, you need to make some changes to that file, especially the following:

define("DB_USER", "your_name");
define("DB_PASS", "your_pass");
define("DB_NAME", "your_dbname");


Replace your_name with your database username, your_pass with your database password, and your_dbname with the name of your database.

Check the rest of that file, there might be some other things you need to change as well.

Joe


I have already done that and like I have said I can login and everything just can't access the admin area.
 
0
•••
Well the problem is with line 24 in database.php, which is the following:

PHP:
$this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error());

It is having some sort of problem connecting to the database, dont know why you can access the users page though...

Contact me on AIM/Yahoo and ill see what I can do, Ill be on for another 20 minutes, otherwise I will be on tomorrow morning

Joe
 
0
•••
Also, just incase you can't figure this out, I have provided another wonderful script...Its very easy to use. Step by step guide..

Tutorial Here
 
0
•••
Hey bud, try this code. its 100% free to use, as long as you cite it.

I named this file private.php, you can change the name of this file, to watever you want, but then YOU MIGHT have to modify this script..

Put this part of the script in the code before <HTML>, means very begining of the page..
PHP:
<?
/* ---------- user settings ---------- */


$un = "YOUR USER NAME";
$pw = "YOUR PASSWORD";

/* ----------  actions ----------  */

if ($action == "logout") {
   session_unset();
echo "<b>You were successfully logged out from the system!</b>";
}

if ($action == "login") {
   if ($put_un == $un)    {
       if ($passw0rd == $pw) {
           $_SESSION['auth'] = true;
       } else {
           $error = "<font color=\"red\">Error:</font> incorrect password/username. <br /> The username/Password are CAsE SEnSItiVE";
       }
   } else {
       $error = "<font color=\"red\">Error:</font> incorrect username/password. The username/password are The User/Password are CAsE SEnSItiVE";
   }
}

/* ---------- authenticate ----------  */
if ($_SESSION['auth'] == true) {
   /* secure code */
} else {
   /* non-secure code */

   $view = "login";

}

?>



The code below goes anywhere on the page, for instance <BODY>;
PHP:
<? if ($view == "login") { ?>

<form action="private.php" method="post">
Don't have an account? Click <a href="/contact_me.php">here</a><br /> <br>
	<table border="0" cellpadding="3" cellspacing="1" width="100%">

		<td width="45%" align="center">Username:</td>
		<td> 
		<input type="text" name="put_un" size="20" maxlength="20">
		</td>
	
<tr> 
		<td align="center">Password:</td>
		<td>
	
		<input type="password" name="passw0rd" size="25" maxlength="25" />
		</td>
	  </tr>
</table>
   <input name="action" type="hidden" id="action" value="login"><br>
  <center> <input type="submit" name="Submit" value="login"><br /><? echo  "$error<br>"; ?></center>
</form>

<? } if ($_SESSION['auth'] == true) { ?>

<! -- SECURE CONTENT -->

<a href="private.php?action=logout"><b><?php echo "$un"; ?></b> logout? </a>

PUT YOUR SECURE STUFF HERE

<? } ?>

thats it!

PS- this is NOT the best way to secure your page..

use .htaccess on your Apache server If u have one, that's what I use..
 
Last edited:
0
•••
Yes I would suggest apache password protect folders. I am not that ggod at php so I use it.
 
0
•••
Dynadot — .com TransferDynadot — .com Transfer
Appraise.net

We're social

Domain Recover
DomainEasy — Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back