MrMoo posted:That's generally what AJAX is for. Why make the extra request if I'm rendering other things just like it already there in the template though?
|
|
# ? Apr 7, 2009 07:28 |
|
|
# ? May 29, 2024 08:27 |
|
486 posted:How are you storing the time? What format? You likely need to convert your old times and save your new times with one of PHP's many handy date functions
|
# ? Apr 7, 2009 12:19 |
How do I round up a number if a division doesn't have an integer as the result? Examples: 8 stays 8 7.58333 becomes 8 7.00001 becomes 8 The only thing I have is checking the result with !is_int(), but I have no idea how to round the number up to the next integer.
|
|
# ? Apr 8, 2009 03:16 |
|
fletcher posted:Why make the extra request if I'm rendering other things just like it already there in the template though? Nobody cares, whichever is the easiest to implement and look after is the correct answer.
|
# ? Apr 8, 2009 03:16 |
|
Uncle Marx posted:How do I round up a number if a division doesn't have an integer as the result? ceil()
|
# ? Apr 8, 2009 03:24 |
FeloniousDrunk posted:ceil()
|
|
# ? Apr 8, 2009 03:30 |
|
There are some pages on php.net that, if we aspire to being any form of php programmer, we should all at least scan through to look at what the functions in each list do: http://php.net/manual/en/ref.math.php http://php.net/manual/en/ref.strings.php http://php.net/manual/en/ref.array.php We've decided to dine at the PHP restaurant; we might as well flip through the menu. Nobody needs to memorise all of these (I check the parameter order of strpos and in_array probably once a month - check them out to see why I have to do this!). I also infrequently browse through the lists to see what functions I've been ignoring or reinventing. But having scanned it all at least once, means that you'll at least remember that there were LOTS of array sorting functions, not just a couple - then you can go see if one does what you really need right now... A quick scan through will tell you all the neat functions you have available to do the really common things. Or it will tell you what PHP calls your favourite functions from other languages. Or in some cases it'll introduce you to really weird functions that solve obscure corner cases. Seriously; its worth reading through what all the various XsortYZ functions for arrays actually do. In some cases just to think to yourself; who the christ actually NEEDED that? There are many things you can complain about regarding PHP. My favourite at the moment is that class constants have to be explicitly scope-resolved INSIDE the defining class! (seriously; no default to local scope? what?) But lack of basic docs isn't one of them. Awkwardly arranged docs isn't either. I'm not raging against anyone's questions, honest. Just occurred to me that those 3 urls can solve maybe 20% of 'is there a function for ...' questions in this thread? Also: php:<? class Numpty { const MYCONST = 3; public $a = MYCONST; // failure! public $b = self::MYCONST; // WHY?!? Why must I do this? } ?>
|
# ? Apr 8, 2009 13:45 |
|
Can anyone think of a good reason that putting this:php:<? if(!function_exists('udbError_sendErrorReply')) { function udbError_sendErrorReply($errMsg,$error_id){ include_once('udbGlobal.php'); $reply = $xmlHeader; $reply .= "<USER id=\"\">\n"; $reply .= "<STATUS>ERROR</STATUS>\n"; $reply .= "<ERROR>$error_id</URL>\n"; $reply .= "<ERROR_MESSAGE>$errMsg</ERROR_MESSAGE>\n"; $reply .= "<DEBUG></DEBUG>\n"; $reply .= "</USER>\n"; print $reply; return $reply; } } ?> Please do me a favor and ignore anything weird going on in the actual function I pasted up there thanks. Munkeymon fucked around with this message at 15:39 on Apr 8, 2009 |
# ? Apr 8, 2009 15:37 |
|
I've got a block of PHP that needs to avoid concurrent execution. I've thought about writing a small library which uses flock to LOCK_EX a lockfile, and then LOCK_UN when done, so other threads* will wait to acquire their LOCK_EX on said lockfile. It seems PHP will indeed block on a call to flock with a LOCK_EX parameter. http://ca3.php.net/manual/en/function.flock.php http://www.tuxradar.com/practicalphp/8/11/0 Is this a Bad Idea (tm)? * When I say "other threads", I don't mean to imply that PHP itself is multi-threaded in the traditional sense, but web programming is inherently concurrent in that two users clicking the same button at the same time may cause the web server to execute the same script twice, and have both instances running concurrently.
|
# ? Apr 8, 2009 17:45 |
|
I have some returned XML data in $xml using simplexml_load_file() and I want to extract $someTitle from it from $xml->a->b->c->d->Title , how would I go about doing so? Thanks in advance
|
# ? Apr 8, 2009 17:55 |
|
Safety Shaun posted:I have some returned XML data in $xml using simplexml_load_file() and I want to extract $someTitle from it from $xml->a->b->c->d->Title , how would I go about doing so? http://us.php.net/manual/en/function.simplexml-element-xpath.php You are welcome.
|
# ? Apr 8, 2009 19:39 |
|
Munkeymon posted:Can anyone think of a good reason that putting this:
|
# ? Apr 8, 2009 20:03 |
|
epswing posted:I've got a block of PHP that needs to avoid concurrent execution. I've thought about writing a small library which uses flock to LOCK_EX a lockfile, and then LOCK_UN when done, so other threads* will wait to acquire their LOCK_EX on said lockfile. It seems PHP will indeed block on a call to flock with a LOCK_EX parameter. That looks like it would work for what you need to do. For the one time I needed to prevent concurrency issues, I just used a PID file since it would catch the new stuff anyways.
|
# ? Apr 8, 2009 20:52 |
|
duz posted:That looks like it would work for what you need to do. For the one time I needed to prevent concurrency issues, I just used a PID file since it would catch the new stuff anyways. Any PID file in particular, and if so, why? What do you mean by "the new stuff"?
|
# ? Apr 8, 2009 21:16 |
|
supster posted:Is it in a class? Nope, but I figured out that, in one case, the other file that defines udbError_sendErrorReply - where there is no guard for function existance - gets included second. It just wasn't clear that was what was going on from the error message. It's all a clusterfuck caused by a stupid decision on someone else's part. Namely, to put the error reporting functionality in a different file then call it without checking to see if it exists and rely on people including both every time.
|
# ? Apr 8, 2009 22:23 |
|
epswing posted:Any PID file in particular, and if so, why? In this case, an external program was putting data into a database for processing. The PHP script in question was called by cron every 60 seconds which when ran it would check the database for new data. The PID file was made/opened when the script started and was removed when it was done. If the PID file already existed, the script would stop since there was already one running. The script's execution wasn't data bound so it would process whatever data was there. Maybe not the best way to handle it, but it was a legacy system and had odd restraints.
|
# ? Apr 8, 2009 22:53 |
|
If I need a user authentication system for something that isn't really critical to having some very strong security on, but I don't want it to be stupidly simple for someone to take advantage of everything, is using PHP's crypt() ok or should I be using something different.
|
# ? Apr 9, 2009 03:56 |
|
If you just need 'must enter password to access' use .htaccess + .htpasswd (google '.htaccess password protect directory' for how to setup) Thats the easiest/fastest way to set it up, just have to put all the protected content into a separate directory then setup .htaccess for it. Remember to put your password file either outside you document root, or if you can't in a dir of its own with a .htaccess of 'deny from all', so it cannot be browsed to.
|
# ? Apr 9, 2009 08:43 |
|
KuruMonkey posted:If you just need 'must enter password to access' use .htaccess + .htpasswd (google '.htaccess password protect directory' for how to setup) Thanks for the advice. I would like a nice form UI though and I also want a session associated with each user. It's not that important in that the information that this login is protecting isn't really critical and no one would care that much if other people got into their account. It's important in that I would like it to look nice and like a regular web application.
|
# ? Apr 9, 2009 14:11 |
|
sonic bed head posted:Thanks for the advice. Crypt is fine, just make sure you use a different random salt each time.
|
# ? Apr 9, 2009 14:53 |
|
I'm having problems using prepared statements and I'm hoping someone can point out my horrible error.php:<? $qryInsert = ' INSERT INTO sessions ( user_id, ip_address, session_start, session_end, ) VALUES ( :user_id , :ip_address , :session_start , :session_end ) '; $aSession = array('user_id' => $userId, 'ip_address' => $ipaddress, 'session_start' => $now, 'session_end' => $expiry); dbQuery($qryInsert, $aSession); function dbQuery($stmt, $aParams) { try { $v = $this->dbo->prepare($stmt); } foreach($aParams as $key => $value) { $v->bindParam(':'.$key, $value); } $v->execute(); return $v->fetchAll(); } catch (PDOException $e) { $this->handleError($e); } } ?> I can't figure what I'm doing wrong here. Edit: the connection has already been made etc. so I cut that code out. Edit again: Nevermind, just figured it out. I should be using bindValue(); Stephen fucked around with this message at 20:34 on Apr 9, 2009 |
# ? Apr 9, 2009 20:30 |
|
Stephen posted:Edit again: Nevermind, just figured it out. I should be using bindValue(); edit: hint: it has to do with how foreach loops work. supster fucked around with this message at 21:56 on Apr 9, 2009 |
# ? Apr 9, 2009 21:40 |
|
supster posted:It's somewhat important that you understand why this is, so make sure you do. Otherwise you will likely run into other problems down the road.
|
# ? Apr 9, 2009 21:57 |
|
Anyone else excited for 5.3? Anyone test with RC1? Any insight?
|
# ? Apr 12, 2009 09:49 |
|
Pfffft. It'll be 2 years before thats on any server I work on. The bleeding edge of PHP is just about the top of my list of places not to be.
|
# ? Apr 12, 2009 12:04 |
|
supster posted:Anyone else excited for 5.3? Anyone test with RC1? Any insight? I am, though no idea when we'll be seeing it on our production servers after release. It'll be great to have namespace support and late static binding though.
|
# ? Apr 12, 2009 14:28 |
|
I'm learning OOP from a pretty fantastic book (so far): PHP Object Oriented Solutions by David Powers. Anyway, he regularly says this "-> operator". Is there a name for '->'? How the hell do I tell someone what I am talking about in plain English?
|
# ? Apr 12, 2009 21:27 |
|
member access operator edit: fnar fnar
|
# ? Apr 12, 2009 21:59 |
|
I need to do a database export from within a PHP application (without using mysqldump) similar to how phpMyAdmin does it. I've searched around a bit and surprisingly did not find anything that did this - does anyone havea any suggestions?
|
# ? Apr 12, 2009 23:14 |
|
supster posted:I need to do a database export from within a PHP application (without using mysqldump) similar to how phpMyAdmin does it. I've searched around a bit and surprisingly did not find anything that did this - does anyone havea any suggestions? Well probably since phpmyadmin is written in PHP, you can find out how it does a dump, and just copy/adapt that. On the copy I'm looking at (version 2.9.2), it's in export.php around line 461, the line code:
|
# ? Apr 13, 2009 03:59 |
|
You can't really use mysqldump through PHP (system() is almost always disabled). I know exactly how phpMyAdmin does it, I was just trying to avoid having to rewrite it all (phpMyAdmin is GPLed and I can't just grab theirs). Anyway I've already resorted to writing an exporter akin to phpMyAdmin's - it wasn't that bad, just a bit tedious.
|
# ? Apr 13, 2009 04:24 |
|
eHacked posted:I'm learning OOP from a pretty fantastic book (so far): PHP Object Oriented Solutions by David Powers.
|
# ? Apr 13, 2009 06:59 |
|
KuruMonkey posted:member access operator gibbed posted:-> is officially called the object operator (T_OBJECT_OPERATOR). Yeah, object operator sounds like it's the right answer (although I don't have anything to back it up). I find that putting an actual name to things make it much easier to learn/work with/remember. Thanks, gibbed.
|
# ? Apr 13, 2009 16:42 |
|
eHacked posted:I'm learning OOP from a pretty fantastic book (so far): PHP Object Oriented Solutions by David Powers. "The thing that most other languages use a dot for" At least that's what I call it. Was interesting to learn the actual name for it.
|
# ? Apr 13, 2009 18:41 |
|
I'm writing a website that has a lot of PHP files that need access to a DB (almost all of them do). Now, in order to avoid having to type something likephp:<? $conn = pg_connect('dbname=database user=username password=password');?> My questions: Is what I'm doing a security risk (that is, could someone else do a require_once(FULL_PATH/dbconnect.php) and get access to my DB?)? How do you guys deal with this problem? Thanks!
|
# ? Apr 18, 2009 08:58 |
Fangs404 posted:My questions: Is what I'm doing a security risk (that is, could someone else do a require_once(FULL_PATH/dbconnect.php) and get access to my DB?)? How do you guys deal with this problem? If that was a security risk then wouldn't the user also be able "do a pg_connect('dbname=database user=username password=password');". It's the exact same thing as require_once, they are just PHP functions. Yes, somebody could potentially include that file in a malicious way if they share the same server as you and your host is dumb enough to setup security permissions like that. Hopefully this is unlikely. As far as a user hitting your website and executing a line of PHP like that, it would not be possible unless you had some poorly written image uploader and some hosed up permissions. Also, check out using something like PDO for interacting with a database. I typically grab a database connection like: php:<? $database = Database::getConnection(); $query = $database->prepare("select what from huh where this = :that"); $query->bindParam(":that", $that); ?> fletcher fucked around with this message at 09:51 on Apr 18, 2009 |
|
# ? Apr 18, 2009 09:45 |
|
Fangs404 posted:I'm writing a website that has a lot of PHP files that need access to a DB (almost all of them do). Now, in order to avoid having to type something like Put anything that stores info you don't want known outside of web root. For example, if your web site is stored at: /blah/some/path/webRoot/ Then have your files with db passwords and other stuff at: /blah/some/path/hideMe/ And the web server can't serve the files up at all to people.
|
# ? Apr 18, 2009 16:09 |
|
Awesome, thanks guys.
|
# ? Apr 18, 2009 19:51 |
|
edit: Question deleted. Found an easier way to do this
indulgenthipster fucked around with this message at 20:50 on Apr 20, 2009 |
# ? Apr 20, 2009 18:04 |
|
|
# ? May 29, 2024 08:27 |
|
OK, I've got a retard simple php question, I'm sure. But here it goes anyway I have a huge list of IF->Then type statements in a page template. The reason is I have no idea how many items need to be displayed...could be anywhere from 0 - 200. So what I'm doing now is putting a huge list like this: code:
|
# ? Apr 21, 2009 19:51 |