Jump to content

coop

Members
  • Posts

    19
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

coop's Achievements

Member

Member (2/5)

0

Reputation

  1. Thanks Darren, Could you explain why this works - I'm newish to php and some things aren't making sense. I know the difference with single and double quotes - if it's double quotes the value of the variable is parsed, but here you have " ' ' " - single quotes within double quotes. Thanks for you time. c.
  2. Hi all, I'm having real problems with this code that creates a new password for a customers account and then emails it to them (if they have forotten there password when loggin in 0). The code tests if the email is in the database which seem to work fine, then generates a random 7 character password which works, and then emails this to the email which also works. The problem is it's not being updated in the database. This has been driving me med all day so any help would be much appreicated. The code uses a database class that acts the same as the mysqli class. [pre] <?php require_once('database.php'); require('phpmailer/class.phpmailer.php'); if (!get_magic_quotes_gpc()) { foreach($_POST as $key=>$value) { $temp = addslashes($value); $_POST[$key] = $temp; } } $db = new Database('localhost','root','root','Test'); $sql = 'SELECT * FROM Customers WHERE userMail = "'.$_POST['user_Mail'].'"'; $result = $db->query($sql); $numRows = $result->num_rows; if($numRows < 1){ $noEmail = 'That email is not in the database.'; echo 'notHere=y&message='.urlencode($noEmail); }else{ $row = $result->fetch_assoc(); $username = $row["userName"]; //echo $username; $rand_string = ''; for($a=0;$a<7;$a++){ do{ $newrand = chr(rand(0,256)); } while(!eregi("^[a-z0-9]$",$newrand)); $rand_string .= $newrand; } $pwd_to_insert = md5($rand_string); $sqlUpdate = 'UPDATE Customers SET userPassword = "$pwd_to_insert" WHERE userName = "$username" AND userMail = "'.$_POST['user_Mail'].'"'; $mail = new PHPMailer(); $mail->IsSMTP(); $mail->Host = "smtp.mysite.com"; $mail->Mailer = "smtp"; $mail->From = "sales@mysite.co.uk"; $mail->AddAddress("me@mysite.com"); $mail->Subject = "Login password"; $mail->Body = "\n\n\n\nYou requeted that a new password be sent to ".$_POST['user_Mail']."\n\n"."User Name : ".$username."\n\nYour new password is : ".$rand_string."\n\n\n\nIf you have further problems please contact the mysite support staff."; $mail->WordWrap = 50; if(!$mail->Send()){ $noEmail = 'Email not sent'; echo 'Mailer Error: ' . $mail->ErrorInfo; }else{ $emailSent = 'Email sent'; echo 'email=y&message'.urlencode($emailSent); } } ?> [/pre]
  3. I tried this but no luck, and now the user variable isn't being passed. Is this the correct way tto capture the userid and then pass it ut of the function ? // //Call the functions if(isset($_POST["action"])){ switch($_POST["action"]){ case "login": $result = login($_POST['username'],$_POST['pass']); //echo "user=" . $result; echo "&user=" . $result . "&custID" . $cust_id; break; case "register": $result = register($_POST['username'],$_POST['pass'],$_POST['email']); echo $result; break; case "new_password": $result = new_password($_POST['email']); echo $result; break; } } // //Login function login($username,$pass){ GLOBAL $db,$table; $username = trim($username); $pass = md5(trim($pass)); $query = mysql_query("SELECT * FROM $table WHERE userName = '$username' AND userPassword = '$pass'"); $cust_id = mysql_query("SELECT userID FROM $table WHERE userName = '$username' AND userPassword = '$pass'"); return mysql_num_rows($query); return $cust_id; }
  4. Hi all, I'm developing a shopping cart application using php/MySQL and a flash front end but I'm syure the information I'm looking for would e the same if it was html. I wanted to capture the Customer_id of a customers table when people login, so when people login in successfully there customer_id will be captured and sent back to flash (if I can work out how to echo the result I can send it back to flash) //Call the functions if(isset($_POST["action"])){ switch($_POST["action"]){ case "login": $result = login($_POST['username'],$_POST['pass']); echo "user=" . $result; break; case "register": $result = register($_POST['username'],$_POST['pass'],$_POST['email']); echo $result; break; case "new_password": $result = new_password($_POST['email']); echo $result; break; } } // //Login function login($username,$pass){ GLOBAL $db,$table; $username = trim($username); $pass = md5(trim($pass)); $query = mysql_query("SELECT * FROM $table WHERE userName = '$username' AND userPassword = '$pass'"); $id_query = mysql_query("SELECT userID FROM $table WHERE userName = '$username' AND userPassword = '$pass'");// My attempt to capture the id return mysql_num_rows($query); // capture the customer_id }
  5. Hi all, I'm new to php but come from using Actionscript, so I understand alot of what PHP has to offer. I'm learning php so I can use it with Flash - I'm using a friends of Ed book which is good but some things are unexplained. This class is from the book and is used to connect to the database - I understand the idea of classes and how they work but could someone give a quick explanation of how this class is supposed to work, and do you think it is better to use a class for this or use seperate statments, (which I feel more comfortable using, ,cos I can understand them better. ) such as $con = mysql_connect('localhost','root','root'); <?php class Database { protected $host; protected $user; protected $pwd; protected $dbName; protected $flash; protected $dbLink; protected $result; protected $resultObj; function __construct($host, $user, $pwd, $dbName, $flash=1){ $this->host = $host; $this->user = $user; $this->pwd = $pwd; $this->dbName = $dbName; $this->flash = $flash; $this->connect(); } public function connect() { try { $this->dbLink = @mysqli_connect($this->host, $this->user, $this->pwd, $this->dbName); if (!$this->dbLink) { throw new Exception ("Couldn't connect $this->user to $this->dbName"); } } catch (Exception $e) { echo $this->flash ? 'error='.urlencode($e->getMessage()) : $e->getMessage(); exit(); } return $this->dbLink; } public function query($query) { try { $this->result = mysqli_query($this->dbLink, $query); if (!$this->result) { throw new Exception ('MySQL Error: ' . mysqli_error($this->dbLink)); } } catch (Exception $e) { echo $this->flash ? 'error='.urlencode($e->getMessage()) : $e->getMessage(); exit(); } $this->resultObj = new MyResult($this->result); return $this->resultObj; } public function close(){ mysqli_close($this->dbLink); } } class MyResult { protected $theResult; public $num_rows; function __construct($r) { if (is_bool($r)) { $this->num_rows = 0; } else { $this->theResult = $r; $this->num_rows = mysqli_num_rows($r); } } function fetch_assoc() { $newRow = mysqli_fetch_assoc($this->theResult); return $newRow; } } ?>
  6. Thanks obsidian, thats a great help
  7. Hi all, Still new to PHP, but with a ActionScript background - I'm trying to run through this class which is for IPN with Paypal. I sort of get the idea but I'm trying to get a better understanding, could anyone explain this code. I know it's a big ask but any help would br greatly appreciated. <?php class paypal_ipn{ var $paypal_post_vars; var $paypal_response; var $timeout; var $error_email; function paypal_ipn($paypal_post_vars) { $this->paypal_post_vars = $paypal_post_vars; $this->timeout = 120; } function send_response(){ $fp = @fsockopen( "www.paypal.com", 80, &$errno, &$errstr, 120 ); if (!$fp) { $this->error_out("PHP fsockopen() error: " . $errstr , ""); } else { foreach($this->paypal_post_vars AS $key => $value) { if (@get_magic_quotes_gpc()) { $value = stripslashes($value); } $values[] = "$key" . "=" . urlencode($value); } $response = @implode("&", $values); $response .= "&cmd=_notify-validate"; fputs( $fp, "POST /cgi-bin/webscr HTTP/1.0\r\n" ); fputs( $fp, "Content-type: application/x-www-form-urlencoded\r\n" ); fputs( $fp, "Content-length: " . strlen($response) . "\r\n\n" ); fputs( $fp, "$response\n\r" ); fputs( $fp, "\r\n" ); $this->send_time = time(); $this->paypal_response = ""; // get response from paypal while (!feof($fp)) { $this->paypal_response .= fgets( $fp, 1024 ); if ($this->send_time < time() - $this->timeout) { $this->error_out("Timed out waiting for a response from PayPal. ($this->timeout seconds)" , ""); } } fclose( $fp ); } } function is_verified() { if( ereg("VERIFIED", $this->paypal_response) ) return true; else return false; } function get_payment_status() { return $this->paypal_post_vars['payment_status']; } function error_out($message, $em_headers){ $date = date("D M j G:i:s T Y", time()); $message .= "\n\nThe following data was received from PayPal:\n\n"; @reset($this->paypal_post_vars); while( @list($key,$value) = @each($this->paypal_post_vars)) { $message .= $key . ':' . " \t$value\n"; } mail($this->error_email, "[$date] paypay_ipn notification", $message, $em_headers); } } ?>
  8. Hi all, I'm more use to ActionScript, so I'm getting a little confused with php syntax. What does the "->" mean is this same as the dot syntax in ActionScript where you would write "this.paypal_post_vars = $paypal_post_vars" function paypal_ipn($paypal_post_vars)} $this->paypal_post_vars = $paypal_post_vars; $this->timeout = 120; }
  9. phpMailer problem Hi all, This is part of the code I'm using to create a new password and I then wanted to email the new PW. This code was working fine a few weeks back but now I'm not getting the emails, I'm I doing something wrong. I did want to do do it using the "$email", but I carn't even get it to work using a full address - "c.dickinson40@ntlworld.com" [code] //New password function new_password($email){   GLOBAL $db,$table;   $email = trim($email);   $query1 = mysql_query("SELECT userName from $table WHERE userMail = '$email'");   if(mysql_num_rows($query1)<1){       return "error=email not present into database";   }   $row = mysql_fetch_array($query1);   $username=$row["userName"];   $query = mysql_query("SELECT * FROM $table WHERE userName = '$username' AND userMail = '$email'");   $rand_string = '';   // ---   // generating a random 8 chars lenght password   // ---   for($a=0;$a<7;$a++){       do{         $newrand = chr(rand(0,256));       } while(!eregi("^[a-z0-9]$",$newrand));       $rand_string .= $newrand;   }   $pwd_to_insert = md5($rand_string);   $new_query = mysql_query("UPDATE $table SET userPassword = '$pwd_to_insert' WHERE userName = '$username' AND userMail = '$email'");   //return "userName=$username&new_pass=$rand_string";     require("phpmailer/class.phpmailer.php"); $mail = new PHPMailer(); $mail->IsSMTP(); // telling the class to use SMTP $mail->Host = "stmp.ntlworld.com"; // SMTP server $mail->SMTPAuth = true; $mail->From = "coopersimon@postmaster.co.uk"; $mail->AddAddress("c.dickinson40@ntlworld.com"); $mail->Subject = "Login password"; $mail->Body = "\n\n\n\nYou requeted that a new password be sent to this email address\n\n"."User Name : ".$username."\n\nYour new password is : ".$rand_string."\n\n\n\nIf you have further problems please contact the moretype support staff."; $mail->WordWrap = 50; if(!$mail->Send()){   echo "Message was not sent";   echo "Mailer Error: " . $mail->ErrorInfo; }else{   echo "Message has been sent"; }   } //"\n\n\n\n User Name : ".$username."\n\n Your new password is : ".$rand_string; ?> [/code] 
  10. Orio, the password generating works, it's just this part of the code where I'm trying to send it by email. [code=php:0]   //return "userName=$username&new_pass=$rand_string"; // this send it back to the flash app.       // but I wanted to send it by email ?         $to = $email;         $subject = "Password";         $body = $rand_string;         if (mail($to, $subject, $body)) {           echo("Message successfully sent!");           } else {           echo("Message delivery failed...");           }   } } [/code] this bit sends it back to the LoadVars object in flash that called the function. When I do it this way the password is generated and shown in the falsh app., so I sure that the password generation works, but I  want to send t by email instead of showing it in flash. [code=php:0] return "userName=$username&new_pass=$rand_string"; [/code] 
  11. Hi all, I'm working on a User authentication system using php and mysql with a flash front end. Everything works fine apart from generating the new password and sending it to email of the person requesting the new password. This is part of the php that generates the new password and updates MySQL. [code=php:0] //New password function new_password($email){   GLOBAL $db,$table;   $email = trim($email);   $query1 = mysql_query("SELECT userName from $table WHERE userMail = '$email'");   if(mysql_num_rows($query1)<1){       return "error=email not present into database";   }   $row = mysql_fetch_array($query1);   $username=$row["userName"];   $query = mysql_query("SELECT * FROM $table WHERE userName = '$username' AND userMail = '$email'");   $rand_string = '';   // ---   // generating a random 8 chars lenght password   // ---   for($a=0;$a<7;$a++){       do{         $newrand = chr(rand(0,256));       } while(!eregi("^[a-z0-9]$",$newrand));       $rand_string .= $newrand;   }   $pwd_to_insert = md5($rand_string);   $new_query = mysql_query("UPDATE $table SET userPassword = '$pwd_to_insert' WHERE userName = '$username' AND userMail = '$email'");   if(!$new_query){       return "error=unable to update value";   }else{   //return "userName=$username&new_pass=$rand_string"; // this send it back to the flash app.       // but I wanted to send it by email ? $to = $email; $subject = "Password"; $body = $rand_string; if (mail($to, $subject, $body)) {   echo("Message successfully sent!");   } else {   echo("Message delivery failed...");   }   } } [/code]
  12. coop

    Flash/php

    Flash/php Hi all, I work mainly in flash and am now starting to use php for server side stuff, does anyone know of good tutorials or books in this area. c.
  13. Hi all, I have this function for checking valid emails but I'm a bit stuck with some of the code [code] function valid_email($email){   // check if email is valid   if( !eregi(“^[a-z0-9]+([_\\.-][a-z0-9]+)*”.”@([a-z0-9]+([\.-][a-z0-9]+))*$”,$email, $regs)){     return false;   } else if( gethostbyname($regs[2]) == $regs[2] ){       // if host is invalid       return false;   } else {       return true;   } } [/code] it's this bit I dont understand [code] !eregi(“^[a-z0-9]+([_\\.-][a-z0-9]+)*”.”@([a-z0-9]+([\.-][a-z0-9]+))*$”,$email, $regs) [/code] I know eregi is the case insensitive regular expression match, but it's the rest I dont understand, could someone explain.
  14. User Authentication Hi all, Still new to php so I'll try and explain my problem. I'm trying to produce a User authentication page so a user can log in with a user name and password. I've worked out setting up the database and adding new users to the database. So now people can log into pages using there user_id and password which is checked on the MySQL database. The problem comes when a user forgets there password and I wanted to send it to the email that they used in the registration. I'm using md5(), so the database contains a 32-character hash, it is possible to transfer this back to plain text.    Any help would be greatly apperciated. I'm usin fFlash for the front end but any help or tutorials would be fine. c.
  15. coop

    php usage

    Hi all, still finding my feet with php and the basic stuff. I have this code that connects to the database and creates a table then closes the connection. Is it right to then open the connection and populate the tables with infomation. If I try to fill the tables within the code that creates the tables the database is created but the table isn't. I know this is a really basic question, but I'm using phpmyAdmin where I can see the database is created and the tables, but is it possible to see the information I inserted. [CODE] <?php $dbhost ='localhost'; $dbusername ='root'; $dbpassword = 'root'; $dbname = 'first'; //connect to the mysql database server. $link = mysql_connect($dbhost,$dbusername,$dbpassword); if(!$link){ die("could bot connect:".mysql_error()); }else{ echo"connected to server <br>"; } //create database $database = $dbusername."_".$dbname; $query  = mysql_query("CREATE DATABASE $database"); if(!$query){ die("could not create database:".mysql_error()); }else{ echo"database created <br>"; } //create tables mysql_select_db($database)or die("unable to select database".mysql_error()); $query="CREATE TABLE contacts (id int(6) NOT NULL auto_increment, first VARCHAR(15) NOT NULL, last VARCHAR(15) NOT NULL, email VARCHAR(30) NOT NULL, web VARCHAR(30) NOT NULL, PRIMARY KEY (id), UNIQUE id (id), KEY id_2 (id))"; mysql_query($query); mysql_close(); ?> // // <?php $link = mysql_connect($dbhost,$dbusername,$dbpassword); if(!$link){ die("could bot connect:".mysql_error()); }else{ echo"connected to server <br>"; } mysql_select_db($database)or die("unable to select database".mysql_error()); $query ="INSERT INTO contacts VALUES('John','Smith','johnsmith@somewhere.com','http://www.somewhere.com')"; mysql_query($query); mysql_close(); ?> [/CODE]
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.