|
functional posted:If your tests are not time intensive, why not simply run all of them and then check at the end to see if one failed? This is what I usually do. Actually, I keep a stack of error messages and then check to see if it's non-empty. Another way to do this is to iterate over the post array in a loop and use a switch statement like this php:<? $errors = array(); foreach($_POST as $key=>$value){ switch($key){ case 'email': //fancy email validation code break; case 'ssn': //fancy ssn validator break; default: if(empty($value)){ $errors[$key]=$key.' cannot be empty'; } break; } } if(empty($errors)){ //process post } else{ //handle errors } ?>
|
# ¿ Mar 27, 2008 20:39 |
|
|
# ¿ Apr 30, 2024 12:11 |
|
functional posted:(I would prefer a string solution to this, or something built into the PHP library, and not some big package I have to install.) http://us.php.net/simplexml
|
# ¿ Mar 27, 2008 21:12 |
|
fletcher posted:What's the point of declaring public variables in a class? If I remove them all, my application will behave the same, correct? With the way php currently handles objects there's no difference. However removing public or even not declaring the variables is just plain bad practice and could possibly break in future versions of php.
|
# ¿ Mar 28, 2008 20:08 |
|
fletcher posted:What's a good way to maintain my public variable declarations if they are all the exact same as my field names in the database, or do I have to just do it manually? The simplest way is to do it manually. Alternative you could use an ORM package. What I done in the past is build an array of the column definitions like this php:<? $props = array( 'username'=>array( 'type'=>'varchar', 'length'=>40, 'required'=>1), 'email'=>array( 'type'=>'varchar', 'length'=>255, 'required'=>0, 'validator'=>'email' ) ); ?> Another thing I've done in the past is use a script that I call one time to generate the above listed array after I've designed my database. It saves a little time. bt_escm fucked around with this message at 21:09 on Mar 28, 2008 |
# ¿ Mar 28, 2008 21:00 |
|
Finite posted:I'm writing some authentication code for something I'm mucking around with, while at the same time trying to improve my coding habits. With the example below, CheckPassword() throws an exception if the password is incorrect. What you want to use is a try/catch around the the code after the newPassword to newPassword2 check. Also your example seems really strange since you are mixing oop and procedural function calls.
|
# ¿ Mar 29, 2008 06:16 |
|
I still think a try catch would be better here because it could tell you why it failed, but after reading over your example some more the if statement would be fine. I think this would work a lot better for you for logging purposes php:<? try{ $this->CheckPassword($this->name, $oldPassword); $salt = self::CreateSalt(); $password = self::CreateSaltedHash($newPassword, $salt); $sql = 'UPDATE user SET password = "' . DB::Escape($password) . '" salt = "' . DB::Escape($salt) . '" WHERE name = "' . DB::Escape($this->name) . '"'; return $this->db->Execute($sql); } catch(SPECIFIC EXCEPTION $e) { } catch(Exception $e){ } ?>
|
# ¿ Mar 29, 2008 14:18 |
|
Treytor posted:I have since upgrade to PHP 5 and it seems my method of querying a server via a predefined URL no longer works: check you fopen wrapper settings. also http://us3.php.net/manual/en/function.stream-context-create.php
|
# ¿ Mar 29, 2008 22:38 |
|
OlSpazzy posted:Does anyone see a reason why the "show news comments" section of this code is only displaying the newest comment for each post? I looks like you are assigning $comments_list_commentbit each time. I think you want to use .= instead of = Also I see no reason to use eval here or anywhere else in your code and it's really just a style and readability thing, but never use select * from table, even when you want to select everything from the table. List out the columns. It will save your sanity in the future.
|
# ¿ Apr 4, 2008 18:51 |
|
I honestly don't know where to begin with this. To fix the append issues try adding $comments_list_commentbit='' in between the number of rows check and the while loop. Don't use eval. bt_escm fucked around with this message at 20:18 on Apr 4, 2008 |
# ¿ Apr 4, 2008 20:14 |
|
Zorilla posted:So would there be anything wrong with sanitizing as late as the MySQL query string? Right now, I'm getting away with processing form inputs with their original $_POST superglobals, then using htmlspecialchars() at the query function argument to keep form inputs from doing anything too powerful, though I don't know if that would leave you wide open on older, less secure versions of PHP. htmlspecialchars() won't stop sql injection. You'll need to you mysql_real_escape_string() to properly clean the string for inserting into the database.
|
# ¿ Apr 6, 2008 23:36 |
|
fletcher posted:Is it a bad idea to write a backup script in PHP? I just need it to dump the database, tar.gz a folder, delete the oldest backup on the backup server, and upload the new one. It seems like it would be cake to write it in PHP, but should I? Is there a reason I have to write this as a bash script? Since you already know PHP, writing it PHP would make the most sense. I really don't think it would matter what you write it in.
|
# ¿ Apr 9, 2008 09:40 |
|
Zorilla posted:I've got a client we're doing a web page redesign for and it turns out he would like to be able to edit basically anything that might need changing on the site on his own. Normally, I would just set up some system like Website Baker or CMS Made Simple, but this site in particular has quite a bit of markup I don't want the client to disturb. Plus, the site has some dynamic content with a backend I wrote a month or so ago to edit its contents. I'm pretty sure cmsms has a user management system in it that you can use to prevent users from editing certain pages and content blocks. Actually I think most content management systems have that now. You could take a look at http://www.opensourcecms.com/ and look over some of the more popular ones.
|
# ¿ Apr 9, 2008 09:47 |
|
the talent deficit posted:Is this the right place for Zend questions? I hope so. It's one of two things 1) mod_rewrite is not enabled 2) your htaccess file is messed up If it was setup correctly then all requests should be going to the index.php file in the webroot. The framework handles all requests form there.
|
# ¿ Apr 9, 2008 09:52 |
|
drcru posted:e: php4 You could use strpos to find the nth line break and then substr to grab the first and then second half of the string. I'm sure there's a way to do this with regular expressions too.
|
# ¿ Apr 9, 2008 22:18 |
|
TheHeadSage posted:I'm writing another small PHP script to amuse myself, and this time I'd like to move away from having SQL sitting in my code. Are there any articles on how to go about this? I'm not looking for a full blown framework as that's just overkill for this but a simple DB class or something would be nice. Here's an ORM http://propel.phpdb.org/trac/ And here's a tutorial http://codepoets.co.uk/propel_php5_framework_quickstart_howto_guide
|
# ¿ Apr 10, 2008 07:28 |
|
fletcher posted:I don't really understand what that helps with. Isn't it more beneficial to just learn/practice SQL? They're not mutually exclusive. This explains it way better than I could http://en.wikipedia.org/wiki/Object-relational_mapping
|
# ¿ Apr 10, 2008 16:39 |
|
TheHeadSage posted:I already know SQL. I'd like to move away from having SQL statements littered all throughout my projects where it's hard coded in. Which leads to maintaining multiple versions because my home system runs MySQL and my sever runs PostgreSQL and for added fun a friend uses my scripts and he's got Oracle. What do you mean by hard coded? Technically if you have sql anywhere in your code it could be considered hard coded since sql is frequently tied to the specific database server you are using. If you just want to be able to execute sql statements using the same set of commands across multiple script regardless of the database then pear's mdb2 would be better suited for that. If you want code to dynamically know the structure of your tables and handle all of the basic manipulations for you then propel would be ideal for that.
|
# ¿ Apr 10, 2008 16:48 |
|
Grigori Rasputin posted:I have a question that might be a little involved, but maybe someone can point me in the right direction. Zend_Mail has a really nice way of doing this http://framework.zend.com/manual/en/zend.mail.read.html
|
# ¿ May 21, 2008 07:34 |
|
MrEnigma posted:Is there any extension/package that will do form creation, and then auto detect if the form values were tampered with (ie with firebug or rewriting the page). There's Zend_Form that does both form creation and validation. I'm pretty sure it won't autodetect tampering. There's also something in the PEAR libraries, but it doesn't do tampering either. I'm pretty sure you're going to have to write your own for that.
|
# ¿ May 24, 2008 21:24 |
|
fletcher posted:Do you guys pass in a database connection in to a static function or do you get the database connection from within the static function? I get the database connection from within the static function.
|
# ¿ May 24, 2008 21:31 |
|
Grigori Rasputin posted:
Your authentication scheme is fine for a basic site. I'm assuming you have a collection of php pages that contain the layout and any processing logic in them. Doing that is fine for a smaller site or a site that doesn't really do anything. If you goal is to try and build something more complicated than a site with bunch of content and a few contact forms, then I recommend looking into a framework. To force the sessions to time out set session.gc_maxlifetime in your php.ini to however many seconds you want before the session file is erased. If you are on a shared host then you may need to use ini_set('session.gc_maxlifetime',#seconds) before you call session start or set it in a .htaccess file for your whole site.
|
# ¿ May 24, 2008 21:47 |
|
MonkeyMaker posted:I'm trying to use the PHP-native result from the Flickr API and I have everything working well enough except when I try to display results from more than one photoset on the same page. It returns the same images for all photoset calls. Any ideas? change line 60 to php:<? $rsp = hitFlickr('',$photoset); ?> php:<? $url = "http://api.flickr.com/services/rest/?".http_build_query($params); ?>
|
# ¿ May 24, 2008 22:14 |
|
nbv4 posted:I have a PHP array with each item being an airport identifier. "KBOS", "KTEB", "KMIA", "MMIO", etc. These are wordwide airports, not just US airports. I want to get the longitude/latitude coordinates of each item. It's a long shot, but is there a tool that already does such a thing? I can probably swing together a function that crawls some other page for the info, but I don't want to waste my time if something already exists. I found this http://www.webservicex.com/airport.asmx and I was able to get a couple of coordinates for a few airports. I think google maps would be ideal for this.
|
# ¿ May 24, 2008 22:22 |
|
magicalblender posted:How about something like this: This would be so much better as a regular expression php:<? $phone = '2145551212'; $formattedString = preg_replace('/(\d{3})(\d{3})(\d{4})/','$1-$2-$3',$phone); ?>
|
# ¿ May 26, 2008 11:10 |
|
Evil Angry Cat posted:Although I think considering the user is so new to php that he thought splitting a string required some sort of loop, substr() is a better method than reg exps. Perhaps, but at least now they've seen two ways to do it, and have been given some exposure to a valuable tool. bt_escm fucked around with this message at 15:51 on May 26, 2008 |
# ¿ May 26, 2008 15:47 |
|
Grigori Rasputin posted:When you say framework, would something like PEAR's Auth be adequate? Yes, pear_auth would be fine. By framework I was talking about a framework like the zend framework, cake or syphony or any of the other dozen or so php frameworks.
|
# ¿ May 28, 2008 02:55 |
|
MrEnigma posted:PDFLib is the one you want, it's not easy at all to do things though...well anything besides just a block of text. take a look at http://www.digitaljunkies.ca/dompdf/ It will convert html + css2.1 to a pdf document and is a crap load easier than directly using PDFLib.
|
# ¿ Jun 16, 2008 03:10 |
|
iamstinky posted:I am trying to implement a reversible sort a 2d array by an arbitrary key in the second level function. I have to question where you're getting the data from that you would need to sort it in php?
|
# ¿ Jun 16, 2008 22:35 |
|
willjo3 posted:I'm having a problem using the php mail() function. I've been googling and experimenting for two days trying to figure it out to no avail. what is the value of $mailheader in the original script?
|
# ¿ Jun 17, 2008 00:08 |
|
Treytor posted:I have a file upload script based on this - http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=2293&lngWId=8 To just remove spaces use this php:<? $string = str_replace(' ','',$string); ?> However if you are looking to make the filename safe for your file system then you should use a regular expression to replace any non-aplhanumeric characters like this php:<? $string = preg_replace('/[^A-Za-z0-9\\.\\-_]/','',$string); ?> bt_escm fucked around with this message at 22:26 on Jun 17, 2008 |
# ¿ Jun 17, 2008 22:16 |
|
iamstinky posted:It is a combination of physical file data and stuff from db, sortable by the user as needed. As some of it isn't db related I can't let the DB sort the data for me. But if you have any suggestions, feel free to offer them. Ok, the solution posted earlier will work. It's just unusual to have to sort a large block of data in php like that.
|
# ¿ Jun 17, 2008 22:28 |
|
passionate dongs posted:Really dumb question: put the resultset into an array and then have a look at http://www.php.net/json_encode
|
# ¿ Jun 25, 2008 03:25 |
|
Dirk Pitt posted:I need to find a library that allows for the creation of php to pdf on the fly. So far I have found fpdf.org and tcpdf.org to be the best, does anyone have any experience with either library? The built-in pdf support in php5 is not good enough for what i need to create. thanks! domPDF will take an html page formatted with css2.1 and convert it to a pdf. It's really nice and it's free. http://www.digitaljunkies.ca/dompdf/
|
# ¿ Jul 28, 2008 21:36 |
|
Stephen posted:Yeah, this is what I thought, but I was still hoping there was a workaround. Unfortunately sessions won't work because I'm not redirecting to an internal page. Basically I'm using a grossly insecure 3rd party web app that accepts confidential information via POST. My solution was to use an internal database as a proxy to accept a coded value, and then query a database with a list of the confidential values and redirect to the 3rd party site with those values in a POST header. It seems like you could use curl to take the original form on your site and then resubmit to the other server, capture the results and spit them back to the user. You may need to parse all of the src and href in the result html to the full url, but that's pretty easy. This can also be done without curl depending on the version of php you're using. The code for that is php:<? function do_post_request($url, $data, $optional_headers = null) { $params = array('http' => array( 'method' => 'POST', 'content' => $data )); if ($optional_headers !== null) { $params['http']['header'] = $optional_headers; } $ctx = stream_context_create($params); $fp = fopen($url, 'rb', false, $ctx); if (!$fp) { throw new Exception("Problem with $url, $php_errormsg"); } $response = stream_get_contents($fp); if ($response === false) { throw new Exception("Problem reading data from $url, $php_errormsg"); } return $response; } //call $post = http_build_query($_POST); try{ $response = do_post_request('http://www.XXX.com/form.html',$post); echo $response; } catch(Exception $e) { die($e->getMessage()); } ?> bt_escm fucked around with this message at 21:08 on Aug 7, 2008 |
# ¿ Aug 7, 2008 21:02 |
|
iamstinky posted:
if $_SESSION['cuerrent_vendor'] doesn't have a value or is equal to '' or 0, set $_SESSION['current_vendor'] to the value of $r[2]?
|
# ¿ Aug 12, 2008 17:57 |
|
change all the php:<? echo $row; ?> php:<? echo $row['URl'] ?>
|
# ¿ Aug 25, 2008 04:28 |
|
Emo Businessman posted:I'm having tons of issues with CakePHP. It seems like if you ever venture out of the realms that tutorials and the inadequate manual covers, it has a 'right' way to do things, but good luck finding the 'right way' that fits what you're trying to accomplish, and trying to figure out that 'right way' involves a ton of source diving and refactoring of code you've already written to something 'acceptable' that you hope to god you can fix later on down the line. I find myself blindly following tutorials almost to the letter, and trying to do something 'clever' or apply anything I've learned in a Cake tutorial or manual to something else always seems to get me in trouble. I think the Zend Framework (http://framework.zend.com/) is all kinds of awesome.
|
# ¿ Aug 29, 2008 16:42 |
|
|
# ¿ Apr 30, 2024 12:11 |
|
gibbed posted:
If you are using php5, then please use the spl directoryIterator (http://www.phpro.org/tutorials/Introduction-to-SPL-DirectoryIterator.html).
|
# ¿ Feb 25, 2009 23:55 |