View Full Version : Setting up PHP client login
AFFIX
11-02-2006, 03:42 PM
I want to be able to have clients sign up for an account on my site, and have them be able to sign into their own area. Any ideas?
Whats their own area consist of it...is it content they provide? Anyway, having them sign up for an account...firstly, allow them to select a user name, once they have entered it, compare against the database to make sure someoen else isnt already using that user name. If its available, then save, if not, send a message back letting the user know its taken. Then once all that is set up, when they sign in....direct them to that section..
AFFIX
11-03-2006, 01:07 AM
how do i go about setting all that up, i am new to php with flash and server basde operations
The things you need to be familiar with, in Flash.... LoadVars(), understand of scope, and for the love of god dont use scenes. This is a very basic sample script which checks if a username already exists, if it does send that message back to flash, if it doesnt, register that user and send email notifacation.
<?php
$table = "YourTableNameHere";
$username = "YourDatabaseUserNameHere";
$password = "YourDatabasePasswordHere";
$database = "YourDatabaseNameHere";
//-------connect to database
mysql_connect("localhost", $username, $password) or die("Could not connect to database");
mysql_select_db($database) or die("Could not select database");
$colum = $_POST['username'];
$query = "SELECT * FROM $table WHERE username='" . $colum . "'";
$myQuery = mysql_query($query);
$row = mysql_fetch_array($myQuery);
echo "&name=".$colum;
echo "&count=".count($row);
if ( count($row) > 1 ) {
echo "&mess=User Name Exists, Try Again&";
exit();
} else {
mysql_connect("localhost", $username, $password) or die("Could not connect to database");
mysql_select_db($database) or die("Could not select database");
$uname = $_POST['username'];
$pass = $_POST['pword'];
$query = "INSERT INTO temp_register VALUES ('$pass', '$uname')";
mysql_query($query);
//-------------------------------------
// the below code set the headers. There can be a bit difficult to understand fully.
// Information about them and all the commands below can be found at the PHP manual
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: Some Person <addy@domain.com>" . "\r\n";
//------------------------------
// gets variables for email
$to = "addy@domain.com"; //inset the email address it goes to here
$subject = "New Registered User";
$message = "You have a new registered user.";
if ($message != "") { //this checks to make sure someone didn't visit the page manually by making sure message_txt is not empty
$ok = mail($to, $subject, $message, $headers); //this line sends the mail and returns true or false
if ($ok) {
echo "&mess=ok&"; //if mail was send print to the screen "&server_mes=ok"
} else {
echo "&mess=fail&"; // if mail was NOT sent, print to the screen "&server_mes=fail"
}
}
//Email to User
// gets variables from flash
$toa = $email; //inset the email address it goes to here
$subjecta = "New Registered User";
$messagea = "Thank you for your registration";
if ($messagea != "") { //this checks to make sure someone didn't visit the page manually by making sure message_txt is not empty
$ok = mail($toa, $subjecta, $messagea, $headers); //this line sends the mail and returns true or false
if($ok) {
echo "&mess=ok&"; //if mail was send print to the screen "&server_mes=ok"
} else {
echo "&mess=fail&"; // if mail was NOT sent, print to the screen "&server_mes=fail"
}
}
}
?>
Its not perfect but it gets the job done. In Flash you'd have a loadvars() object sending a username and password.
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.