Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [php]

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

4
votes
3answers
1k views

73 Lines of Mayhem - Parse, Sort and Save to CSV in PHP CLI

Inside of a folder named txt I have 138 text files (totaling 349MB) full of email addresses. I have no idea (yet) how many addresses there are. They are separated ...
5
votes
2answers
669 views

Uploading a file to the server

I wrote a simple PHP script which allows the user to upload a file to the server. It works, but I'm not very sure about security. Could you give me some hints about security mistakes? In a nutshell: ...
7
votes
2answers
589 views

Generating code with XML

I'm working on my graduate project and I had stumbled upon a somewhat dilemma, I've managed to solve it with some workarounds but I have my doubts that this is the most efficient way to deal with this ...
5
votes
2answers
521 views

Splitting code, am I doing it right?

I would like to have my code reviewed, I'm trying to get a general model I'm using for my stuff going and I don't want to keep using wrong or inefficient code if I can. My file structure is like this:...
5
votes
2answers
771 views

Switch statement in PHP - cleaner way to determine priority?

I have a function that takes in a controller instance, a method, and parameters (this is for a little MVC experiment I'm working on). The purpose of the function is to execute the controller method ...
3
votes
1answer
452 views

Decoding name/value pairs

I have this code in a class sharing a private static array of data. Internally it's encoded, but I need the iterator for a foreach loop to show the decoded values. ...
7
votes
1answer
239 views

Do nothing lamda…

$privilegeStrings = array_filter($privileges, function ($s) { return is_string($s); } ); Is there a better way to specify that I want just the string values in ...
1
vote
2answers
143 views

Best way to use an array that is returned from a function immediately in PHP

I have a function that returns an array and I want to check that a certain value is not set in the array. ...
5
votes
3answers
331 views

Expanding sizes between given values

This a very simple function to expand the sizes between the given values. For instance, if the input variable is "S-XL" then the function returns "S, M, L, XL". Basically I'm not happy with this ...
4
votes
2answers
3k views

Handling HTTP requests

This class handles HTTP requests. It's a singleton class that parses URI to get the controller, method and parameters and then executes the controller's method. Maybe ...
3
votes
2answers
483 views

Submitting client reviews

I generally encounter a lot of if/else. I would like to get some suggestions on my code: ...
4
votes
2answers
261 views

Displaying all single posts

I think there are some confusing and weird indentation problems in this WordPress file (single.php). Any suggestions on improving indentation and readability? ...
7
votes
5answers
722 views

Securely handling a password protected application

I have some small applications that I want to secure. I've been using the following setup that I think is fairly safe, but I've never been able to set my mind at ease that it really is. Could you ...
8
votes
2answers
675 views

Object Paradigm for PHP, Practice in Design

I've created and I manage a point of sale web application built in PHP which has thus far followed no clear guidelines or methodology for development; it's operation is completely procedural. In turn, ...
5
votes
1answer
584 views

Generalized PHP function for editing data in a table

I've got some legacy code which I need to maintain and its got this function which works perfectly fine, but I'm trying to understand if it is working using acceptable coding practices or not... I am ...
5
votes
2answers
253 views

Extract a joined result set into a parent-child hierarchy

I'm writing a quiz application in PHP and am querying the DB for questions and their associated answers. I then wrangle the result set into a usable array for my front end. However, it always seems ...
3
votes
2answers
204 views

Zend_Application bootstrapper

This seems a bit wrong because there's a lot of business logic going on inside the bootstrapper. Is there a better way to accomplish what's going on here? ...
8
votes
1answer
431 views

Large Zend_Db query

Is there a better way to accomplish the following? ...
6
votes
2answers
557 views

modify custom loops to improve readability and efficiency for Wordpress?

The following code retrieve custom post types with their custom taxonomy. I'm just a beginner in PHP and I would like to know tips in order to improve readability and perhaps efficiency. home.php: <...
5
votes
1answer
474 views

Adding flair to PHP page with Sassy (SCSS)

This is what I've done so far: ...
8
votes
5answers
12k views

Database class using PDO

The point of this question I'm actually using it while developing a simple application and it seems to cover all my needs. Also it uses PDO so that we don't really have to worry about SQL Injection. ...
8
votes
2answers
5k views

Connecting to a database

I'm working on a web application that I inherited from a colleague long gone. To connect to the MySQL database I use the following classes: statement.php ...
7
votes
1answer
4k views

Workaround for overloaded constructor in PHP

I have a class whose purpose is to display a comment. I'd like to be able to instantiate it by passing a Comment object if I happen to have it available, or just ...
22
votes
1answer
1k views

Dynamically generating a list of events

This is a simple list of items in a list, which allows the user to dynamically generate that list of events. Then a controller action does the work of serializing that into the database. The issue is ...
4
votes
1answer
1k views

Simple MVC in PHP

I have a very simple PHP MVC library for my auto-didactic pedagogical purposes. I'm having a little trouble figuring out how to add in the observer patterns as show in this UML diagram from Wikipedia. ...
6
votes
2answers
542 views

JSON API for some bank account

I have been developing this class, and was wondering if anyone had any thoughts on how I can improve the performance of it. ...
7
votes
1answer
532 views

MySQLi_Recordset: blending SPL and Statement/Query results

I've made a SPL-based class named "Recordset" that wraps both MySQLi_STMT and MySQLi_Result objects and allows treating either as a 3-dimensional array. It requires PHP5.3+. I'm pretty bummed about ...
10
votes
4answers
5k views

Checking date & time in PHP

Goal: To create a countdown to our next available live stream. Details: We live stream six times a week all (PST). 1. Sunday at 8:00 a.m. 2. Sunday at 10:00 a.m. 3. Sunday at 12:00 p.m. 4. Sunday at ...
12
votes
1answer
12k views

Simple Tic-Tac-Toe PHP/Pure HTML

I've been doing a simple Tic-Tac-Toe with PHP, generating only HTML code. A few notes: I didn't bother yet to give an AI to the opponents (the Os), and it is intentional. There is no CSS style to ...
5
votes
2answers
420 views

User error logging

I have created this code for user error logging, and I am wondering if there is anything that can be improved. The point is that this error handler would ONLY catch user errors created in-code by ...
10
votes
1answer
2k views

Php/Doctrine array hydration

According to the Doctrine docs, you should use Array hydration rather than record hydration when retrieving data for read-only purposes. Unfortunately, this means I have to use array syntax (as ...
25
votes
3answers
18k views

Calculate a median

I got this as an implementation of "get me the median of those values". But it sort of doesn't feel right (too long, too many branch points) so I thought I'll post it here to see what you think. <...
32
votes
8answers
16k views

is_numeric_array() is missing

I found that in PHP (or I probably can't find it) a proper is_numeric_array($array) function is missing. So I created one. The problem is that I don't think it's ...
7
votes
1answer
425 views

Database method to query

I have a database class that in __construct() initialize a PDO connection and insert the instance into a $db private var. Now i'm working on a method that can be ...
43
votes
7answers
2k views

Instantiating objects with many attributes

I have a class with quite a few attributes, most of which are known when I create an instance of the object. So I pass all the values in the constructor: ...
18
votes
2answers
574 views

A take on DB Abstraction - PHP / MySql

It's a little bit more code but i wanted to show the full class. I highlight the points i'd like input after the source. I've cut comments since they where not in english and translated the important ...
11
votes
2answers
362 views

Is this a sufficient way to prevent script injections and other bad stuff in strings

Would this function be sufficient enough to remove all malicious code and foreign characters from a string? ...
7
votes
2answers
2k views

Loop with enclosing items every 'n' steps

I'm listing elements with a foreach, and I would like to enclose items in something tag n by ...
6
votes
2answers
795 views

PHP/Doctrine bootstrap for review

Here's my bootstrap.php for my PHP/MySQL/Doctrine app. It's my first PHP app so I'm interested in learning from the experience of others how this could be improved ...
6
votes
2answers
1k views

Critique My Codeigniter Custom CMS Pages Model

I am currently developing a custom CMS being built on top of Codeigniter and was wondering if you can spot any flaws in my page fetching model code. The page fetching model is not entirely complete ...
12
votes
4answers
306 views

Test case for a caching library

This shows a test case for an old caching library that I use for a project. It features simple save/load/delete functions (sadly static calls) but what I want to focus on is the test code written for ...
8
votes
2answers
1k views

Comparing data in 2 tables on different servers with CHECKSUM

So I've had a problem where I need to compare data in 2 different tables on two different servers. Now, I know MySQL supports CHECKSUM TABLES, but from my testing ...
26
votes
3answers
32k views

CodeIgniter Active Record Subqueries

I use CodeIgniter at work, and one of our model files had a lot of subqueries in it. I originally had to manually write each subquery, and wondered if I could use active records instead. So, to make ...
24
votes
4answers
1k views

PHP Autoloader Library

Basically, I had written this class a little while ago to ease autoloading of our local libraries. The premise is that everything is split by packages into multiple layers of sub-packages. Classes ...
38
votes
5answers
9k views

Database connection in constructor and destructor

I am playing with different ways to do database interaction in PHP, and one of the ideas I have been playing with is connecting to the DB in the constructor and disconnecting in the destructor. This ...
12
votes
2answers
1k views

PHP mcrypt AES encryption wrapper

There are two keys: the main is aes128 and the second is XTEA, used just for randomization of data inside the AES. Randomization is done with secret random key that is not know even if someone knows ...
5
votes
1answer
706 views

AES encryption wrapper

After taking into account answers for my questions here and here I created (well may-be) improved version of my wrapper. The key issue was what if an attacker is knowing what is encoded - he might ...
19
votes
3answers
501 views

Encryption functions based on mcrypt

I learned here that it is unsafe to design encryption algorithms from scratch. Given that advice, I made a pair of encryption functions based on mcrypt: ...
7
votes
1answer
142 views

Bad code to handle image upload

I'm using this form to submit articles into the database: ...