Help with PHP - Riddy - 19.05.2012
Hi there, I dont really know if people would help as this isnt a PHP forum, but I think I should give it a go.
What I need help on:
Currently I am editing a register script which uses PHP, I basically got a source which I have been editing to work properly, and It is going well execpt, I want the 'Username' bar to work when this 'Firstname_Lastname' format is input into the textbox or else it returns a error saying:
"Please use this format: Firstname_Lastname" on the top of the page.
The next request is, I would like the register script to save password as a SHA1 hash instead of a text hash, How can I do that?
Thank you in advance, Riddy
Re: Help with PHP -
TheJayMan - 19.05.2012
Hi, for the username you could use PHP eregi... Like this..
if(eregi("^[a-z]*_[a-z]", $username)){ // The username is in first_last format } else { // Error }
and for sha1 it is just sha1($password);
Re: Help with PHP - Riddy - 19.05.2012
What do I do with this:
$Username = $_POST['Username']; // Setting the user value
and
<? echo "Username: <input type='text' name='Username' /><br>"; ?>
Re: Help with PHP - kikito - 19.05.2012
Quote:
Originally Posted by Riddy
What do I do with this:
$Username = $_POST['Username']; // Setting the user value
and
<? echo "Username: <input type='text' name='Username' /><br>"; ?>
|
You will need always to take the data from the form, or the login / register system don't work.
Re: Help with PHP - Riddy - 19.05.2012
If I left the other to boxes empty, I need it to return as "Please put stuff in all the fields" and What about string limit?
Re: Help with PHP -
Vince - 19.05.2012
use isset() to determine if a variable contains a value. I don't think there's any particular string limit in PHP, at least not when POST'ing data. Also eregi is deprecated, use preg_match instead.
Re: Help with PHP - Riddy - 19.05.2012
Quote:
Originally Posted by Vince
use isset() to determine if a variable contains a value. I don't think there's any particular string limit in PHP, at least not when POST'ing data. Also eregi is deprecated, use preg_match instead.
|
One problem, I really dont know how to use these things, so can you give me a example of the code your telling me to use please
Re: Help with PHP - kikito - 19.05.2012
If you use the empty(never used it) function or '', it can help you out .
like
PHP код:
if(isset($_POST['user'] == "")) echo 'Please fill up the username field!';
else {
// continue the code
}
Or setup more than 1 $_POST on a if, like:
PHP код:
if(isset($_POST['user'] == '')||($_POST['password'] == '')||($_POST['e-mail'] == '')) echo 'Please fill up all fields.';
else {
// continue the code
}
Re: Help with PHP -
TheJayMan - 19.05.2012
<?php
if ($username == null){
// The variable is blank..
} else {
// It is not blank..
}
?>
For string limit, if you mean allow only a certain limit, I'd just recommend putting maxlength="30" on the input (form) and limiting the length in the database.
Re: Help with PHP -
Ricop522 - 19.05.2012
PHP код:
if(isset("Submit")) {
$Username = $_POST['Username']; // Setting the user value
$Pass = $_POST['Password']; // Setting the user value
if($Username == "/" || $Username == "\" || $Username == "_") {
echo "invalid"; exit;
}
mysql_query("INSERT INTO table (name, pass) VALUES ($Username, $Pass));
}
// Form with html
<form method = "POST" action = "index.php">
Username: <input type='text' name='Username' /><br>
Password: <input type='text' name='Password' /><br>
<input type = "submit" name = "Submit" /> <br />
</form>
Its something like that, i'm not sure if this is right, check on
www.******.com.br or w3schools about HTML and PHP scripting and your questions will be answered.
http://forum.sa-mp.com/showthread.ph...ighlight=MySQL
Check PHP part.