Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Newbie

Status
Not open for further replies.

cannonenter

Programmer
Mar 27, 2003
20
GB
I am using D Weaver MX. I wish to make a login PHP screen with a database behind the page. I wish the user to Login and then a download page to be shown.

The problem is that i do not have any idea how to do this. And also i do not wish any person without a login and password to be able to access the page until they register with the site.

And finally how would i go about getting a registration page setup where the user enters and User Name and Password. this information would then connect to the database and enter the information and save it all

sorry to be a pain.

Hope you can help.
 
Sorry to be a pain as well, but this is the heart of PHP/MySQL in a nutshell, what you want to do. It would take an entire website to describe it all...try searching the web for each part at a time...start here maybe:


This helped me in the beginning....The Refugee
 
Session variables are your ticket to success.

Here's the basic concept of how they work...

You set a special session variable after doing your verifications of the person.

Every page they load until a logout gets access to this session variable, so you can make sure they're cool.

If the page doesn't see the session variable it asks for a log in.

 
Here's a snippet from one of my scripts, but before pasting, definitely read what skyflyer sent you...

Code:
	$username=$_POST['username'];  //these come from the form on the page before this one
	$password=$_POST['password'];

	connectDB();  //This is a function I made for mysql_connect() and mysql_select_db();
	
	$query="SELECT * FROM members where username = '$username'";
	$result=mysql_query($query,$conn) or die(mysql_error());
	
	$line = mysql_fetch_array($result);
//if valid user
	if ((!$username=="") and (!$password=="")) {
		$pwd=$line['password'];
		if (($username==$line['username']) and (md5($password)===$pwd)) {
			//if ($line['active']=="1") {
				$_SESSION['username']=$line['username'];
				$_SESSION['logged']="1";
				$_SESSION['company_name']=$line['company_name'];
				$_SESSION['first_name']=$line['first_name'];
				$_SESSION['last_name']=$line['last_name'];
				$_SESSION['member_id']=$line['id'];
				$_SESSION['email']=$line['email'];
								
				write_log($_SERVER['PHP_SELF'],"Login success",$conn);
				if (isset($_GET['redirect'])) {
					redirect($_GET['redirect'],"");
				} else {
					redirect("usermain.php","");
				}
		} else {  
			session_destroy();
			write_log($_SERVER['PHP_SELF'],"Login fail: $username/$password",$conn);
			unset($username);
			unset($password);
			unset($_POST['username']);
			unset($_POST['password']);
			redirect("index.php?v2e=failed","");
		}	
	} else {  
			session_destroy();
			write_log($_SERVER['PHP_SELF'],"Login fail",$conn);
			redirect("index.php?v2e=failed","");
		}		
	
	mysql_close($conn);
	echo "<table width=\"100%\" height=\"100%\">";
	echo "<tr><td width=\"130\"></td><td valign=\"middle\" align=\"center\">";
	echo "&nbsp;&nbsp;Processing...<br>";
	echo "<img src=\"../images/star1.jpg\"><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p></td></tr>";

here's another function to help you out...

Code:
function logged($access_privledges) {  
	$r=false;
	if ($_SESSION['logged']==1) {
		if ($_SESSION['membertype_id']==$access_privledges) $r=true;
		if ($access_privledges==99) $r=true;
	}
	return $r;
}

and structure each secure page like this:

Code:
<?
if (!logged(99)) {
	connectDB();
	write_log($_SERVER['PHP_SELF'],"Session not started",$conn);
	redirect("index.php?v2e=timeout","");
} else {
?>
.
.
page content
.
.
<? } mysql_close($conn); ?>
 
You might try hetting a book out of the library!

Failing that, this seems to be a good resource for php tutorials. Work through the examples and you should get a basic understanding of what is going on.


Regards,

paragliding
 
Thank you all very much for your help

You r the best

Stephen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top