|
What's the recommended PHP book path to become job-candidate worthy? I'm looking at: PHP from Novice to Professional 3rd Ed (to learn the language) Pro PHP Patterns, Frameworks, and Testing (to learn to use the language) and then a CodeIgniter book and user guide readthrough (to make poo poo easy once i know the basics)
|
# ? May 13, 2010 14:09 |
|
|
# ? Jun 4, 2024 00:31 |
|
What are some good ways to create full-featured forms? I'm not talking about simple contact forms or "sign up for a stupid newletter" stuff. I want to do multiple pages, custom validation, conditional display of fields, real-time updates, etc. I found HTML_QuickForm2 but there doesn't seem to be any documentation besides the autogenerated API docs. I found some other Javascript stuff like fValidator and iMask, and I've worked a little with jQuery before. I'd like to avoid AJAX at this point if possible. So what are the best ways to create high quality, complex forms with PHP and Javascript?
|
# ? May 13, 2010 18:39 |
|
I've always just used jQuery. It's plenty powerful enough to do all that. A multi-step form is really just a form with tabs. Conditional display is really just show/hide. Validation jquery plugin makes validation stupid easy if you know some regex. Not sure what "real-time updates" means, but you're not going to avoid ajax in that regard.
|
# ? May 13, 2010 21:07 |
|
First Time Caller posted:I've always just used jQuery. It's plenty powerful enough to do all that. A multi-step form is really just a form with tabs. Conditional display is really just show/hide. Validation jquery plugin makes validation stupid easy if you know some regex. Not sure what "real-time updates" means, but you're not going to avoid ajax in that regard. Sorry, that wasn't very clear. I meant updating a field based on other fields when the user enters data in the form. Like updating a total as they check off boxes. I'm pretty sure Javascript can do that. Thanks for the rest of the tips. I was hoping there was something out there to make it a little easier, but it seems like the right way to do it is using a framework that has form stuff already. Unfortunately that isn't option for me, so it looks like I'll just have to do these one-off forms manually.
|
# ? May 13, 2010 22:01 |
|
Cpt.Wacky posted:Sorry, that wasn't very clear. I meant updating a field based on other fields when the user enters data in the form. Like updating a total as they check off boxes. I'm pretty sure Javascript can do that. You can't use jquery? Its not a framework, just a kick rear end javascript library that you include in your page that lets your work with the DOM in a non sucky way. You can still be writing all your forms manually, however jquery will make it really easy to access form element values, add stuff up, put totals in fields, hide / unhide fields, etc.
|
# ? May 14, 2010 15:09 |
|
Begby posted:You can't use jquery? Its not a framework, just a kick rear end javascript library that you include in your page that lets your work with the DOM in a non sucky way. You can still be writing all your forms manually, however jquery will make it really easy to access form element values, add stuff up, put totals in fields, hide / unhide fields, etc. Yeah, I ended up using jQuery. It works but it's less elegant than I'd like, which could because I've only done a few small things with it before.
|
# ? May 14, 2010 16:59 |
|
I working on storing information in a text file rather than a database, and reading it into an array with file(). The information looks something like this (it's a very small array used to create a dropdown menu):code:
The problem is that if I want to change the position of the rows for a given MenuLinkID, a simple foreach loop will change the values, but file() will still read it in the order it gets fed, and I need to change that (hell, possibly doing away with the position field altogether). A glance at sorting options in PHP reveal a number of options, but I don't see any clear way to do an associative sort of the array by a given index, and ensuring that that sort only applies to rows with the same MenuLinkID Of course I could use the same foreach loop mentioned earlier to just swap the values of the rows in question, which does the trick but seems unnecessarily wasteful - for such a small array it's probably not a huge concern, but I'd rather do it the right™ way - any ideas?
|
# ? May 15, 2010 15:04 |
|
I don't understand why you need to do this with a text file rather than a database, but suppose for the sake of the problem there is a good reason. What is the ID "column" for? Is it used for anything? If you got rid of it and stored the rows in the form code:
Alternatively, why don't you comma-separate the columns in the text file (or separate them using some delimiter you will never put into the names or URLs), then you can go through and explode() the entries in the array returned by file(), and sort() them more or less easily.
|
# ? May 15, 2010 15:47 |
|
Masked Pumpkin posted:I don't see any clear way to do an associative sort of the array by a given index, and ensuring that that sort only applies to rows with the same MenuLinkID Do you need to ensure that? If you sort() by position then yes, within position-groups there will be a jumble of rows with different MenuLinkIDs, but I assume that at some point you have a loop that builds up the drop-down list, or echoes it item-by-item or something. You could just add an if statement to the loop to make sure only the appropriate rows are treated.
|
# ? May 15, 2010 15:53 |
|
Hammerite posted:I don't understand why you need to do this with a text file rather than a database, but suppose for the sake of the problem there is a good reason. Sadly I had the database system up and running, and due to some other random stuff I was doing working with files, I set it for myself as a cool little project to learn about an aspect of PHP I've never really used before. Because the whole thing here is web based, handled with a combination of GET and POST requests for different options (like changing the position of an item), having an ID for each item is necessary so that I know which item I'm actually meant to be changing. The code I gave you was just a representation of the array, the file itself has all the values separated by '||' and with a new line for each new row. file() and explode() then return the values in an array that I can work with. Hammerite posted:Do you need to ensure that? If you sort() by position then yes, within position-groups there will be a jumble of rows with different MenuLinkIDs, but I assume that at some point you have a loop that builds up the drop-down list, or echoes it item-by-item or something. You could just add an if statement to the loop to make sure only the appropriate rows are treated. This is a drat good idea - I hadn't thought of that at all. The question then is how I can sort by the position field instead of the normal index - I'm not seeing anything standing out in the documentation.
|
# ? May 15, 2010 16:25 |
|
Masked Pumpkin posted:The question then is how I can sort by the position field instead of the normal index - I'm not seeing anything standing out in the documentation. The only thing that immediately occurs to me is to use array_multisort, as in code:
|
# ? May 15, 2010 16:40 |
|
Of course, now I understand how that sort works - the manual and examples given left me a bit confused. Thank you, kind sir! I'm still a much bigger fan of databases - they're there exactly so I don't have to fiddle through text files, and ORDER BY clears up sorting problems, but I can see myself finding this useful at some point, I guess.
|
# ? May 15, 2010 17:36 |
|
It looks like you already have a working solution in place, but I suggest you take a look at
Using a well known tactic next time could save you some headaches.
|
# ? May 15, 2010 18:08 |
|
rt4 posted:It looks like you already have a working solution in place, but I suggest you take a look at There is not a big enough to describe this - it's enabled by default in PHP, so it's pretty much available on any server I might have to work on! I considered a small single file database, since I've used it before with great success, but I couldn't remember the name, and thought it might have been tinydb (it wasn't) but this... I've still learned a lot about file management, which was the goal, and XML does seem like a great idea for the next step, so I'll do that, thanks. Still... !
|
# ? May 15, 2010 20:12 |
|
I built a website for a Goon with some very basic PHP. As part of it he has a form that gets e-mailed to him, using the email() function. It was working fine until last night when all of a sudden it started sending multiple duplicate e-mails. Has anyone seen this? pre:if($from == '') { print "You have not entered an email, please go back and try again"; } else { $send = mail($to, $subject, $body, $headers); $send2 = mail($from, $subject2, $autoreply, $headers2); if($send) { header( "Location: http://www." ); } else { print "We encountered an error sending your mail, please notify membership@_______.com"; } }
|
# ? May 16, 2010 13:06 |
|
ODC posted:I built a website for a Goon with some very basic PHP. As part of it he has a form that gets e-mailed to him, using the email() function. Is it doing it for all e-mail or just from one person? If it's just for one email address, I'd guess the user's not seeing the page load fast enough and are refreshing or they're refreshing on the "We encountered an error" page and you're getting the send request multiple times. --- I'm starting to use templates and after googling, Smarty is my engine of choice. I understand the core principles of binding variables and including files from within template files themselves but I want to check something before going down an awkward path. I have a body.tpl which is the main layout for my page. In it I have a title and pagecontent placeholders. I want to include another template in my pagecontent placeholder, it's a form and will be included conditionally from my business logic. Doing the following doesn't work: php:<? $smarty->assign('pagecontent', "{include file='form_newclient.tpl'}"); ?>
|
# ? May 16, 2010 13:48 |
|
ODC posted:It was working fine until last night when all of a sudden it started sending multiple duplicate e-mails. Has anyone seen this? My guess could be either, as gwar3k1 said, a user refreshing the page too quickly, or possibly some problem on the mail side with that server. However, it seems as though that your mail function so far seems to be trying to send two messages - one ($send) with To, Subject, Body and Headers, and then another ($send2) with From, Subject, Autoreply and Headers. Mail should always at least have a From specified, though this can be set by default in php.ini, and so it's possible that the mail is being sent twice, albeit with slightly different information in each message. I'd recommend something like the following: php:<? if(!filter_var($from, FILTER_VALIDATE_EMAIL)) { print "You have not entered a valid email address, please go back and try again"; } else { $headers = "From: ".$from."\r\nReply-To: ".$autoreply; //I'm not sure if you have extra header information to insert here $send = mail($to, $subject, $body, $headers); if($send) { header( "Location: [url]http://www.[/url]" ); } else { print "We encountered an error sending your mail, please notify membership@_______.com"; } } ?> Of course, if you're going down that route, since you're getting the important information (perhaps just the email address), or whatever else POSTed to you anyway, you could redirect them back to the page with the email form on failure, and fill in the information they have already tried to submit to save them the hassle of doing it again. Edited to fix a missing bracket Masked Pumpkin fucked around with this message at 15:02 on May 16, 2010 |
# ? May 16, 2010 15:00 |
|
I am going to be coding a browser MMO sort of game, however long it takes, as a personal project. I have programmed, I can do HTML/CSS/Flash|AS3 etc. so the thinking around coding is comfortable for me. I have not ever used PHP or SQL, though. There are a few rough logistics things that I don't quite get, to start: 1) This is probably more an SQL question, but each player's account is going to include a pretty massive amount of data, much of which will be in constant flux. Am I just going to be making a single database here, with one row per player, and a poo poo-ton of columns for everything, or is it easier to divide it up by category (stats, wealth, location, etc) into separate databases? I'm thinking for scale here, should I ever actually develop a player-base. 2) The game will likely use a time-scale of some form, so that you can build something, and it would take 4 hours to complete. What on my server would run the hourly "tick"? Can I do this in PHP/SQL or am I going to need to add other things? I'm not adverse to bringing in other tech if I need it. Ideally while I'm developing I'd like to have manual control over the tick, as well. Any other tips from people who've coded web games about problems they encountered and such are also appreciated.
|
# ? May 16, 2010 20:58 |
|
SPACE WEED posted:1) This is probably more an SQL question, but each player's account is going to include a pretty massive amount of data, much of which will be in constant flux. Am I just going to be making a single database here, with one row per player, and a poo poo-ton of columns for everything, or is it easier to divide it up by category (stats, wealth, location, etc) into separate databases? I'm thinking for scale here, should I ever actually develop a player-base. SPACE WEED posted:2) The game will likely use a time-scale of some form, so that you can build something, and it would take 4 hours to complete. What on my server would run the hourly "tick"? Can I do this in PHP/SQL or am I going to need to add other things? I'm not adverse to bringing in other tech if I need it. Ideally while I'm developing I'd like to have manual control over the tick, as well.
|
# ? May 16, 2010 21:08 |
|
Yay posted:Whilst I'll attempt to avoid sounding douchey here, you need to get your terminology right. Mostly, you will want it in one database, spread across multiple tables, into logic groups (eg: 'user', 'user_ally', 'resource_type', and so on). Worry about normalisation when scaling becomes an issue. Well, my test server is a windows machine, so I wouldn't be using cron. I figured it would be done by a scheduler rather than PHP, which is what I needed to confirm and yes, I have no actual experience with SQL terminology yet, just a basic understanding. I meant tables.
|
# ? May 16, 2010 21:12 |
|
SPACE WEED posted:I am going to be coding a browser MMO sort of game, however long it takes, as a personal project. 1) Separate related data into individual tables: user accounts in one table, game data in others etc. You don't need individual databases to do this, just multiple tables. If that's something that is alien to you, its worth reading up on first rather than delving right into it. 2) Cron scripts can automate tasks at specified time intervals, but if you're not desparate for 100% realtime accuracy, just record the time the unit was created and compare to the current time every time the page loads. If its been x+ unitsoftime then set the unit to complete.
|
# ? May 16, 2010 21:13 |
|
Things are starting to come together in my head, thanks for clearing things up! I picked up a PHP/SQL textbook, the sort that guides the reader through coding various little games and diversions to learn the various functions. Going to work through it end to end before I even think about actually making this browser game. If CyberNations can take off and get poo poo-tons of users, I can definitely succeed, so long as I complete the project... so I'll take my time and do it right. Is there anything I need to watch out for as far as migrating my stuff goes? I'm currently using a beat up old HP with XPSP3 and XAMPP to do my testing, but I will be putting some of my PHP/SQL work online (my own portfolio site, for one). Moving the files over isn't a problem, but is there some "correct" way to get the database structure over other than rebuilding the tables by hand on my DreamHost?
|
# ? May 16, 2010 23:04 |
|
Complete beginner with hashing here, have a few questions. I work in PHP + MySQL so that's why I am posting here, though these aren't PHP-specific questions I suppose. Didn't really know where to post. It seems, based on what I've read, that md5, sha1 and apparently more of the sha-family of hashing functions are more or less compromised. I've been unable to read my way to which hashing function I should use instead. Does it even matter that md5 and sha1 are compromised if I salt the hash with randomly generated numbers and letters (and symbols?)? How should I store the key to the salt if it is randomly generated? If it's stored in the database with the hash of the password doesn't that make it simple to account for the salt if someone should get a hold of the database to try and steal the passwords? Going further with the above thought, is storing the key to the salt in the database with the password more of a "You may get a few passwords, but it'll take you a billion billion years to get all of them" way of doing it than "complete security "? On the other hand, if I use 1 key to generate the salt for all the hashed passwords and the key is hardcoded in php, will that be safer?
|
# ? May 17, 2010 00:20 |
|
As long as you're not storing credit card information in your database or working for a bank, you should be fine with just salting your hashes. Try and have a different salt for every person though.
|
# ? May 17, 2010 01:15 |
|
There has been a bit of discussion on encryption and hashing. I found a nice class I thought I would share. http://www.tonymarston.co.uk/php-mysql/encryption.html
|
# ? May 17, 2010 01:25 |
|
drcru posted:As long as you're not storing credit card information in your database or working for a bank, you should be fine with just salting your hashes. Try and have a different salt for every person though. Just for the sake of clarity, where should I store the salt for every person, optimally? In the database seems an obvious answer, but isn't it a bad solution? Should I just store the salts in a separate database? I have read that the salts should be stored seperately, but I'm not entirely sure in which way. I am still a complete beginner with this. Meshak fucked around with this message at 01:48 on May 17, 2010 |
# ? May 17, 2010 01:46 |
|
Meshak posted:Just for the sake of clarity, where should I store the salt for every person, optimally? In the database seems an obvious answer, but isn't it a bad solution? Should I just store the salts in a separate database? You could store information that is used to generate a salt. For example, create a unique string from the name of the user and the date. Then take every other character and that is your salt. You can even limit the length. Something like this: User: Jonathan Doe $saltstring = md5('jonathan doe' . time()); Store $saltstring in the database and then you have a unique string for each and every user created. You then create a function to take a certain number of characters from the MD5 hash. The following example will create a unique string which can be used to generate a unique SALT for each user. You get an MD5 of the user's name and current time, then remove every other character from that string and strip to 8 characters and you have a unique SALT. This is just an example and an idea. I just made it up and haven't used it so I can't say for sure how well it works php:<? $name = "Jonathan Doe"; $saltstring = md5($name . time()); $userSalt = generate_salt($saltstring); function generate_salt($string) { $new = ""; for($i = 1; $i < len($string); $i += 2) { $new .= $string[$i]; } $new = substr($new, 0, 8); return $new; } ?> DarkLotus fucked around with this message at 02:08 on May 17, 2010 |
# ? May 17, 2010 02:00 |
|
drcru posted:As long as you're not storing credit card information in your database or working for a bank, you should be fine with just salting your hashes. Try and have a different salt for every person though.
|
# ? May 17, 2010 08:54 |
|
Meshak posted:Just for the sake of clarity, where should I store the salt for every person, optimally? In the database seems an obvious answer, but isn't it a bad solution? Should I just store the salts in a separate database? There's no point to storing them separately - if they have access to your database, they probably have access to the whole thing. You can make a second salt that sits in a configuration file somewhere that is also added to the hash with the per-user salt for a little extra piece of mind. That would only help if they were somehow only able to see the contents of the database and not the code files as well. Having said that, you should be using crypt() with blowfish if it supports blowfish on your server: php:<? echo 'Does crypt() on this machine support the only useful cryptographic hashing '; echo 'standard PHP has seen fit to include? ',CRYPT_BLOWFISH ? 'YES!':'Hah hah -No.'; ?> Munkeymon fucked around with this message at 20:53 on May 17, 2010 |
# ? May 17, 2010 16:52 |
|
SPACE WEED posted:Moving the files over isn't a problem, but is there some "correct" way to get the database structure over other than rebuilding the tables by hand on my DreamHost? code:
code:
|
# ? May 17, 2010 17:28 |
|
Munkeymon: Apparently my host supports it. I'll look into it. Thanks to everyone for the responses, I think I've managed to wrap my mind around this hashing business for now.
|
# ? May 17, 2010 20:24 |
|
Meshak posted:Munkeymon: Apparently my host supports it. I'll look into it. Thanks to everyone for the responses, I think I've managed to wrap my mind around this hashing business for now. I was looking for this earlier but couldn't find it: http://www.dereleased.com/2010/02/09/lets-talk-about-your-password-model/
|
# ? May 17, 2010 20:51 |
|
I've got a monolithic data source abstraction class that's shared between several applications, and I'm trying to trim it down by, ideally, making it load only the methods that are needed for that application, without running into any code duplication issues. The obvious way of doing this would be something along the lines of "class foo extends foo" so I could then have foo.base.class.php, foo.writes.class.php, foo.othersource.class.php, foo.somemethod.class.php and foo.othermethods.class.php... and manage what's loaded by the includes but something seems so about that, and while I haven't tried it, I'm pretty sure PHP doesn't allow that anyway. I'm sure I'm approaching this the wrong way, but I'm not sure what the right way is.
|
# ? May 17, 2010 21:57 |
|
edit: Thought this might be a server config issue but TankAuth works fine. I am having a very strange problem with CodeIgniter. I'm following a tutorial for building a login system and crud, and so far it's gone perfectly except for one thing. I write to the session with php:<? function Login($options = array()) { // required values if(!$this->_required( array ('userEmail', 'userPassword'), $options) ) return false; $user = $this->GetUsers(array('userEmail' => $options['userEmail'], 'userPassword' => md5($options['userPassword']))); if(!$user) return false; $this->session->set_userdata('userEmail', $user->userEmail); $this->session->set_userdata('userID', $user->userID); return true; } ?> php:<? echo "welcome to the dashboard " . $this->session->userdata('userEmail'); ?> quote:welcome to the dashboard Everything seems to be right to me, and I've autoloaded the session library and set up the ci_sessions database, but it just won't work. The cookie does not appear to contain any userdata: quote:a:4:{s:10:"session_id";s:32:"36f76ae7550a825c27b86b264380ef8b";s:10:"ip_address";s:12:"192.168.1.42";s:10:"user_agent";s:50:"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv";s:13:"last_activity";s:10:"1274129699";}d29fdc27625bf7b8b1077b1b563d62ba Neither does the (successfully saved) database entry: quote:session_id: 36f76ae7550a825c27b86b264380ef8b wat i do rong edit: and to clarify re: the IP, I have a test-server on my LAN at 192.168.1.145, and my main computer is 192.168.1.42 - the domain stuff in CI is set up properly, and everything else works so far except for the session's user_data. SPACE CARBS fucked around with this message at 22:58 on May 17, 2010 |
# ? May 17, 2010 21:59 |
|
I don't see anything MySQL related in your code. Did you forget to paste something?
|
# ? May 18, 2010 03:18 |
|
drcru posted:I don't see anything MySQL related in your code. Did you forget to paste something? Either way, I've abandoned the tutorial and I'm just working off TankAuth now, which is much more secure than anything I could make.
|
# ? May 18, 2010 07:49 |
|
Hey Space Weed, a friend and I got a long way through writing a browser MMORPG a few months ago, but it sort of ran out of steam when exams came. Either way, the code design might give you a few ideas: http://github.com/josh04/quest/ We never really got round to game mechanics though.
|
# ? May 18, 2010 13:30 |
|
josh04 posted:Hey Space Weed, a friend and I got a long way through writing a browser MMORPG a few months ago, but it sort of ran out of steam when exams came. Either way, the code design might give you a few ideas: http://github.com/josh04/quest/ Thanks, I'll take a look. I've been hacking away at this thing since my first post, and I now have the auth system up and running. It can read various player data from a player-data table that is separate from the primary "player info" table, and the registration process creates an empty row in each table. That was the part I was most uneasy about, so onto game-building!
|
# ? May 18, 2010 18:11 |
|
Loosely PHP-related. I have a bunch of scripts (like, 7 or 8) that run as cron jobs. One of them runs every 15 minutes; the rest run anywhere from once a day to once a month. I want to change the way I do things a bit. I want to split one of the things the once-every-15-minutes script does into its own cron job that runs every minute. At the same time, I'm happy for the other things done by that script to happen less frequently than they do at present. This is straightforward so far but I also want some control over in what order things happen, when the job that is to be once-per-minute runs at the same time as another job. So I came up with the idea of having just one job that runs every minute and that looks at the time it is run (down to the minute) in order to determine what it does and in what order. To make sure it's not too intensive on the server when it is to do more than one thing, I'd chain jobs for it to do together with commands like sleep(2). All of my cron jobs are run with the nice -n 19 prefix. Is this a reasonable approach to take to this? As in it's not likely to be too intensive on my host's server? Does anybody here do something like this themselves?
|
# ? May 19, 2010 16:45 |
|
|
# ? Jun 4, 2024 00:31 |
|
I'm a bit perplexed by this scenario. I have a registerUser function that validates data and then inserts it into the database, but I want to be able to have error breaks. I also want to be able to load the page's HTML (including the footer, such as closing HTML tags) and still have the error displayed. The only way I can see exiting out of a function is by using:php:<? function registerUser() { //some code here if($var == false) { error = "This variable is false"; return die($error); } } ?>
|
# ? May 20, 2010 00:02 |