|
Tiny Bug Child posted:Are you looking for something like var_export()? Is there any functional difference between var_export and serialize()? Just asking out of curiousity, since the latter is what I typically go to for stuff like this.
|
# ? Nov 23, 2011 20:19 |
|
|
# ? May 16, 2024 18:17 |
|
OriginalPseudonym posted:Is there any functional difference between var_export and serialize()? Just asking out of curiousity, since the latter is what I typically go to for stuff like this. serialize() returns a string that can be unserialize()'d later to get the same value. var_export() doesn't need an unserializing function because it returns actual PHP code, and you use it when you want to do something like have a PHP script that generates another PHP script. Using either function can be a sign that you're about to do something gross, especially if you're sticking a serialized object into a database or using var_export() in tandem with eval().
|
# ? Nov 23, 2011 21:11 |
|
Anyone use the simple html dom library?code:
|
# ? Nov 26, 2011 22:05 |
|
This seems like it would work:code:
|
# ? Nov 28, 2011 05:46 |
|
Whats the best framework to use nowadays? a lot of people seem to be against cake for various reasons, I've been mainly looking at symfony.
|
# ? Nov 29, 2011 15:35 |
|
the_cow_fan posted:Whats the best framework to use nowadays? a lot of people seem to be against cake for various reasons, I've been mainly looking at symfony. I'm still a student, but a lot of job postings I see are all Wordpress, Joomla, or Drupal it seems.
|
# ? Nov 29, 2011 16:06 |
|
the_cow_fan posted:Whats the best framework to use nowadays? a lot of people seem to be against cake for various reasons, I've been mainly looking at symfony. Symfony2 rocks. Hit me up on github if you have any questions. https://github.com/dustin10 or come chat on IRC; #symfony on freenode.
|
# ? Nov 29, 2011 16:40 |
|
the_cow_fan posted:Whats the best framework to use nowadays? a lot of people seem to be against cake for various reasons, I've been mainly looking at symfony. Yii is getting popular, I highly recommend checking it out (http://www.yiiframework.com/). I just made a point-of-sale system for a ski resort with it, and it went together smoothly and relatively quickly.
|
# ? Nov 29, 2011 18:09 |
|
There was just a bunch of PHP framework talk in the general web design thread
|
# ? Nov 29, 2011 18:20 |
|
Thanks for the awesome suggestions, I'm currently messing around with Symonfy, I'll checkout Yii and have a read of the design thread.
|
# ? Nov 29, 2011 18:31 |
|
the_cow_fan posted:Whats the best framework to use nowadays? a lot of people seem to be against cake for various reasons, I've been mainly looking at symfony. It's hard to say what the "best framework" is. Asking people that question is probably going to get similar results as asking "What framework are you most familiar with?" Give some thought to whether you really need a framework. PHP is actually pretty good on its own, and its frameworks tend to be big, lumbering, heavyweight things that force you into using their style. Rasmus Lerdorf (the dude who created PHP) is often critical of the larger frameworks, and wrote this article on a "no-framework MVC framework" to illustrate how you can write clean, well-organized code without using an external framework. Personally, when I do need to use a framework, I like the Zend Framework. It's pretty good about letting you use only the parts you need. e: apparently that link is down, here's google's cache in the meantime
|
# ? Nov 29, 2011 20:11 |
|
Tiny Bug Child posted:Rasmus Lerdorf (the dude who created PHP) is often critical of the larger frameworks, and wrote this article on a "no-framework MVC framework" to illustrate how you can write clean, well-organized code without using an external framework. This is a really bad idea. You have to write everything from scratch, opening up the potential of security holes and exploits. Frameworks have teams of people testing these things all the time, something Uncle Joe's PHP Framework will lack. Also, you are going to have to think of every possible way you might want to expand this thing, as you can accidentally put your entire site in handcuffs with a bad design decision early on. I did this "roll your own" thing on 3 websites, and I regretted it after spending the time to learn Yii. With a framework you get to spend more time worrying about how your website will look and behave instead of the architecture. The best frameworks give you the necessary tools to do that, and it's up to you to chose something like a heavyweight (PHPCake), or something very hands off (in my case, Yii). edit: Also, didn't Rasmus argue against Object Oriented code at one point, and instead wrote a whole blog post about the benefits of procedural instead? He really isn't a good source of information.
|
# ? Nov 29, 2011 21:10 |
|
VerySolidSnake posted:edit: Also, didn't Rasmus argue against Object Oriented code at one point, and instead wrote a whole blog post about the benefits of procedural instead? He really isn't a good source of information. I'm not saying Rasmus Lerdorf is a Good Programmer, but what's wrong with doing that? There's nothing wrong with procedural code.
|
# ? Nov 29, 2011 21:22 |
|
Sure, if you're new to PHP and/or you're doing something that's already been done to death and/or performance isn't a concern, there's nothing wrong with using a framework. I'm just saying that a lot of developers consider copying over their MVC framework of choice to be the immutable step 0 of every project, but using a framework and using an MVC architecture are not only not prerequisites to writing good code but sometimes actively get in the way of getting things done.VerySolidSnake posted:edit: Also, didn't Rasmus argue against Object Oriented code at one point, and instead wrote a whole blog post about the benefits of procedural instead? He really isn't a good source of information. I don't ever remember reading this, but I'm curious as to why you think it would discredit him. OOP isn't the one true way of doing things, it's just a paradigm with its own set of issues.
|
# ? Nov 29, 2011 21:33 |
|
Tiny Bug Child posted:OOP isn't the one true way of doing things YES IT IS BLARRGGHGHG
|
# ? Nov 29, 2011 21:35 |
|
Tiny Bug Child posted:I don't ever remember reading this, but I'm curious as to why you think it would discredit him. OOP isn't the one true way of doing things, it's just a paradigm with its own set of issues. I can't find the article, but I know it was one of the PHP "lead" guys. The article didn't just write about the benefits of procedural, but went on and on about why you shouldn't use object oriented. Everyone went up in arms about this. I'll try to find it and post it. But even in his example "Write your own MVC" he is using .inc files. He doesn't even mention the fact once that these files do not parse PHP code, and if someone guesses the URL to that .inc they will see all of your config values. You could probably do some server configuration to prevent direct access to the files, but why would he even suggest a naming convention like that? I used to only write procedural code for websites and every time I have to go back and make changes I want to slam my nuts in the door. When you are making larger websites OOP is the only way to do things.
|
# ? Nov 29, 2011 22:19 |
|
I'm doing a REALLY simple PayPal function for a small organization. There's a redirect URL that updates the DB to note their payment, etc. Everything seems to work in theory. Testing is a bit weird, though. I tried setting up a sandbox account to run null transactions (like you can with some other payment gateways) and it doesn't seem like it will work with the simplistic workflow we're using here. Is there a way to use a sandbox account to test payments on the site (rather than just log into the sandbox account page) or to simply cancel payment on the merchant side so it isn't credited?
|
# ? Dec 2, 2011 14:22 |
|
klem_johansen posted:I'm doing a REALLY simple PayPal function for a small organization. There's a redirect URL that updates the DB to note their payment, etc. Everything seems to work in theory. Testing is a bit weird, though. You need two sandbox accounts, a buyer account and a seller account. Somewhere buried in the settings for the sandbox account you will be able to add a credit card. It will then generate a fake credit card number and add it to the account. Since eBay started their whole x.commerce thing though, it seems all of their sandbox stuff has gotten even more buggy than usual. Yesterday I continually got redirected from the sandbox to pages on their taiwanese site. I think they are having some serious code management issues. I had problems doing this before, and I got it working as best as I could, then finally I just ran a real credit card for a low purchase price and then cancelled it. Probably a good idea anyways for complete end to end testing.
|
# ? Dec 2, 2011 18:09 |
|
Begby posted:I had problems doing this before, and I got it working as best as I could, then finally I just ran a real credit card for a low purchase price and then cancelled it. Probably a good idea anyways for complete end to end testing. This is essential, actually; PayPal's sandbox has never been an accurate duplication of their live system - for instance there are character encoding issues (causeing IPN to reject valid transactions, that if duplicated in the sandbox work fine) that exist ONLY in the live system; they are fun to deal with.
|
# ? Dec 3, 2011 12:58 |
|
Ok, so this is probably pretty simple but I've been stumbling. I'm just trying to call a mySQL database with some information in it, put them in variables, and display them on a website. I've figured out how to access the database, but it's the SQL queries that are killing me. I'm using wordpress, and I want to pull my records based on the title of the blog post, which is usually returned with code:
code:
code:
code:
code:
|
# ? Dec 5, 2011 02:34 |
|
biochemist posted:Ok, so this is probably pretty simple but I've been stumbling. The first thing you need to do is to learn about a type of website security vulnerability called SQL injection. (Here is the Wikipedia page. This is fun additional reading.) What happens if your article title is "Two meals for the price of one at O'Flanagan's Irish Pub"? Having said that, if we completely ignore the issues posed by SQL injection (do not do this) the strings you are trying to form are not difficult to obtain. You would have two options: to create a new variable ($temp_variable) say, assigned the value returned by the_title(), and use variable interpolation as you had been doing: code:
code:
|
# ? Dec 5, 2011 04:12 |
|
Use PDO. Once you've set up your connection (we'll call it $mysql), you can do this:code:
|
# ? Dec 5, 2011 04:17 |
|
biochemist posted:Ok, so this is probably pretty simple but I've been stumbling. It has been said by the two guys ahead of me, but I'm saying it a third time: Don't write your own SQL in PHP. It's like leaving your front and back door wide open before you go on vacation.
|
# ? Dec 5, 2011 04:28 |
|
Given that you're using Wordpress, you might also want to look at the Wordpress database object and how it emulates safe parameter binding. I wouldn't want to mix PDO and the Wordpress code at the same time.
|
# ? Dec 5, 2011 04:51 |
|
Lumpy posted:It has been said by the two guys ahead of me, but I'm saying it a third time: Don't write your own SQL in PHP. It's like leaving your front and back door wide open before you go on vacation.
|
# ? Dec 5, 2011 06:57 |
|
Lumpy posted:It has been said by the two guys ahead of me, but I'm saying it a third time: Don't write your own SQL in PHP. It's like leaving your front and back door wide open before you go on vacation. Haha thanks everyone, I've heard of SQL attacks (hard not to with all of the press they got with lulzsec or whatever). I guess I was just rushing things to try to get some functionality up, but it makes much more sense to build that all in as you go than try to come back and patch things up. I'll take a look at all of your suggestions, and I'm sure I'll be back with some other inane questions. Thanks again! Oh, a little edit: I could skip the SQL database entirely and it might even work better if I could have my page template contain all of the formatting and variable calls, but assign them in the actual post. The post content is called with code:
biochemist fucked around with this message at 07:38 on Dec 5, 2011 |
# ? Dec 5, 2011 07:09 |
|
Anyone have any idea why, when I do file_get_contents on this image (hopefully you can see it without an active session): http://media.allinteractive.com.au/content/55c363911af776eb2f93ae665935fd6c/4edc7691/image/4/b18ec27a-a614-11df-af95-001a6465ada8.jpg And copy it into a MySQL blob, and then I echo it back to the browser out of the database, I get this? I assume there's some character in the JPEG raw that is breaking the MySQL insertion and inserting only half of it, but if I encapsulate the query in mysql_real_escape_string or addslashes it makes no difference. Anyone able to help? edit: also, if I encapsulate it with addslashes, then output it with stripslashes, it goes spastic and it's just a mess. What the hell? edit 2: Fixed it, didn't realize BLOB had a 65535byte limit. Thanks goons! Mug fucked around with this message at 08:53 on Dec 5, 2011 |
# ? Dec 5, 2011 08:48 |
|
biochemist posted:
There is an excellent WordPress thread and I'm sure they will be able to help you do exactly what you want in WP-eqsue fashion using it's internal way of getting things.
|
# ? Dec 5, 2011 13:06 |
|
the_cow_fan posted:Whats the best framework to use nowadays? a lot of people seem to be against cake for various reasons, I've been mainly looking at symfony. I have made quite a few projects using CodeIgniter, and I really enjoy it. It's very simple to learn.
|
# ? Dec 6, 2011 08:15 |
|
Am I doing this wrong? It's getting to be loving retarded to do a simple task. php:<? // load string into a DOM object as HTML $dom = new DOMDocument(); @$dom->loadHTML($result); // create title tag $title = $dom->createElement('title', '[redacted]'); // create viewport meta tag $metaViewport = $dom->createElement('meta'); $metaViewportName = $dom->createAttribute('name'); $metaViewportContent = $dom->createAttribute('content'); $metaViewportName->value = 'viewport'; $metaViewportContent->value = 'width=device-width'; $metaViewport->appendChild($metaViewportName); $metaViewport->appendChild($metaViewportContent); // create reset styles css link $resetCSSlink = $dom->createElement('link'); $resetCSSHREF = $dom->createAttribute('href'); $resetCSSREL = $dom->createAttribute('rel'); $resetCSSTYPE = $dom->createAttribute('type'); $resetCSSHREF->value = '/css/reset.css'; $resetCSSREL->value = 'stylesheet'; $resetCSSTYPE->value = 'text/css'; $resetCSSlink->appendChild($resetCSSHREF); $resetCSSlink->appendChild($resetCSSREL); $resetCSSlink->appendChild($resetCSSTYPE); // create custom styles css link $customCSSlink = $dom->createElement('link'); $customCSSHREF = $dom->createAttribute('href'); $customCSSREL = $dom->createAttribute('rel'); $customCSSTYPE = $dom->createAttribute('type'); $customCSSHREF->value = '/css/styles.css'; $customCSSREL->value = 'stylesheet'; $customCSSTYPE->value = 'text/css'; $customCSSlink->appendChild($customCSSHREF); $customCSSlink->appendChild($customCSSREL); $customCSSlink->appendChild($customCSSTYPE); // insert elements into head $head = $dom->getElementsByTagName('head')->item(0); $head->insertBefore($customCSSlink, $head->firstChild); $head->insertBefore($resetCSSlink, $head->firstChild); $head->insertBefore($metaViewport, $head->firstChild); $head->insertBefore($title, $head->firstChild); // output DOM object as HTML echo $dom->saveHTML(); ?>
|
# ? Dec 21, 2011 23:17 |
|
I see PHP Simple HTML DOM recommended quite a bit for such things.
|
# ? Dec 22, 2011 00:27 |
|
IT Guy posted:Am I doing this wrong? If you're okay with XHTML instead of HTML, use XMLWriter instead. It's stream-based, so your code ends up looking a lot nicer: php:<? $w=new XMLWriter(); $w->openMemory(); $w->startDocument('1.0','UTF-8'); $w->startElement("root"); $w->writeAttribute("ah", "OK"); $w->text('Wow, it works!'); $w->endElement(); echo $w->outputMemory(true); ?>
|
# ? Dec 22, 2011 13:06 |
|
Scaevolus posted:Manipulating the DOM directly sucks a lot. I was unaware of XMLwriter, but it looks like it might work out better for me, thank you.
|
# ? Dec 23, 2011 14:30 |
|
I have a question regarding sanitizing data. When doing something like this: code:
|
# ? Dec 23, 2011 17:29 |
|
IT Guy posted:I have a question regarding sanitizing data. It is the contents of $array[$key] that you are outputting to the browser. The browser does not see the value of $key. So no. To give an example: code:
code:
|
# ? Dec 23, 2011 17:35 |
|
Hammerite posted:It is the contents of $array[$key] that you are outputting to the browser. The browser does not see the value of $key. So no. Makes sense, thank you.
|
# ? Dec 23, 2011 19:56 |
|
Let's say I have more than 2 arrays of supposedly unique values. How would I go about finding out if any one value in an array exists in the rest of the arrays? I am looking for a fairly fast way to do this without having to loop through each array manually and see if the value exists in any of the other arrays. To clarify, I'm hoping to avoid using in_array(), I'm also only interested in the whether "user" is duplicated. rough example: php:<? array ( 0 => array ('user' => 'jdoe','email' => NULL,), 1 => array ('user' => 'tsmith','email' => 'tomsmith@gmail.com') ) array ( 0 => array ('user' => 'pmcallister','email' => 'pmc@test.com'), 1 => array ('user' => 'nnancy','email' => 'nnancy@gmail.com') ) array ( 0 => array ('user' => 'jdoe','email' => 'jdoe@pmail.com'), 1 => array ('user' => 'griviera','email' => 'george@poop.com') ) array ( 0 => array ('user' => 'rmurphy','email' => 'rachel@murphygroup.com'), 1 => array ('user' => 'nnancy','email' => 'nnancy@gmail.com') ) ?> DarkLotus fucked around with this message at 02:37 on Dec 24, 2011 |
# ? Dec 24, 2011 02:30 |
|
Is there better documentation of mcrypt internals than can be found on php.net? I'm trying to write some C code using OpenSSL to decrypt some strings that have been encrypted using something like: php:<? $plaintext = '12345'; $key = 'secret'; $enc = base64_encode(mcrypt_encrypt(MCRYPT_BLOWFISH, $key, $plaintext, MCRYPT_MODE_ECB)); printf("<P>encrypted string is \"%s\"</P>", $enc); ?> code:
code:
|
# ? Dec 24, 2011 06:26 |
|
echo in the shell always appends a newline, which can easily throw things off. Try echo -n instead?code:
|
# ? Dec 24, 2011 07:15 |
|
|
# ? May 16, 2024 18:17 |
|
McGlockenshire posted:echo in the shell always appends a newline, which can easily throw things off. Try echo -n instead? This could explain why the two ciphertexts don't match---assuming everything else was equal---but it doesn't explain why a ciphertext produced by mcrypt can't be decrypted by OpenSSL at all (as opposed to just decrypting plus or minus an extraneous newline). Which is my real problem.
|
# ? Dec 24, 2011 08:40 |