View Full Version : PHP Script help
RizlaUK
02-02-2008, 11:32 AM
Hi guys, iv been asked to make a login system for a AMS project that will use some PHP and a MYSQL database to store registration information, iv got the AMS/MYSQL stuff under control but what i need is a basis of a PHP script that will:
1. receive email, username and hardware id from user (via HTTP.Submit)
2. generate a random password (
2. save email, username,hardware id and generated password to MYSQL
3. send email, username,hardware id and generated password back to users email addy
4. return status of the above back to AMS (pass or fail)
also some advice on making a PHP script secure (hacker safe)
any help/advice would be great
srussell
02-03-2008, 08:34 AM
See if any of this helps... :yes This was from a form to create a new account for a online slideshow service that I wrote using PHP
There are parts here to connect to the database, insert the form values into the database and generate a random member id (use this as a random password), and send an automated emial message to the use.
Steve
<?php
- DATABASE CONNECTION
$host = "localhost"; // server to connect to.
$db_name = "database"; // the name of the database.
$db_user = "username"; // mysql username to access the database with.
$db_pass = "password"; // mysql password to access the database with.
$table = "tablename"; // the table that this script will set up and use.
- CHECK FOR EMPTY FIELDS
if (($values['firstname'] != null) and ($values['lastname'] != null) and ($values['username'] != null) and ($values['password'] != null) and ($values['password2'] != null) and ($values['lastname'] != email))
-DEFINE FIELD VARIABLES AND SET DATA
$firstname = ucfirst(strtolower($values['firstname']));
$lastname = ucfirst(strtolower($values['lastname']));
$username = $values['username'];
$password = $values['password'];
$password2 = $values['password2'];
$email = $values['email'];
$agree = $values['agree'];
$notices = $values['notices'];
if ($notices == "") {
$notices = "No";
} else {
$notices = "Yes";
}
$memberstatus = "Free";
$slideshows = 2;
// CHECK IF USERNAME IS TAKEN
$checkuser = "select UserName from $table where UserName = '".$username."';";
$qry = mysql_query($checkuser) or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry);
if ($num_rows != 0) {
$errors = "Sorry, the User Name ".$username." is already taken. Please try a different User Name";
} else {
$today = date("m-d-Y");
- CREATE PASSWORD HASH
$passwordhash = md5($password);
- CREATE A MEMBER ID
srand((double)microtime()*1000000);
$memberid = rand(100000,999999);
$fn = substr($firstname, 0, 1);
$fn = strtoupper($fn);
$ln = substr($lastname, 0, 1);
$ln = strtoupper($ln);
- INSERT THE DATA INTO THE TABLE
$insert = mysql_query("insert into $table values ('NULL', '".$today."', '".$fn.$ln."', '".$memberid."', '".$email."', '".$firstname."', '".$lastname."', '".$username."', '".$password."', '".$passwordhash."', '".$notices."', 'Free', '2', '')") or die("Could not insert data because ".mysql_error());
- EMAIL CONTENT
$subject = "Your account information";
$message = "Here is your account information.
First Name: $firstname
Last Name: $lastname
User Name: $username
Password: $password
Member ID: $memberid
Member Status: Free
Available Slideshows: $slideshows
Please visit http://www.iireproductions.com/design/ss_signin.php to sign in.
Thanks!
Site Administrator
This is an automated response, please do not reply!";
- SEND THE EMAIL
mail($email, $subject, $message, "From: iiRe Design<slideshows@iireproductions.com>");
}
?>
RizlaUK
02-03-2008, 02:33 PM
Thats great, i can certainly make use of this
i have been palying with some php and almost have what i needed but this is perfect, Thanks again :yes
srussell
02-03-2008, 09:43 PM
No problem!, Glad some of this helps. I had a couple of music projects that used the AMS database connectivity, but I can't seem to find them at the moment... I'll keep looking.
Obviously , you'll have to have a MYSQL table setup on the server somewhere to read/post values and change the appropriate values... but at least it's a start.
Imagine Programming
05-08-2008, 02:05 PM
Srussel, what do you think about this:
<?php
if(isset($_POST['Submit'])){
if(empty($_POST['text'])){
echo('Please fill in some text!');
}
if(empty($_POST['for_rood'])){
$_POST['for_rood'] = 255; //forground red RGB value if empty set
}
if(empty($_POST['for_groen'])){
$_POST['for_groen'] = 255; //forground green RGB value if empty set
}
if(empty($_POST['for_blauw'])){
$_POST['for_blauw'] = 255; //forground blue RGB value if empty set
}
if(empty($_POST['bg_rood'])){
$_POST['bg_rood'] = 255; //background red RGB value if empty set
}
if(empty($_POST['bg_groen'])){
$_POST['bg_groen'] = 255; //background green RGB valuef empty set
}
if(empty($_POST['bg_blauw'])){
$_POST['bg_blauw'] = 255; //background blue RGB value if empty set
}
if(empty($_POST['font_size'])){
$_POST['font_size'] = 14; //if empty post, set fontsize
}
if(empty($_POST['width'])){
$_POST['width'] = 300; //if empty post, set width
}
if(empty($_POST['height'])){
$_POST['height'] = 150; //if empty post, set Height
}
$fr = $_POST['for_rood'];
$fg = $_POST['for_groen'];
$fb = $_POST['for_blauw'];
$br = $_POST['bg_rood'];
$bg = $_POST['bg_groen'];
$bb = $_POST['bg_blauw'];
$text = $_POST['text'];
$fs = $_POST['font_size'];
$w = $_POST['width'];
$h = $_POST['height'];
$angleTXT = 0; // De random angle of the image, here set as straight
$font = "font.ttf"; // font you want to use, its in the same folder as this script
$imgCreate = ImageCreate($w, $h); // Image create values
$imgBg = ImageColorAllocate($imgCreate, $br, $bg, $bb); // Background color (specified above)
$imgFg = ImageColorAllocate($imgCreate, $fr, $fg, $fb); // Text Color (specified above)
ImageFill($imgCreate, 1, 1, $imgBg); // Fill the image with the background color
$Tw = 5;
$Th = $h * 0.75; //calculate the middle of the background (not perfect yet:P)
Imagettftext($imgCreate,$fs,$angleTXT,$Tw,$Th,$img Fg,$font,$text) or die ("Please refresh");
// Imagettftext (int im, int size, int angle, int x, int y, int col, string fontfile, string text) = how it works =)
$path_watermerk = "watermerk.gif"; //Path to the watermark
$watermerk = imagecreatefromgif($path_watermerk);//creating image from the specified *.gif (for the watermark)
$watermerk_width = imagesx($watermerk); //setting the wirdth of the watermark
$watermerk_height = imagesy($watermerk); //setting the height of the watermark
$xas = $w - $watermerk_width -5; //making a margin (positioning)
$yas = $h - $watermerk_height -5; //making a margin (positioning)
imagecopymerge($imgCreate, $watermerk, $xas, $yas, 0, 0, $watermerk_width, $watermerk_height, 100); //merging the background&text with the watermark
header('Content-type: image/jpeg'); //setting the Content type header
ImageJPEG($imgCreate); // Creating the JPEG image
ImageDestroy($imgCreate); // Making image ready to use
//warning, in my situation, firefox didn't let me save the document, Internet Explorer did so
}
else{
?>
<img src="example.bmp">
<form method="post" name="post" action="">
Text: <br><input type="input" value="The text" name="text"><br><br>
Forground - red: <br><input type="input" value="1" name="for_rood"><br>
Forground - green: <br><input type="input" value="255" name="for_groen"><br>
Forground - blue: <br><input type="input" value="1" name="for_blauw"><br><br>
Background - red: <br><input type="input" value="1" name="bg_rood"><br>
Background - green: <br><input type="input" value="1" name="bg_groen"><br>
Background - blue: <br><input type="input" value="1" name="bg_blauw"><br><br>
Font-Size: <br><input type="input" value="14" name="font_size"><br>
Width: <br><input type="input" value="300" name="width"><br>
Height: <br><input type="input" value="150" name="height"><br><br>
<input type="submit" value="Create image" name="Submit">
<input type="reset" value="reset" name="image">
</form>
<?}?>
Result:
http://black.c-wolf.nl/img/example.bmp
sorry for the dutch colorl words:P i can't help it:P
//warning, in my situation, firefox didn't let me save the document, Internet Explorer did save it as unnamed.bmp (you can type in a name yourself) but firefox saves the php file. it wont save the php script but the html form as *.php (luv serverside :D)
Powered by vBulletin™ Version 4.0.6 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.