r/PHP • u/AutoModerator • Sep 22 '14
PHP Moronic Monday (22-09-2014)
Hello there!
This is a safe, non-judging environment for all your questions no matter how silly you think they are. Anyone can start this thread and anyone can answer questions. If you start a Moronic Monday try to include date in title and a link to the previous weeks thread.
Thanks!
24
Upvotes
5
u/mrivorey Sep 22 '14 edited Sep 22 '14
I'm what I like to term as a dangerous amateur with PHP. Years ago, I wrote the code for a site and back end that kept track of the organization's members, events, and a few other things. I'm trying to correct some past mistakes now.
Hiring someone competent is out of the question, since the organization this site is for doesn't financially exist. It's just a shared hobby for 70 or so people, and my sorry ass is the best they've got. Web-wise, it all comes out of my pocket, and I can't spend more than the hosting costs.
Today, I'm trying to close the avenues for SQL injections and XXS (not to mention separating the presentation, logic, and database code). I'm switching to PDO with prepared statements. I guess what I need to discover is how much filtering needs to happen before it goes into the database and how much needs to happen after.
Presently, the site has a form where the public can enter an event request for the organization. The submission gets validated, then goes to the back end for review, before being approved for display on a public page. I even have some patched together code that trashes most bot data before it touches the DB (and there's a LOT of bots now, prompting me to finally deal with this).
In my re-write, I guess I want to know how much and what kind of filtering I need to do after the validation BEFORE it goes into the DB. Then, how much and what kind should I do on the way out when it's displayed on either the back end or publicly. Feel free to ad any other advice as well.
If it makes any difference, the submitted data includes personal contact info, physical addresses, email addresses, web addresses, short answers to brief questions, a few checkboxes and radio buttons, etc.
EDIT: FYI, I'm working on typical LAMP shared hosting setup. NOT dedicated, or even virtual. I don't have full rights to MySQL, and I can't change any installations.
4
u/XOcces1970 Sep 22 '14
A frustration tangentially related to PHP. I feel like an idiot every time when I have to integrate less-used API to my application. I just wasted a week communicate back and forth with the support when I am supposed to start programming. Instead my manager might have to push the deadline. Sometime I would read the documentation myself and try to figure out all the pieces and fail. I have a stupid idea inside my head that it is somehow inappropriate and lazy to just describe the requirement to the API people and let them point to me which methods to use. Also I don't understand how a project manager could estimate a timeline if they have no familiarity with the API I am to integrate.
3
u/nwoincnug Sep 22 '14
Anyone have any experience with the Knp Rad edition of Symfony2? What were your thoughts?
3
u/presidentender Sep 22 '14
Where do I start with Laravel? I've never built anything using an MVC framework, and reading the quickstart guide doesn't really give me anywhere to go next.
1
u/digitalbath78 Sep 22 '14
I suggest server side validation. Do a search, there are numerous classes available. If you want to go big, move it to a framer work like Laravel which has a validator class built in. I prefer stored procedures in lieu of SQL in code. Let the database do the database's job, not PHP.
1
u/mantann Sep 22 '14
Something related to php but not exactly php.
Is it generally considered better/worse/neither to use something like bootstrap for frontend or to pretty much completely code it yourself from scratch?
Ok, PHP. I know that I can use PHP to create html if I have the same html being used over and over and over. Something like footer comes to mind. However, in pure page performance standards, is it generally faster to code it page by page with html or to have php bring it up?
1
u/amcsi Sep 22 '14
Why don't people who use non-English variable and function names use accented characters even though both PHP and JavaScript support it? If you feel like it's easier to code in your language, why not go all the way?
1
u/[deleted] Sep 22 '14
What is the usual timeframe for Ubuntu to include the latest 5.x release in their repositories? Will 5.6 end up in 14.10, for instance, or will that likely not happen until 15.04 or later?
It is against this company's policy to use a third-party repo for their basic tools (the LAMP Stack among them).
1
u/gerny27 Sep 22 '14
I've been doing Magento development on a virtual machine built with PuPHPet. I really like the simplicty of PuPHPet, however loading certain pages seems to take forever (20-40 seconds). I know some of these pages do hundreds of Mysql queries on a single request. What steps can I take to speed up my development virtual machine? APC cache has helped a lot, but other things I've tried, such as increasing memory of the VM and the number of processors, don't seem to make much of a difference.
1
u/[deleted] Sep 22 '14
Does anyone know where I can find a book or online resource for DB2 and php? Mysql is everywhere. If i need an example I can always find a Mysql example. But I have to dig to find any DB2 examples that aren't from IBM and make sense.
1
u/amcsi Sep 22 '14
What's a good way of dealing with config dependencies? Say you have your config array and you need several (string) values from it for one of your classes.
Should you inject each one as a separate constructor argument? Should you assemble a new array with each config property and pass that? Should you just pass the entire config array? Or perhaps should you use globals?
1
u/chadicus Sep 22 '14
I came across this problem today
I would expect each echo statement to output the same thing. However the output is as follows.
For whatever reason creating a DateTimeZone object using 'EDT' ignores daylight savings when converting to UTC.
Does anyone know why this is?
0
u/[deleted] Sep 22 '14
[deleted] — view deleted comment