Questions tagged [php]

PHP is a widely-used, general-purpose scripting language that is especially suited for web development.

Filter by
Sorted by
Tagged with
2
votes
1answer
89 views

Single function to read one, read all, or set

I have the below function, it is designed so I can call: ...
3
votes
1answer
7k views

Capturing optional regex segment with PHP

I need to check the end of a URL for the possible existence of /news_archive or /news_archive/5 in PHP. The below snippet does exactly what I want, but I know that I could achieve this with one ...
5
votes
1answer
2k views

Is there any problem in checking PHP PDO connection this manner?

Is there any problem in checking PHP PDO connection this manner? Is this way reliable? ...
0
votes
3answers
50 views

Building array keys using a span of numbers for like values

I am calculating discounts based on a quantity after 6. Is there a cleaner way to do this: ...
1
vote
2answers
124 views

How can I ascertain and test SQL injection vunerabilities on this login code?

I know about the "little bobby tables" scenario and was just wondering if this code is vulnerable to such SQL injections. I am fairly new to PHP and am curious about this. My code for a login script:...
3
votes
2answers
233 views

Would be possible to refactor this PHP code more?

I really don't like the so many return statements. Anyone think that this could be refactored more? ...
2
votes
1answer
535 views

Help improve my first PHP class

I recently started to learn more about OOP in PHP and I created a website for testing. I have 4 classes: database, user, ...
5
votes
2answers
545 views

moving from->to: mysql->pdo, md5->pbkdf2, procedural->oop

I'm upgrading/rewriting our online client portal and wondering if my log in page code looks okay so far. during this rewriting/learning process I am upgrading a number of things: PHP 5.2 to 5.3.5, ...
2
votes
6answers
186 views

Is there simplier than this one in PHP?

I want to refactor my code but I can't find and much simplier one. Can you please suggest on how to refactor the code below without using a loop? maybe using only array functions? TIA ...
4
votes
2answers
426 views

PHP MVC controller code needs diet?

This is the dashboard controller code in PHP Symfony 2. It collects some aggregate data and points for charts, but i don't like it very much. Do you think that this code belongs to what a controller ...
2
votes
1answer
809 views

Better Database Connection Function

I'm about a week into learning pdo. I've created, with help from an example online, a database connection function. I have a config file with all my info (username, pass, database, host) and a ...
3
votes
2answers
409 views

PHP simple engine

i have created simple php engine, i want that this engine used html/php codes from mysql. Here is this php code and please if you find out some mistakes or bugs, please post here. I realy want to use ...
4
votes
1answer
3k views

PHP code to scale images and generate thumbnails

I have written a piece of code by taking help from this link. For generating thumbnail, I create a temporary scaled image and then copy from that image. I am assuming that it is resource intensive. ...
2
votes
1answer
148 views

Functional testing issue - Feels like one long test

I'm using Selenium to test a PHP site that goes through the following process: Register user Log in Fill out Form 1 and submit Fill out Form 2 and submit Fill out Form 3 and submit (tear down) Delete ...
2
votes
1answer
157 views

Is this simple add/mod/del/jquery code secure enough?

I have written some code to simple add/mod/del to a table called person. I would like comments on where this code could be comprising on security. I have used the PDO library in php. GetPerson.php ( ...
4
votes
1answer
164 views

Is my PHP script/embed remover robust?

The goal of this question: Your goal here is to find a security hole in my code which allows a user to create input that contains a script doing anything they want, without that script being stopped ...
2
votes
1answer
177 views

Procedural PHP code for showing videos on the page, sorting them in different ways. Is this good? Should it be switched to OOP?

I have just finished another page of my project and everything is working just great with the following code example. My first concern is whether you could recommend something to make my code look ...
1
vote
1answer
382 views

PHP class and interface interrogation using reflection

I have been working on a class to use Reflection to interrogate other PHP classes and interfaces, what I want to know from anyone with more experience of this is, is there anything else I can add, or ...
2
votes
2answers
2k views

Correct GenericDAO implementation?

I implemented a MVC Framework with Generic DAO and I would like know if is correct. I did not have developed yet the MySQLDAO. My controller class ...
1
vote
1answer
136 views

Error handling data from XML document [closed]

I am getting information from an XML document and for the most part everything runs as it should. Occasionally, I get a php fatal error Call to a member function children() on a non-object. I have ...
4
votes
1answer
6k views

What is the correct way to set up my classes in OOP programming in PHP?

Let me start with a little introduction. I am in the process of learning OOP in PHP. I have also researched Design Patterns but have not yet fully grasped the different types of concepts. I am at the ...
3
votes
1answer
706 views

Lots of RegEx match against huge number range (PHP)

I have to check a given amount of regular expressions, which are defining number ranges for dial plans, against an input number range. The target is to check and see, if any of the numbers in the ...
4
votes
1answer
664 views

Processing a form with PHP

I've seen few ways of processing forms with PHP. Whenever I am working with a form, I typically have two files: one for displaying the information (e.g. form.php) and the other for processing ...
2
votes
2answers
535 views

OOP PHP with language detection

I cannot quite see all the advantages of OOP PHP. I have already started translating some procedural functions into object oriented. How is the second code better than the first one? Is there anything ...
0
votes
1answer
368 views

Optimizing blocks-maze generation script php [closed]

I created script that generates maze or some kind of dungeons that looks like this: http://s13.postimage.org/4uify3jxj/blocks.jpg I have problem with optimize, because when I've tried to add blockade ...
2
votes
1answer
338 views

Luhn - bPAY mod10v5 [closed]

So I am using the following ...
1
vote
1answer
4k views

PHP PDO wrapper class

I'm one of those coder/designers that has been at it since day one, but is still getting the hang of several important coding nuances (e.g. OOP for PHP, and concepts such as this). In this case, I'm ...
1
vote
1answer
120 views

Are these MySQL Abstraction Classes safe from SQL Injection? Can they be made safe?

I was looking at this website: http://www.devshed.com/c/a/MySQL/Creating-User-Models-in-PHP-and-MySQL/1/ and http://www.devshed.com/c/a/MySQL/Creating-User-Models-in-PHP-and-MySQL/2/ In the first ...
5
votes
2answers
26k views

!empty() check before a foreach statement

Is this the best way to prevent that foreach loop from happening if $terms doesn't exist? ...
1
vote
1answer
2k views

MVC Structured CMS

I'm creating a MVC structured content management system as both a means to learn better OOP and redesign my tacky website to me more modular and simplistic. My aim is to approach everything with ...
2
votes
1answer
73 views

Code behaviour: Working object orientated with a database

I'm working on my own PHP framework for a long while now. Right now I'm in a refactoring process. I'm came up with the question what a programmer would excpect what happens when he see following code:...
3
votes
3answers
306 views

Pinging the user requested host - is this code insecure?

...
2
votes
2answers
1k views

Updating a chart from Yahoo Finance CSV files

I want to load some CSV columns or contents in my Ajax code. Please help me or improve my code. This will be live API code for me. Data will be downloaded from Yahoo Finance in CSV format on an ...
2
votes
1answer
191 views

Will this code make some attacks (XSS, CSRF…) harder to do?

I have following code on my login page (now i use it for preventing POST variable resubmit on page refresh): ...
2
votes
2answers
836 views

Speed up highscore rank calculation

I calculate a highscore and find the users current rank like shown here. This is the query: ...
5
votes
3answers
297 views

PHP backup log table from MySQL

I have been working on a little project to tidy up my log table which has exceeded the shared host provider limits:) So I have done some script that is working except one thing at the end: optimise DB....
2
votes
1answer
163 views

Controller method optimization

I have the following function for validating users facebook information against the rules setup in the database for users. Its working fine but i need to know if it can be more optimized. Few things ...
0
votes
2answers
55 views

Is there more efficient way of processing my XML file in PHP?

The page is assigning $gid to the url paramater gid. It then reads an XML file that looks like this: ...
2
votes
1answer
68 views

Is having preset queries prone for disaster?

Edit Just did some further reading around the website and have come to the conclusion that this method leads to Leaky Abstraction, sorry for wasting peoples time. Time to head back to the drawing ...
3
votes
2answers
194 views

Closures power and concise style vs readability and maintainability?

Is large use of closures actually a bad thing for readability and maintainability of the code? For example, consider the following code with (comments removed on purpose): ...
0
votes
1answer
155 views

php function for gathering includes…is there a better way than this?

I am building a dynamic site. All data will be served through an index.php in my webroot, using jquery to update the content. In webroot, I have a folder 'i/' which contains the files I want to ...
2
votes
1answer
373 views

Process list of e-mail addresses in PHP 5.3

Part of an application that I am building in CakePHP 2.1 needs to send out an e-mail based on a template from a database. The end user is able to set the from, reply to, to, cc, and bcc addresses. ...
0
votes
2answers
98 views

advice on polymorphism

Im trying to teach myself enough to start using more OOP in php. This is what Ive come up with. Is there any reason why any of this is done wrong, or should be done another way? ...
1
vote
1answer
968 views

PHP 5.4 Event System, just looking for general feedback

So I decided to create a trait that I could add to my classes that would add a simple way of binding functions to an event, and to fire those events. It ended up going a little further than I expected ...
3
votes
1answer
196 views

Small class to manage config data

I made this small class the allows me to navigate large arrays using something like: key1/key2/key3 I made this because I was creating large arrays to hold my classes configs and needed a simpler way ...
1
vote
1answer
961 views

Dynamically instantiating classes

I have the following class: ...
1
vote
1answer
548 views

PHP - Is this proper use of exceptions for error handling within classes?

I've searched plenty on this topic and have gotten a lot of good (but different) results. Some of the results weren't quite related and it does seem to be a matter of preference in the end, but I'm ...
2
votes
2answers
480 views

Use filter_var_array on whole array, or inside iteration

I have a MySQL result set in a PHP multidimensional array. I want to iterate through it and output it sanitized. Considering the two alternatives below, are there any performance differences? ...
2
votes
2answers
954 views

Dynamic two-column list, “Vertical Wrap”

I have created a very simple script that will create two columns which are populated by an array. It works, but I am certain that the way that I have gone about it is not the best way. I have been ...
0
votes
1answer
93 views

How to store option key names

I have to store some properties in a database properties table which looks like this: ...

1
78 79
80
81 82
84