Tema: no entiendo.
Ver Mensaje Individual
  #1 (permalink)  
Antiguo 13/11/2002, 15:30
fosforito
Invitado
 
Mensajes: n/a
Puntos:
no entiendo.

para hacer un signup o registro como le coloco los script de aqui abajo:

todo esto lo salvo como registro.php?
---------------------------------------------
<form name=registration action="signup.php" method="get">
Username:
<input name="signupusername" type="text" width="10"><BR>
Password:
<input name="signuppassword" type="password" width="10"><BR>
Verify your password:
<input name="signuppasswordverify" type="password" width="10"><BR>
Email Address:
<input name="emailaddress" type="text" width="10"><BR>
<INPUT TYPE=SUBMIT VALUE="Sign Up">
</form>
------------------------------------------------------------

y para la funcion le salvo con un nombre de archivo aparte?
o esque va todo en uno ,el de arriva con este de abajo?
--------------------------------------------
<?
// User Sign Up PHP Script
//
// This script validates information, saves it to the database
// displays it to them
// and sends it to them via email
//
// vars:
// $signupusername
// $signuppassword
// $signuppasswordverify
// $signupemailaddress
//
// Note have to use signup* vars initially to make it
// clear to ourselves that
// we're dealing with signupotherwise

// Include common variables and message text
// include 'zcommon.php';
// Normally these would come from an include file. Since this is
// an example, we'll just put them here:
// db login parameters

$dbhost = "localhost";
$dbuser = "mysqluser";
$dbpassword = "password";
$db = "dbname";
$sysadminemail = "youremail";


// null out cookies if new user
// null out cookies at start of sign in routine
// all cookies begin with "ck_" to indicate that they are a cookie
// helps troubleshoot mysterious cookie errors
// note on using cookies.
// MUST BE SET before ANY http output.
// They TRAVEL in the http HEADER so have to go first.
setcookie ("ck_user", "");
setcookie ("ck_password", "");
setcookie ("ck_user_id", "");

// 0th check that passwords match
if($signuppassword!=$signuppasswordverify) {
create_error_page_passwordsnotmatch();
}
else {
// their passwords match so enter next validation stage
// first test that their username isn't already in use

// Connecting, selecting database
$link = mysql_connect("$dbhost", "$dbuser", "$dbpassword")
or die("Could not connect");
// select the database
mysql_select_db("$db")
or die("Could not select database");
// try and select the username that the user entered to see if
// it is already in the db
$query = "SELECT username "
. " FROM users "
. " WHERE username='$signupusername'";

$result = mysql_query($query)
or die("Query failed at username unique testing stage.");

// logic -- if the num_rows is 1 then the username is already
// in use and they have to choose another
$num_rows = mysql_num_rows($result);
// don't need to get it -- its the same as what we already have

// num_rows can't ever be >= to 1 since unique constraint
// on the column of data
if ($num_rows == 1) {
create_error_page_usernameinuse();
}
else {
// NOTE -- Depending on how you want to define
// a valid password (5 chars, 6 chars
// plus a number, etc), that would go here

//Capture the ipaddress and call MD5
$ipaddress = getenv ("REMOTE_ADDR");
$encryptedpassword = md5($signuppassword);

//try and add them to the database
$query = "INSERT INTO users "
. " ( username, password, date, ipaddress ) "
. " VALUES ('$signupusername','$encryptedpassword', "
. " NOW(), '$ipaddress')";

//execute the query
$result = mysql_query($query)
or die("Query failed at user insertion stage.");

//now query the db back for the user_id variable
$query = "SELECT user_id "
. " FROM users "
. " WHERE username='$signupusername'";

// get the result
$result = mysql_query($query)
or die("Query failed at userid retrieval stage.");

//get the user_id from the result
$num_rows = mysql_num_rows($result);
$row = mysql_fetch_array($result);
$user_id = $row[0];

// send the cookies now. MUST BE FIRST THING OUTPUT
setcookie ("ck_username", "$signupusername");
setcookie ("ck_password", "$signuppassword");
setcookie ("ck_user_id", "$user_id");

//Define the $title variable for the page title
$title = "Thanks for Signing Up!";

//Set up the page header
PrintPageHeader("$title");

//Print out the body of the page
// Note that some basic html formatting is used
// here to make it look better

print "<TABLE WIDTH=728 BGCOLOR=WHITE><TR><TD>";
print "<H1>Thank You...</H1>";
print "<HR>";
print "<CENTER>Thanks for playing! ";
print "Seriously, we appreciate your signing";
print "up.</CENTER><BR><BR>";
print "Here is the information that you entered:";
print "<UL>";
print "<LI>Username: $signupusername</LI>";
print "<LI>Password: $signuppassword</LI>";
print "<LI>Email Address: $emailaddress</LI>";
print "</UL>";
print "<BR>We have also emailed this to the email ";
print "address you gave us.<BR>";
print "</TD>";
print "</TR>";
print "<TABLE>";

//Usually you want to add a link to your
// application's home page here.
// Left as an exercise for the reader.

//handle sending out the email if we got an email address!
if ($emailaddress != "") {
// compose the email
$to = $emailaddress;
$subject = "Your IMSaver Account";
$message = "Hi there, "
. "Your account has been created and is ready for use."
. ""
. ""
. "Your username is: $signupusername"
. "Your password is: $signuppassword"
. ""
. "Thanks for signing up for YOURNAMEHERE."
. "http://YOURURLHERE/"
. ""
. "YOURNAMEHERE";
// send the email
mail($to, $subject, $message, "From: [email protected]", "[email protected]");
}

//Set up the footer of the page
PrintPageFooter("");
}
}

// start of functions

function PrintPageHeader ($title) {
print "<HTML>";
print "<HEAD>";
print "<TITLE>";
print "$title";
print "</TITLE>";
print "</HEAD>";
print "<BODY>";
}

function PrintPageFooter ($title) {
print "</BODY>";
print "</HTML>";
}


function create_error_page_passwordsnotmatch() {
//Define the $title variable for the page title
$title = "We're Sorry But You're Passwords Don't Match!";

//Set up the page header
PrintPageHeader("$title");

print "<TABLE WIDTH=728 BGCOLOR=WHITE><TR><TD>";
print "<H1>We're Sorry...</H1>";
print "<HR>";
print "<BR>";
print "We're sorry but You didn't enter matching passwords. ";
print "&nbsp;Please make sure that you enter your password ";
print "in the Password field and the Verify Password fields ";
print "and that both are the same.<BR><BR>";
print "Please press the back button and make sure that the ";
print "passwords match.";

// close container table
print "</TD></TR></TABLE>";

//Set up the footer of the page
PrintPageFooter("");
}


function create_error_page_usernameinuse() {
//Define the $title variable for the page title
$title = "We're Sorry But that Username is Already in Use...";

//Set up the page header
PrintPageHeader("$title");

print "<TABLE WIDTH=728 BGCOLOR=WHITE><TR><TD>";

print "<H1>We're Sorry...</H1>";
print "<HR>";
print "<BR>You entered a Username that another person is using";
print "<BR>Press Back to try again.";
// close container table
print "</TD></TR></TABLE>";

//Set up the footer of the page
PrintPageFooter("");
}

?>


o esque todo los script le hago en uno solo y le salvo como registrarse.php no se si me entendieron.