|
Wrote yourself a fancy image uploading script and want us to point out the problems? Can't figure out how to get rid of the mysterious slashes in the data from your form? Don't know why the slashes should probably be there? Need help writing OOP in PHP5? This thread will be for all that and any other PHP related issue. It does not have to be web related to be asked in here. The official site has extremely useful documentation. itskage has written up a handy guide to getting a useful dev environment setup on windows. If you're a *nix user, you should know which steps to skip. itskage posted:This has become less of a "copy the guide from these mark down files" and more of a "Retype the jist of stuff into a forums post". Sorry but there's more company specific stuff in them than I remembered, and it was quite long and I was fighting with the lack of md formatting, so I cut it down a lot, and now it is like a text dump, but hopefully it's useful to someone. duz fucked around with this message at 15:09 on Jan 18, 2021 |
# ¿ Mar 19, 2008 20:36 |
|
|
# ¿ Apr 29, 2024 12:27 |
|
fletcher posted:Can you combine a function call that returns an array with the array index you want like: Naw, can't do that in PHP. Javascript can do what you want, don't know off hand what else could.
|
# ¿ Mar 19, 2008 23:25 |
|
Kaluza-Klein posted:I want to parse an html file. For example, say I want to know what is contained inside an <h1> tag. I can do this with strstr and substr but it is ugly. You can use a combination of HTMLTidy to clean up the HTML and SimpleXML to search the document. php:<? $config = array( 'indent' => true, 'output-xhtml' => true, 'wrap' => 200); $tidy = new tidy; $url = 'http://www.example.com/index.html'; $tidy->parseFile($url, $config); $tidy->cleanRepair(); $doc = new DOMDocument(); $doc->loadHTML($tidy); $html = simplexml_import_dom($doc); $h1 = $html->xpath('//h1[@id="main"]'); ?>
|
# ¿ Mar 22, 2008 16:57 |
|
Daddy Fantastic posted:Are there any benefits to using MDB2, assuming I'm already using mysqli prepared statements, won't be switching away from mySQL, and I'm not already using PEAR? If you're already using prepared statements, then probably not.
|
# ¿ Mar 22, 2008 19:47 |
|
Daddy Fantastic posted:Is there a fancy one line PHP trick that could replace this foreach loop? php:<? if (in_array($password, $b)) { // whatever } ?>
|
# ¿ Mar 25, 2008 19:28 |
|
Daddy Fantastic posted:I'm not sure that will work though, since $password could be any length-- in other words, I'd like it to match words that include the banned words, but may contain other letters (like dookieq). In that case no, the only other way I can think to do it would be to use a callback function with something like array_filter but that would take about the same amount of lines. Edit: Or you could collapse the array to a single string but that could introduce false positives.
|
# ¿ Mar 25, 2008 21:13 |
|
Kaluza-Klein posted:Should you not escape the forward slash in the closing tag? Yes, you should. However the forums like to eat escaping slashes.
|
# ¿ Mar 28, 2008 18:39 |
|
bt_escm posted: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. Correct. In PHP5, if a scope isn't declared it's assumed to be public because there was no scope in PHP4.
|
# ¿ Mar 28, 2008 20:27 |
|
Finite posted:It looks like you're using a database abstraction layer. Use its built in prepared query functions instead of string concatenations. It also looks like you're using PEAR::DB, any chance you can upgrade to MDB2?
|
# ¿ Mar 29, 2008 02:34 |
|
Uh, you're outputting text instead of an image. Get rid of that html nonsense.
|
# ¿ Mar 31, 2008 20:51 |
|
MrEnigma posted:or move the header right before it. One other piece of advice, usually you want your functions to always return data, instead of printing it out. And then do a print/echo/whatever on on the function on your page. You can't send headers after outputting content.
|
# ¿ Mar 31, 2008 21:00 |
|
That's because you're still outputting text instead of the image your header is telling the browser to expect.
|
# ¿ Mar 31, 2008 21:12 |
|
fletcher posted:Which has corrected the malformed html. Is this a bad solution? You could probably also use HTMLTidy to clean it up.
|
# ¿ Apr 1, 2008 02:29 |
|
drcru posted:What kind of timestamps are these? The roll-your-own kind. Good luck figuring out that system! duck monster posted:Another tip, not really php, is hunt down an old javascript library called 'fvalidate' for the javascript side of it. But remember NEVER rely on javascript validation. fvalidate is neat however, since it just involves setting alt tags on input fields. Setting the alt tags is kind of neat, since it validates, and normally alt tags have no real role on input fields, so they are handy for hijacking for metadata. Alt tags on inputs are for screen readers. jQuery has a nice form validation plugin that uses class names or you can use JSON to build you validation requirements. Treytor posted:Without using curl, but fopen instead? Edit: duz fucked around with this message at 03:50 on Apr 1, 2008 |
# ¿ Apr 1, 2008 03:37 |
|
Treytor posted:Instead of using explode and what not, look up fgetcsv and fputcsv.
|
# ¿ Apr 2, 2008 04:25 |
|
I helped him out with what he needed to do to access a DB and wrote the SQL query needed. I'm guessing everything worked out.
|
# ¿ Apr 2, 2008 17:58 |
|
omgwtfnoway posted:I'm trying to use exec() in a php script to add and commit some files to SVN. Install the SVN PECL extension then do it natively.
|
# ¿ Apr 3, 2008 03:49 |
|
OlSpazzy posted:Also, the evals are necessary, without them unp_printTemplate('comments_list_commentbit') returns, for example: eval is never necessary. Especially not when all you're doing is string replacement.
|
# ¿ Apr 4, 2008 19:37 |
|
Finite posted:I do it in a few places to do things like... You're supposed to use braces when you want the contents of a variable. php:<? $string = "The quick {$data['colour']} fox jumps over the lazy dogs." ?>
|
# ¿ Apr 4, 2008 20:29 |
|
admiraldennis posted:Thats the only way one should include variables within a double-quoted string, in my opinion. Either that or with a concatenation. It's borderline ambiguous otherwise and hurts readability. And braces allows you to do crazy things like: php:<? $variable = 'something'; $obj->a = 'variable'; echo ${$obj->a}; ?>
|
# ¿ Apr 4, 2008 22:05 |
|
Scarboy posted:I disagree. If you're going to be outputting this, and it's data from the user then I would use sprintf and wrap the variable in htmlentities() (I don't write PHP much, is this the correct function to use?) to not allow html/js injection. Ideally you'd have already sanitized it by the time you output it.
|
# ¿ Apr 5, 2008 01:22 |
|
Zorilla posted:Right, I was just trying to prevent users from embedding HTML into pages. For stuff that's to run on servers I can't control, I put this at the start of my script(s) php:<? if (get_magic_quotes_gpc()) { if (!function_exists(stripslashes_array)) { function stripslashes_array($array) { return is_array($array) ? array_map('stripslashes_array', $array) : stripslashes($array); } } $_GET = stripslashes_array($_GET); $_POST = stripslashes_array($_POST); $_REQUEST = stripslashes_array($_REQUEST); } ?>
|
# ¿ Apr 7, 2008 01:25 |
|
You can have constructors run the parent's constructors or you can have your queries just use the last used connection.
|
# ¿ Apr 7, 2008 18:30 |
|
Safety Shaun posted:Any help or pointer towards this would be appreciated. Try using mod_rewrite instead. Much easier and less server load. http://isnoop.net/dev/mod_rewrite.php
|
# ¿ Apr 14, 2008 04:50 |
|
You probably want to do a Natural Sort.
|
# ¿ Apr 16, 2008 19:56 |
|
awdio posted:
It's slow because you're reversing the array each time you loop.
|
# ¿ Apr 16, 2008 22:20 |
|
awdio posted:Yeah I see that, but even if I put the array_reverse($files) after natsort, it won't permanently do anything because its not resorting the array. Also putting rsort after the natsort will do away with the natsort. Read the docs. array_reverse returns the reversed array. You'll need to do $files = array_reverse($files);.
|
# ¿ Apr 16, 2008 22:35 |
|
LastCaress posted:As I said, my coding experience is null. I can run the server in php4 and the code has no problem, and when I put it in php5 there are problems, so obviously the problem is there. The "problem" is that PHP5 has increased security and since the code is poorly written, it's getting tripped up.
|
# ¿ Apr 21, 2008 16:37 |
|
Zorilla posted:The variable you're checking for is $_POST["instance"] (or $_GET["instance"] depending on the form action) and its value is probably true if checked and false if not. I'm not 100% on this Checkboxes will not appear in _GET/_POST if they are not checked. If they are checked, they will contain the contents of the value attribute. I don't know what they contain if there is no value attribute.
|
# ¿ Apr 21, 2008 21:26 |
|
Possym posted:It includes toc.php every time! I'm not experienced with sessions at all, did I do something to mess it up on accident? Are you running session_start(); before you start messing with sessions or outputting anything?
|
# ¿ Apr 21, 2008 23:57 |
|
Snozzberry Smoothie posted:I need to generate XML with a PHP script, but I'm unsure of the best method from a performance perspective. Can anyone give me some advice or point me at a resource that I can read more on the topic? Use SimpleXML. It makes it so easy. Zorilla posted:Ok, I was trying using $_COOKIE in conjunction with $_SESSION without adjusting the default timeout value of "0" before giving up the first time, then only using $_SESSION when I tried setting cookie timeout the next time, so you can see why things didn't work. Looks like I've got a bit of modifications to do. Sessions expire when the browser closes or after 24 minutes of inactivity. What you want are cookies. The cookie will store a unique ID/hash that points to an entry in your database with the session information.
|
# ¿ Apr 22, 2008 09:02 |
|
Zorilla posted:Ok, so this sounds like I actually have to create a MySQL table whose purpose is to store hashes that coordinate with remote users' cookies. Am I way off here? Unless you want to store sensitive information in a cookie that's readable by anyone. The table could consist of just two columns, a session id and the serialized session data. It's really up to you how you want to do it.
|
# ¿ Apr 22, 2008 09:49 |
|
Grigori Rasputin posted:Oh, another quick one that's more of a general *AMP/database question. Should I store timestamps in the format generated by PHP's mkdate() or MySQL's native date format? Storing them as the databases' native date format has the advantage that you know it's a date because it says so and not because the program uses it as one.
|
# ¿ Apr 23, 2008 20:22 |
|
Don't forget post_max_size as well as any database size limits.
|
# ¿ Apr 28, 2008 20:27 |
|
Zorilla posted:Shouldn't referrer handling be done though .htaccess? Ideally.
|
# ¿ May 3, 2008 04:20 |
|
Why not just use absolute paths?
|
# ¿ May 4, 2008 23:38 |
|
If it's static you can just dophp:<? readfile('footer.html'); ?> php:<? include('footer.php'); ?>
|
# ¿ May 7, 2008 21:21 |
|
Atom posted:If this is a serious issue for you, you can use memcache or (harder to write, more optimized) write php that generates php code based on the contents of the db. The risk of somebody rewriting the .html files isn't any more than the risk of someone rewriting the code that includes it in a properly secured system. Or just use readfile which doesn't execute anything.
|
# ¿ May 7, 2008 23:39 |
|
I use PEAR:Mail
|
# ¿ May 8, 2008 15:45 |
|
|
# ¿ Apr 29, 2024 12:27 |
|
Kaluza-Klein posted:I would use empty() and a do-while loop, but I don't have any formal training at all. Don't even have to do that much, array_search() should take care of it with one line. Edit: They probably call it sloppy because you shouldn't be breaking out of a for loop. If you arn't sure you'll go until the end, you are supposed to use a while or something like that. Is that specific case it doesn't matter that much but other times it shows poor planning. duz fucked around with this message at 03:38 on May 9, 2008 |
# ¿ May 9, 2008 03:34 |