Apache2Triad Help, Support and Development Forum Index Apache2Triad Help, Support and Development
The apache2triad help , support and development forums
 

Creating a Member Access Only - HELP!!!!!
Click here to go to the original topic

 
       Apache2Triad Help, Support and Development Forum Index -> Programming
View previous topic :: View next topic  
Author Message
QWERTYtech



Joined: 03 May 2006
Posts: 47

Posted: Wed Jul 05, 2006 8:02 pm    Post subject: Creating a Member Access Only - HELP!!!!!  

I want to create a member access page and I want it to check the usrnm and password to my database... That part I can do.... Now how can i make it open a page in /_private? But i don't want anyone to just be able to browse to /_private.... I don't know if Im going about this the hard way or not but I would greatly appreciate any help....

Also, i don't want the login to store any information in a cookie for future reference.... All this scripts i have found store information in a cookie. I need someone to be able to login to this site without someone being able to go behind them and login also.....


Thanks for any help,
QWERTYtech
Back to top  
cigraphics



Joined: 21 Aug 2005
Posts: 152
Location: Romania, Pitesti

Posted: Wed Jul 12, 2006 11:52 am    Post subject:  

you can make it with php and mysql or with .htpasswd and .htaccess ( with groups)
Back to top  
QWERTYtech



Joined: 03 May 2006
Posts: 47

Posted: Sat Jul 15, 2006 8:06 pm    Post subject:  

what would be easeir? i have worked on some stuff but i cant get it to work right..... look at this code please.....


main_login.php
Code:
 
############### Code

<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="checklogin.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Member Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" id="myusername"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="text" id="mypassword"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
 



checklogin.php
Code:
<?php
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="members"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from signup form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>



login_success.php
Code:
// Check if session is not registered , redirect back to main page.
// Put this code in first line of web page.
<?
session_start();
if(!session_is_registered(myusername)){
header("location:main_login.php");
}
?>

<html>
<body>
Login Successful
</body>
</html>



logout.php
Code:
// Put this code in first line of web page.
<?
session_start();
session_destroy();
?>



php5 - checklogin.php
Code:
<?php
ob_start();
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="members"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// Define $myusername and $mypassword
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}

ob_end_flush();
?>


This is the code that im running but it seems not to run right.

http://redbeardcustoms.no-ip.info/WebSite/main_login.php
Back to top  
cigraphics



Joined: 21 Aug 2005
Posts: 152
Location: Romania, Pitesti

Posted: Mon Jul 31, 2006 10:09 am    Post subject:  

try this:
http://www.phpeasystep.com/workshopview.php?id=6
Back to top  
 
       Apache2Triad Help, Support and Development Forum Index -> Programming
Page 1 of 1


Powered by phpBB Search Engine Indexer
Powered by phpBB 2.0.13 © 2001, 2002 phpBB Group