|
I have been looking around, but can't find a good explanation of using multiple $$$ Like why would you have $$var1 or $$$var2? Please explain or point me to a place that explains it. Or how about how math is done with the e^ stuff. (Sorry if this isn't clear. I was taking some online tests, and have never had to use exponents or that ^, but it wanted me to know)
|
# ? May 11, 2008 03:15 |
|
|
# ? May 16, 2024 18:20 |
|
hallik posted:I have been looking around, but can't find a good explanation of using multiple $$$ Basically $$foo takes the value in the variable $foo and uses it as a variable name for accessing the another variable (this is what the first $ is doing). So if $foo had the value of "baz", then PHP would just access $baz. hallik posted:Or how about how math is done with the e^ stuff. (Sorry if this isn't clear. I was taking some online tests, and have never had to use exponents or that ^, but it wanted me to know) Not really sure what's being asked here. Are you asking how exponentials are computed algorithmically?
|
# ? May 11, 2008 05:00 |
|
Inquisitus posted:Basically $$foo takes the value in the variable $foo and uses it as a variable name for accessing the another variable (this is what the first $ is doing). So if $foo had the value of "baz", then PHP would just access $baz. So $bar = 'yo'; $$bar would also be accessed by $yo. What would $$$bar be? I saw a reference to $$$bar. Would that also be $yo? Or am I forgetting something? Inquisitus posted:Not really sure what's being asked here. Are you asking how exponentials are computed algorithmically? Yeah, I guess this is what I am asking for. I just remember seeing a question with that junk in it, and I was like huzzaah? I haven't seen that since h.s. alegbra, and haven't needed it since. It was a test to check my skills in the language, which weren't good, but I was thrown off by the exponent stuff. I don't even remember how they work. Isn't that why we have computars? I know it's good to know, but I just don't remember them, or how they are applied in PHP. hallik fucked around with this message at 06:38 on May 11, 2008 |
# ? May 11, 2008 05:47 |
|
Anveo posted:It is stored in memory, but you have the overhead of TCP to access it, plus network latency if the server you are accessing isn't the local one. Bah, poo poo like this is why I prefer to use FastCGI+C. There is no reason for something like memcache to run slower than a flat file read. At least if you roll your own poo poo you know exactly how fast it's gonna be. hallik posted:So $bar = 'yo'; if $bar = "lol" and $lol = "wut" then $$$bar == $wut
|
# ? May 11, 2008 08:43 |
|
Quote != edit.
|
# ? May 11, 2008 08:45 |
|
hallik posted:Yeah, I guess this is what I am asking for. I just remember seeing a question with that junk in it, and I was like huzzaah? I haven't seen that since h.s. alegbra, and haven't needed it since. It was a test to check my skills in the language, which weren't good, but I was thrown off by the exponent stuff. I don't even remember how they work. Isn't that why we have computars? I know it's good to know, but I just don't remember them, or how they are applied in PHP. You really don't need to know how exponentials are actually computed at the algorithmic level. I don't know myself, but I imagine it'd be something to do with Taylor expansions. If you just want to get the result of an exponential with base e, then use PHP's exp function. Inquisitus fucked around with this message at 10:05 on May 11, 2008 |
# ? May 11, 2008 10:02 |
|
Inquisitus posted:You really don't need to know how exponentials are actually computed at the algorithmic level. I don't know myself, but I imagine it'd be something to do with Taylor expansions. Good to know. This was one of those questions that was like "what is the result? a) 13, b) 14, c) 15 etc... I will just read up on exponents and what the ^ function does. It's really stupid I was actually asked that I thought. And your response confirms, at least in my mind, it was a dumb question to ask on a php 'prove it' test...
|
# ? May 11, 2008 10:07 |
|
Dominoes posted:I just learned PHP, and set up a simple script to email me submitted form data. I have a small problem that I"m hoping someone can help me with. I just asked about PHP mailing libraries one page ago and at the end I found the Swift library, which filters the data for you. I recommend it, works nicely and I got it set up and working in a matter of minutes.
|
# ? May 11, 2008 12:04 |
|
what the hell I'm trying to have a user upload an image and then I resize it with gd and save it. I'm using a mix of functions that I got from php.net and some other place. Thing is, it works for very small images, but if I try a bigger image (like 250k), I get this error message code:
I could post the functions I use to convert the images but they're pretty long, basically it's just finding out what the type of the image is with a lot of case structures, then it calculates the new width and height and then it calls imagecopyresampled and then it saves it. hey mom its 420 fucked around with this message at 17:32 on May 11, 2008 |
# ? May 11, 2008 17:28 |
|
Bonus posted:what the hell The error message is a little misleading. It means that PHP was already using its maximum memory size and tried to allocate an additional 7500 bytes over the limit.
|
# ? May 11, 2008 17:42 |
|
Atom posted:Bah, poo poo like this is why I prefer to use FastCGI+C. There is no reason for something like memcache to run slower than a flat file read. At least if you roll your own poo poo you know exactly how fast it's gonna be. Memcached is pretty efficient C, you just need to remember it is by design a network distributed memory cache and not a local memory cache, so it makes perfect sense it will be slower than a local file read. It is still fast and awesome. No need to rewrite things yourself, if you mistook it for a local memory cache just use one that already exists and suggested before such as shm functions or apc.
|
# ? May 11, 2008 17:55 |
|
Bonus posted:
JPEG images take up much more space when loaded into RAM because they get decompressed. Plus, I bet you're making multiple copies of it in RAM. Is the 7.5k image fairly large in dimension too? I don't know if it works, but when you're done with a certain instance of an image, you might try using unset() on the variable containing that instance to free up some RAM. Or you could do what I did for my image uploader and raise the php.ini memory limit to 24 MB using ini_set(). Zorilla fucked around with this message at 01:34 on May 12, 2008 |
# ? May 11, 2008 19:45 |
|
That's why you always use image_destroy when you're done with that copy of the image.
|
# ? May 11, 2008 20:27 |
|
Zorilla posted:Probably something like this: Thanks, that worked! It actually doesn't wait 3 seconds and redirect to the "url=whatever", it immediately goes to the home page. That's more than adequate for now. noonches posted:At the very top of the page put ob_start() and after the echo put: It gives me PHP errors. Thanks though. Bonus posted:One word of advice: You are receiving data from the user and putting it directly into emails that you send. Much like putting in data from the user into the database without escaping it, you're leaving yourself open for an injection attack here. Only here it's a header injection attack, meaning that anyone can use your email form to send spam from your server to anyone, not just you. This is okay if you're just learning how emails in PHP generally work, but if you're going to be putting it up for use, it's a good idea to filter it. I'll try and experiment with that later, but I hadn't touched PHP before yesterday, so I'm trying to keep it simple first.
|
# ? May 11, 2008 21:17 |
|
Dominoes posted:Thanks, that worked! It actually doesn't wait 3 seconds and redirect to the "url=whatever", it immediately goes to the home page. That's more than adequate for now.
|
# ? May 12, 2008 00:19 |
|
Thanks guys, I managed to solve it by adding around more calls to free up resources and such. Also, here's something that drove me up the wall today. IE uploads jpg files as image/pjpeg while other browsers do it as image/jpg. I spent at least an hour and then some running around trying to find out why images uploaded with IE don't work, because I was turning the second part of the MIME type directly into the extension. Ugh!
|
# ? May 12, 2008 00:42 |
|
Bonus posted:because I was turning the second part of the MIME type directly into the extension. Ugh! That can be changed by the user so never do that, use content sniffing.
|
# ? May 12, 2008 01:00 |
|
I just hit a snag. When you submit a form, if a checkbox is not checked the resulting POST data doesn't have an element name with no value, it doesn't submit anything at all relating to the check box. The script that receives the POST data does not know the name of the checkboxes. This form does a db update, and if the boxes are not checked the resulting fields are never set to zero, they just remain at their old value since they don't appear in the update.
|
# ? May 12, 2008 02:39 |
|
Kaluza-Klein posted:I just hit a snag. e: I misread that part about not knowing the post names, whoops.
|
# ? May 12, 2008 02:55 |
|
[edit] never mind. Didn't see the crazy "my script doesn't know what I am sending it" caveat.
Lumpy fucked around with this message at 02:58 on May 12, 2008 |
# ? May 12, 2008 02:56 |
|
Kaluza-Klein posted:I just hit a snag. Do you know the names of all the table fields? If so just update them all to zero, and then update them again with the form data.
|
# ? May 12, 2008 03:18 |
|
Anveo posted:Do you know the names of all the table fields? If so just update them all to zero, and then update them again with the form data. Yes, I can get those. I will have to query for the table field names, and if I don't have a $_POST to match it then it gets set to 0. A bit off topic, but it seems like when submitting forms values all form elements should be sent, even if they are null or blank or disabled etc. There are probably good reasons why they are not, but I have yet to notice them.
|
# ? May 12, 2008 03:23 |
|
Anveo posted:Memcached is pretty efficient C, you just need to remember it is by design a network distributed memory cache and not a local memory cache, so it makes perfect sense it will be slower than a local file read. It is still fast and awesome. Well yeah but still in the degenerate case of one machine in the distribution, it should just degrade into normal memory caching. Of course, it doesn't matter anyways because we're piddling over what probably winds up being a small fraction of the execution time anyways.
|
# ? May 12, 2008 09:34 |
|
Kaluza-Klein posted:Yes, I can get those. I will have to query for the table field names, and if I don't have a $_POST to match it then it gets set to 0. Can you not do php:<?php //ice cream flavour chooser if (isset($_POST['checkboxes'])) { $to_check = unserialize($_POST['checkboxes']); foreach ($to_check as $flavour) { if (isset($_POST[$flavour])) { //doWhateverYouNeedToDo if checkbox is selected } else { //checkbox wasnt selected } } } $checkboxes = array ("Chocolate", "Vanilla", "Pastis"); echo '<form action="flavour_picker.php" method="POST" />'; foreach ($checkboxes as $checkbox) { echo $checkbox.'<input type="checkbox" name="'.$checkbox.'" />'; } echo '<input type="hidden" name="checkboxes" value="'.serialize($checkboxes).'" />'; echo '<input type="submit" name="submit" value="Submit" />'; echo '</form>'; ?>
|
# ? May 12, 2008 11:50 |
|
I can't seem to find a good tutorial on how to enter a birth date in a user registration form. I'm not sure how I should store it in my database, or how to parse it to that format. Should I go with one input box and do a lot of parsing to figure out which of the inputs are numbers, and which are slashes or dashes, or do some sort of 3 box setup and put it all together?
|
# ? May 12, 2008 17:49 |
|
raej posted:I can't seem to find a good tutorial on how to enter a birth date in a user registration form. I'm not sure how I should store it in my database, or how to parse it to that format. I generally do three input boxes that already have MM DD YYYY in them as it takes less time to write parsing from different possible entry types to a timestamp. Use mktime() to change the input(s) you get from the form into a timestamp and then store it as a TIME (or maybe DATETIME?) in your database.
|
# ? May 12, 2008 17:56 |
|
Evil Angry Cat posted:I generally do three input boxes that already have MM DD YYYY in them as it takes less time to write parsing from different possible entry types to a timestamp. Use mktime() to change the input(s) you get from the form into a timestamp and then store it as a TIME (or maybe DATETIME?) in your database. Oooh, that seems a lot easier than I was thinking. Thanks!
|
# ? May 12, 2008 18:06 |
|
I have a question about configuration. When I set up PHP on my local machine I have tried giving it Lat/Long and a regular timezone (and both), but it keeps translating that into America/Chicago. That's the correct time and whatnot, but not an actual time zone that people recognise. They assume its a location (go loving figure). Can I get it to use real time zones instead of the made up crap that the open source community seems to be fond of without messing around with the time zone database?raej posted:I can't seem to find a good tutorial on how to enter a birth date in a user registration form. I'm not sure how I should store it in my database, or how to parse it to that format. Do either a 3 box setup with dropdowns and validate it with checkdate or you could let them type it in and pass it to strtotime (or a similar function)*, which is going to be much better at parsing dates than anything you could write by yourself in a reasonable amount of time. I don't have any advice about database storage, but I know MySQL has a DateTime type or something similar. *There could be a security concern, but if there is, I'm shure if you give it a second someone else will probably mention that and call me an idiot for suggesting passing user input to strtotime.
|
# ? May 12, 2008 18:08 |
|
Evil Angry Cat posted:I generally do three input boxes that already have MM DD YYYY in them as it takes less time to write parsing from different possible entry types to a timestamp. Use mktime() to change the input(s) you get from the form into a timestamp and then store it as a TIME (or maybe DATETIME?) in your database. Why store a date as a TIME in your database? Why not store it as, I don't know, a DATE?
|
# ? May 12, 2008 18:17 |
|
duz posted:Why store a date as a TIME in your database? Why not store it as, I don't know, a DATE? I've never really heard of a datestamp before have you?
|
# ? May 12, 2008 18:29 |
|
Evil Angry Cat posted:I've never really heard of a datestamp before have you? No, which is why I said DATE.
|
# ? May 12, 2008 19:08 |
|
duz posted:No, which is why I said DATE. The reason I store as a timestamp rather than using MySQLs inbuilt DATE type is because I personally find it easier to manipulate with php. Apologies, it's been so long since I used DATE that I'd forgotten it wasn't just another timestamp type.
|
# ? May 12, 2008 23:07 |
|
It's easy to convert from a MySQL DATETIME field to a timestamp by using the UNIX_TIMESTAMP MySQL function or to convert from a timestamp to a DATETIME field by using the FROM_UNIXTIME MySQL function, so in the end it largely depends on preference.
|
# ? May 12, 2008 23:26 |
|
What is the best approach to stop sql injections? Should I just use mysql_real_escape_string before inputting the variables into mysql? Is there anything else I should do?
|
# ? May 13, 2008 18:07 |
|
cLin posted:What is the best approach to stop sql injections? Should I just use mysql_real_escape_string before inputting the variables into mysql? Is there anything else I should do? mysql_real_escape_string is about all you need. For simplicity's sake you can also just use intval() if the value's going to be an integer.
|
# ? May 13, 2008 18:12 |
|
cLin posted:What is the best approach to stop sql injections? Should I just use mysql_real_escape_string before inputting the variables into mysql? Is there anything else I should do? Use an abstraction layer like MDB2 and use prepared statements. It'll handle type checking and everything for you.
|
# ? May 13, 2008 18:44 |
|
I use ADOdb, it's pretty cool, especially parametrization, where you do $db->execute("SELECT * FROM foo WHERE foo.bar = ?", array("baz"))
|
# ? May 13, 2008 18:47 |
|
Anyone know of a good resource for how to implement a user management system in a *AMP environment? I want to make one that's pretty basic, should be able to: self-register login add data edit data maintain a session (don't know much about this end...) As far as password storage goes, is it best just to use PHP encryption methods to encrypt/store and decrypt/authenticate, or is there more the database should do? I dug around to see if there was a way to auto-encrypt a column in MySQL but didn't see much. Thanks!
|
# ? May 13, 2008 19:21 |
|
duz posted:Use an abstraction layer like MDB2 and use prepared statements. It'll handle type checking and everything for you. I'm guessing it's similar to the post below yours where you just execute a sql query using one of their methods, but are either of these small in size? I don't want to make a program even slower by including a big file.
|
# ? May 13, 2008 19:40 |
|
|
# ? May 16, 2024 18:20 |
|
cLin posted:I'm guessing it's similar to the post below yours where you just execute a sql query using one of their methods, but are either of these small in size? I don't want to make a program even slower by including a big file. You can use PDO too https://www.php.net/PDO code:
Its not bundled with all distributions of PHP 5 though, so YMMV.
|
# ? May 13, 2008 20:05 |