Jump to content

phporcaffeine

Members
  • Posts

    361
  • Joined

  • Last visited

    Never

Everything posted by phporcaffeine

  1. That's how it usually happens, you send a ticket, they fix it and usually don't respond. Congrats.
  2. Great, suggestion! The class I wrote above is, as is most of my work, in the spirit of being database agnostic. If however, you are using MySQL and you have levenshtein or metaphone UDF's compiled in MySQL (or non-compiled UDF's), I would also advocate calculating distal values using clauses in the query. Here is a simple way to add a levenshtein function to MySQL without recompiling any binaries: CREATE FUNCTION levenshtein( s1 VARCHAR(255), s2 VARCHAR(255) ) RETURNS INT DETERMINISTIC BEGIN DECLARE s1_len, s2_len, i, j, c, c_temp, cost INT; DECLARE s1_char CHAR; -- max strlen=255 DECLARE cv0, cv1 VARBINARY(256); SET s1_len = CHAR_LENGTH(s1), s2_len = CHAR_LENGTH(s2), cv1 = 0x00, j = 1, i = 1, c = 0; IF s1 = s2 THEN RETURN 0; ELSEIF s1_len = 0 THEN RETURN s2_len; ELSEIF s2_len = 0 THEN RETURN s1_len; ELSE WHILE j <= s2_len DO SET cv1 = CONCAT(cv1, UNHEX(HEX(j))), j = j + 1; END WHILE; WHILE i <= s1_len DO SET s1_char = SUBSTRING(s1, i, 1), c = i, cv0 = UNHEX(HEX(i)), j = 1; WHILE j <= s2_len DO SET c = c + 1; IF s1_char = SUBSTRING(s2, j, 1) THEN SET cost = 0; ELSE SET cost = 1; END IF; SET c_temp = CONV(HEX(SUBSTRING(cv1, j, 1)), 16, 10) + cost; IF c > c_temp THEN SET c = c_temp; END IF; SET c_temp = CONV(HEX(SUBSTRING(cv1, j+1, 1)), 16, 10) + 1; IF c > c_temp THEN SET c = c_temp; END IF; SET cv0 = CONCAT(cv0, UNHEX(HEX(c))), j = j + 1; END WHILE; SET cv1 = cv0, i = i + 1; END WHILE; END IF; RETURN c; END//
  3. Alright, now that I see what you're trying to do - on with the thrashing; I've never been a fan of using PHP, natively, for mass emailing. Among many reasons; the typical mail server that PHP is set to use on an average third party hosted web server, is almost never, never setup the way you would wan't a mass emailing mail server to be setup. Maybe 3 -4 years ago, I would have spent the time to craft a solution but there are way too many alternatives available today. Additionally, with the CAN SPAM Act, it pays to use a service designed to handle mass mailing. Google: Constant Contact Aweber iContact MailChimp
  4. Yes, I have tried it with a > 3,000 record set. It isn't hateful, as long as your not trying to match blob's or longtext's .... as long as you stick to the traditional 255 .. varchar length, it seems to be relatively tolerable. Again, though, as you eluded to, metaphone and levenshtein and math-intense constructs. So it can be be super expensive in loops. You could eliminate the scoring mechanism (levenshtein) and just do a simple <> match, and that would reduce calc time. If you go that route though, I would just switch to pattern matching altogether.
  5. Right, so what mysql_real_escape_string() does is escape any special entities that MySQL, specifically, would require, that have not previously been escaped in the string. If you're inserting binary data, you must use it. It really is a good idea to use before sending untrusted data into a query. http://php.net/manual/en/function.mysql-real-escape-string.php
  6. This works just fine: <?php $salt = "asdfghjkl"; $user_input = 'mypassword'; $password = crypt('mypassword', $salt); if (crypt($user_input, $salt) == $password) { echo "Password verified!"; } else { echo "unsuccessful"; } ?> Notice that I specifically set $user_input. So if it didn't work for you, it would indicate that you're not setting the $user_input variable.
  7. When using crypt, you should always use a salt. Using crypt() without a salt can produce varying and inconsistent results. Also, while function but as a matter of practice, you should reference baked-in constructs in lowercase form ( crypt() Vs. CRYPT() ), unless otherwise noted by the PHP manual. Try this: <?php $salt = "asdfghjkl"; $password = crypt('mypassword', $salt); if (crypt($user_input, $salt) == $password) { echo "Password verified!"; } else { echo "unsuccessful"; } ?> BTW: While fine for learning, I would not consider the above as a login method for a production system. There are better, more secure ways of doing authentication.
  8. yes, no and maybe so .... You may run up against the SCRIPT TIMEOUT (default is 30 seconds) ... If your script executes a shell command ( exec(), virtual() ) - then the shell command will run as long as the OS allows it to run, regardless of your web browser ... We'd really need to know more about what you're trying to do. Regardless, I can't picture a scenario where you would need to do what you're talking about, or at least in the manner that you're talking about. As far as monitoring .... if you're on a Linux server you could watch the php process with "ps ax" or "top"; on Windows - Taks Manager. That is just watching the process though. Not sure what you're trying to 'watch'.
  9. I can't post/contribute in the code repo forum, so I'll post it here and maybe a mod will move it for me? Anyway, this is an algorithm for phonetic search scoring. Basically, it will evaluate a search string against an array of strings (list) and then return an array of ranked results from the list, in order of phonetic likeliness to the search string. In the returned array, the key is the score, the closer to 0, the more likely the phonetic match is; 0 being an exact match. Note: this is not pattern matching, this will match phonetic likeliness only. This is built around the English language as it stands, I am working on multi-lingual considerations. <?php /** * @NAME: Phonetic Search Score * @AUTHOR: Ryan Huff - MyCodeTree.com * @COPYRIGHT: (C)2011 * * The idea here is to supply a list (array) of strings (pressumably from a database * record set) and a single string. The class is designed to return an array of results * with X number of strings from the list that are the closest or equal phonetic * matches to the single string, ranked in order of closest phonetic match. * * The uniqueness of the Phonetic Search Score is the method in which it scores matches. The * scoring is based on the phonetic likeness of the single search string and each string * in the list, and is ranked accordingly. Scoring is not based on string length or * pattern matching like traditional REGEX pattern searching. * * A practical use for this would be a scenario where a user types in a search string, and * then the Phonetic Search Score provides a list of matches, ranked in order of their * phonetic likeliness to the search string. In the returned array, the key is the score, * the closer the key\score is to 0, the more likely the phonetic match is; 0 being an * exact match. * * An example use case is provided below. If you have any questions about the Phonetic * Search Score, you can contact me at [email protected] * */ class matcher { var $searchCriteria = NULL; //TEXT TO SEARCH FOR var $searchSet = array(); //SET TO SEARCH WITHIN var $numberOfMatches = 5; //NUMBER OF MATCHES TO RETURN var $removalChars = array('.','?','!','@','*','&','%','$','#',',',';',':','"','\''); //PUNCTUATION TO REMOVE var $returnMatches = array(); function scorer() { if (is_array($this->searchSet) && !empty($this->searchCriteria)) { $distal = array(); foreach ($this->removalChars as $val) { $replace[] = ""; } //REMOVE PUNCTUATION, CONVERT TO ALL LOWERCASE AND REMOVE LEADING AND ENDING SPACES $this->searchCriteria = trim(strtolower( str_replace($this->removalChars, $replace, $this->searchCriteria))); //GET METAPHONE KEY FOR SEARCH CRITERIA $scm = metaphone($this->searchCriteria); if ($this->numberOfMatches <= count($this->searchSet)) { for ($i=0; $i < count($this->searchSet); $i++) { $distal[levenshtein($scm, metaphone($this->searchSet[$i]))] = $this->searchSet[$i]; } } else { for ($i=0; $i < $this->numberOfMatches; $i++) { $distal[levenshtein($scm, metaphone($this->searchSet[$i]))] = $this->searchSet[$i]; } } ksort($distal); $this->returnMatches = $distal; } return false; } } /*INSTANTIATE CLASS*/ $score = new matcher(); /*EXAMPLE USE CASE*/ /*SETUP THE LIST OF STRING TO COMPARE THE SEARCH CRITERIA AGAINST*/ $score->searchSet = array( 'this is one item from a result set', 'this is another test item', 'more testing', 'Hello world, I am a test sentence.', 'So, do you have any mustard that I can borrow?' ); /*SETUP THE SEARCH CRITERIA*/ $score->searchCriteria = "Hello world, I am a test sentence."; /*FIRE THE SCORER METHOD (THIS METHOD WOULD BE EXPENSIVE TO CALL IN A LOOP, USE CAUTION)*/ $score->scorer(); /*DUMP THE RESULTS*/ print_r($score->returnMatches); ?>
  10. Try looking at htmlentities() http://php.net/manual/en/function.htmlentities.php
  11. Here is your first problem: Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /var/www/vhosts/digitalscribe.ie/httpdocs/card_paynow.php on line 17 the connecting resource you are using in mysql_query is no good. You need to establis a connection first, before you can run a query.
  12. no, $qty = $row_cardpayment; is not right because $row_cardpayment should be an assoc array, not a string value. Put this at the top, right under <?php, then try and run the script and see what prints out: ini_set('display_errors', 1);
  13. This is the line you're looking for: $row_cardpayment = mysql_fetch_assoc($cardpayment); $row_cardpayment should be an associative array that contains the result set of your query.
  14. Disagree here. Using similar names for similar methods saves you from having to remember different naming schemes. Tamato / tomato ..... True, there is a good consistency argument to be made here, however, can present some confusion for someone just starting to learn OOP.
  15. Yes, PHP isn't going to know that you want a variable called, '$qty' or the value you want it to equal, unless you specifically tell it to.
  16. Yeah, whomever controls the mail server, needs to allow the IP addess of the web server as an authorized relay or sender. Now, most likely, they won't allow the web server to be an open relay. So they'll probably require the web server to authenticate before sending email. If you get to that point; then in PHP, you should be able to make SMTP connections to the mail server, using the username and password they provide you. They may also give you a non-standard port to connect to, so be on the look out for that as well. Feel free to PM or email me if you need further assistance, once you get to that point.
  17. Okay, well that's what it appears to be. So, basically, the most likely issue (especially if it's Exchange), is that the mail server is not allowing the web server as an authorized relay. The mail server admin needs to make the IP of this web server, an authorized relay server. He/She will not want to make it an 'open' relay and will want to require auth from the web server.
  18. Right, so basically, they have their mail server running in the same network/LAN as this web server, right?
  19. Okay, looks much cleaner! I found a few more syntax/logic issues, here is the corrected code: <?php //Database connect if (!$con = mysql_connect("mysql1.myhost.ie","admin_book","root123")) { die('Could not connect: ' . mysql_error()); } mysql_select_db("book_test", $con); //CLEAN POST VALUES foreach ($_POST as $k=>$v) { $_POST[$k] = mysql_real_escape_string(trim($v)); } $sql="INSERT INTO custdetails (orderid, name, surname, add1, add2, town, county, postcode, phone, email, letterstyle) VALUES ('" . $_POST['orderid'] . "','" . $_POST['name'] . "','" . $_POST['surname'] . "','" . $_POST['add1'] . "','" . $_POST['add2'] . "','" . $_POST['town'] . "','" . $_POST['country'] . "','" . $_POST['postcode'] . "','" . $_POST['phone'] . "','" . $_POST['email'] . "','" . $_POST['letterstyle'] . "')"; $cardpayment = mysql_query(sprintf("SELECT qty FROM cards WHERE orderid = " . $_POST['orderid']), $book) or die(mysql_error()); $row_cardpayment = mysql_fetch_assoc($cardpayment); $totalRows_cardpayment = mysql_num_rows($cardpayment); if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Digital Scribe Books</title> <link href="style.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> function MM_preloadImages() { //v3.0 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} } function MM_swapImgRestore() { //v3.0 var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc; } function MM_findObj(n, d) { //v4.01 var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); if(!x && d.getElementById) x=d.getElementById(n); return x; } function MM_swapImage() { //v3.0 var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3) if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];} } </script> </head> <body onload="MM_preloadImages('images/buttons/home_over.png','images/buttons/books_over.png','images/buttons/cards_over.png','images/buttons/letters_over.png')"> <div id="snow"> <div id="wrapper"> <div id="header"> <div id="logo"><img src="images/digital_scripe.png" width="218" height="91" /></div> <div id="menu"><a href="index.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Home','','images/buttons/home_over.png',1)"><img src="images/buttons/home_act.png" name="Home" width="131" height="132" border="0" id="Home" /></a><a href="books.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Books','','images/buttons/books_over.png',1)"><img src="images/buttons/books_act.png" name="Books" width="131" height="132" border="0" id="Books" /></a><a href="cards.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Cards','','images/buttons/cards_over.png',1)"><img src="images/buttons/cards_act.png" name="Cards" width="131" height="132" border="0" id="Cards" /></a><a href="letters.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Letters','','images/buttons/letters_over.png',1)"><img src="images/buttons/letters_act.png" name="Letters" width="131" height="132" border="0" id="Letters" /></a></div> </div> <div id="content"> <?php echo 'Order ID is : '. $_POST['orderid'] . '.<br />'; if ($qty == 10) echo "<div> <form action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\"> <input type=\"hidden\" name=\"cmd\" value=\"_xclick\"> <input type=\"hidden\" name=\"business\" value=\"[email protected]\"> <input type=\"hidden\" name=\"lc\" value=\"IE\"> <input type=\"hidden\" name=\"item_name\" value=\"10 Christmas Cards\"> <input type=\"hidden\" name=\"item_number\" value=\"$orderid\"> <input type=\"hidden\" name=\"amount\" value=\"12.99\"> <input type=\"hidden\" name=\"currency_code\" value=\"EUR\"> <input type=\"hidden\" name=\"button_subtype\" value=\"services\"> <input type=\"hidden\" name=\shipping\" value=\"2.99\"> <input type=\"hidden\" name=\"return\" value=\"http://www.digitalscribe/thanks.php\"> <input type=\"hidden\" name=\"bn\" value=\"PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted\"> <input type=\"image\" src=\"https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif\" border=\"0\" name=\"submit\" alt=\"PayPal - The safer, easier way to pay online!\"> <img alt=\"\" border=\"0\" src=\"https://www.paypalobjects.com/en_US/i/scr/pixel.gif\" width=\"1\" height=\"1\"> </form> </div>"; if ($qty == 20) echo "<div> <form action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\"> <input type=\"hidden\" name=\"cmd\" value=\"_xclick\"> <input type=\"hidden\" name=\"business\" value=\"[email protected]\"> <input type=\"hidden\" name=\"lc\" value=\"IE\"> <input type=\"hidden\" name=\"item_name\" value=\"20 Christmas Cards\"> <input type=\"hidden\" name=\"item_number\" value=\"$orderid\"> <input type=\"hidden\" name=\"amount\" value=\"21.99\"> <input type=\"hidden\" name=\"currency_code\" value=\"EUR\"> <input type=\"hidden\" name=\"button_subtype\" value=\"services\"> <input type=\"hidden\" name=\"shipping\" value=\"2.99\"> <input type=\"hidden\" name=\"return\" value=\"http://www.digitalscribe/thanks.php\"> <input type=\"hidden\" name=\"bn\" value=\"PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted\"> <input type=\"image\" src=\"https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif\" border=\"0\" name=\"submit\" alt=\"PayPal - The safer, easier way to pay online!\"> <img alt=\"\" border=\"0\" src=\"https://www.paypalobjects.com/en_US/i/scr/pixel.gif\" width=\"1\" height=\"1\"> </form> </div>"; ?> </div> <div id="footer" class="clear"><div id="sign"><div id="sign_text">Personalised<br /> Books</div> </div></div> </div></div> </body> </html> <?php mysql_free_result($cardpayment); ?> Now, where is the $qty variable being set? The $qty variable is what will determin which form (if any) will be shown.
  20. Well, if you have a support contact, I would start there, and ask them for support. If you have shell access you could check the log dump on the server and see if anything is there. You could also try to find another mail server that you could make SMTP connections to. Bottom line, without a valid MTA (Mail Transport Authority), PHP is not going to be able to transfer mail.
  21. Do you control the server or is it a hosted solution?
  22. You can't declare two functions/methods with the same name, in the same runtime namespace. You have to make each function name unique. However, within classes, you can use the same method name as long as they are in separate classes - but I wouldn't recommend that; there is no reason that every function and method can't have there own name.
  23. Okay, lets work through this. Lets start here: mysql_select_db($database_book, $book); $cardpayment = mysql_query(sprintf("SELECT * FROM cards WHERE orderid = '%s' ORDER BY qty ASC", $colname_cardpayment), $book) or die(mysql_error()); $row_cardpayment = mysql_fetch_assoc($cardpayment); $totalRows_cardpayment = mysql_num_rows($cardpayment); //Database connect if (!$con = mysql_connect("mysql1.myhost.ie","admin_book","root123")) { die('Could not connect: ' . mysql_error()); } mysql_select_db("book_test", $con); 1.) It would seem that you are trying to setup two database connections here, but you're only actually making one connection, to the book_test database. What is the other mysql_select_db() ($database_book) for? 2.) It seems that your code is checking the value of $row2['qty'] to determine which form to show; however, in the code, $row2['qty'] isn't referenced anywhere. So, the reason that neither form is echo'ed out, is because $row2['qty'], doesn't equal 10 or 20.
  24. Is this a linux or windows server (the one that it is not working on)?
  25. I don't know why colname_cardpayment = -1; that's the way you had it in your original code. Remember, I am just seeing a small part of what you're trying to do.
×
×
  • 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.