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.

81
votes
3answers
5k views

Shielding your CodeReview on GitHub

In response to a feature-request on meta, I spent a few hours today creating the feature in php. This application adds a review shield to your GitHub repository (or wherever else you want it). It ...
49
votes
2answers
57k views

Class for reducing development time

There are many PHP PDO classes out there, agreed. However I find they do not allow for flexibility. So I created one that helps reduce development time as little as it may be but it does the job (...
46
votes
3answers
33k views

Trait accessing variables of classes using it

I just tried PHP Traits for the first time, to keep my code DRY : ...
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: ...
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 ...
36
votes
3answers
4k views

Displaying courses in an HTML calendar

I'm struggling for a while now with the readability of my code, I after I tried to get as much insight as possible (for my standards). On my level, I think I understand and use it all right for my ...
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 ...
30
votes
6answers
76k views

Setting a default value if a variable is empty

This is the pattern I've been using for "if the variable is empty, set a default value", and for variables like $muffin, it has all seemed well and good. But in ...
28
votes
5answers
122k views

Modifying an array during a foreach loop [closed]

This question is always on my mind. I usually alter the array while looping through its keys, based on my gut feelings: ...
28
votes
3answers
2k views

Small PHP Viewer/Controller template

I have written a small template Viewer/Controller esque library that I would like some critiques on. The library is located here If you are looking for where to start, check out ...
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 ...
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. <...
24
votes
6answers
2k views

Are there any open vulnerabilities in this mailer script?

I made a PHP mailer script does the basic validation of fields, return errors, else submit if all is good. But it also has a honeypot field that is not required to be filled in (I'm assuming by hiding ...
24
votes
3answers
2k views

How is my CMS design? Any security, design, or other issues?

I am trying to learn PHP in depth by creating this personal CMS. I try to utilize OOP concepts and do best I can... The way I am trying to design this CMS is to keep including 'modules' within a page ...
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 ...
24
votes
2answers
7k views

Custom session handler class - is it robust enough?

I've been working on this class for a while now and would appreciate some feedback, even if it's just nitpicking. I've added basic instructions on how to use the class below along with some questions. ...
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 ...
21
votes
3answers
5k views

Using 503 page when my site is in maintenance mode

This is my code for 503 page: header.php if(getOption('maintence_mode')==1) { header("location:503.php"); exit; } 503.php ...
21
votes
3answers
3k views

Project Euler #1 in PHP

The code below works & as far as I can tell the result is correct. Would you please review and let me know what I could have done better? I tried to use variables as much as possible, that way it ...
21
votes
6answers
2k views

Login Form in HTML

I am a beginner and I have made Login Form in HTML. I'm pretty sure it will look horrible to any developer, but hey, that's why I've posted it. I'd like a general review of this. I'm especially ...
21
votes
1answer
626 views

Thoughts on my brain fart interpreter?

Had some free time this weekend and I hacked together a small Brainfuck interpreter, with the sole intention of explaining PHP's flavour of OO to a friend. This is a bit over-engineered on purpose, ...
20
votes
4answers
731 views

HTML tag encoder

library.php My own HTML tag encoder that will print HTML codes according to the input. ...
20
votes
5answers
17k views

Calculate future date based on business days

I've written a program for calculating the future date after certain number of business days. ...
19
votes
3answers
625 views

Pluggin' in Plugins

I'm currently working on an in-house project and a part of that project is this pretty standard plugin loader below. There must be a way to avoid so many ugly looking ...
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: ...
19
votes
2answers
1k views

Allowing users to input a safe subset of HTML

I am currently working on a project that requires users to input text that may or may not be formatted (if it helps, just think of it as a Stack Exchange clone, even though that's not quite accurate). ...
18
votes
3answers
9k views

Show days of single week

I'm currently in the process of creating a online work schedule for internal use. For this, the client needs to show the days of a single week. I pass a week number and a year. From that I get the ...
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 ...
17
votes
3answers
980 views

Prepared statements from security viewpoint

I've decided to go with OOP style and prepared statements, and so far I like it a lot more than the procedural style. It's much more understandable in my opinion. For this code review, I've just ...
16
votes
4answers
2k views

PHP gaming community website

I created a gaming community website about 13 years ago. It uses PHP, SQL, HTML, and CSS, and does not use a framework or template engine. It includes features such as a login system for members, ...
15
votes
1answer
381 views

Portable website template

I have spent the last 6 months as I am studying web development in college to build a website template that is responsive and accessible from as many devices and browsers as possible. I would really ...
15
votes
2answers
2k views

PHP URL Shortener

I just developed a URL shortener. index.php: ...
15
votes
1answer
332 views

Cryptographically-secure super-secret government message transaction machine

-Hello Agent. Are you on a secure line? -Yes, secured. -Good, in 30 seconds the launch codes will be in your e-mail's inbox. You now have the go. Are you ready for the package? -Yes. ...
14
votes
5answers
2k views

PHP mail form is being abused

I'm nowhere near a PHP expert, but I have dabbled a bit. I can make things work just fine, but I am terrible at figuring out what is wrong. I was informed by our server admin that we have a mail ...
14
votes
6answers
4k views

Palindrome checking function

I recently did a little task for fun that required me to create a class to determine if a word is a palindrome or not. I know this is quite simple, but I'd be interested to know if a real developer (I'...
14
votes
3answers
963 views

Quick CSS style generator

One day, I was thinking: Wouldn't it be nice to set a class and have all the styles defined? And that is exactly what I did: a PHP file that generates CSS with pre-defined styles. So, for fun, I ...
14
votes
3answers
256 views

Mission impossible: beat everyone else to the queue

Your mission, should you chose to accept it, is to beat everyone else to the review tab so you get a chance to help out. This is a problem I've been running into lately. I go over to review tab, find ...
14
votes
3answers
390 views

Search script code efficiency

Is there a more efficient way to write this? This script will be used heavily and I want to make sure I do not have any memory leaks or speed issues. This script gets an input from a form and ...
14
votes
3answers
8k views

PHP Login System with persistent login

I'm writing my first CMS (for personal use) and I'm trying to make it the most secure I can. This is my project structure: ...
14
votes
2answers
7k views

Want to check if I am using PDO correctly

So today after few years of not programming in PHP I decided to go back, but to do so I needed to change all MySQL connections. So I want to check if I am using it good. Earlier I used to write ...
14
votes
1answer
913 views

Web application for a restaurant

I'm making a web application for a restaurant kind of type. The idea is to administrate the orders and customers. For selecting one of the orders and showing more specific data about it, I have this ...
14
votes
4answers
7k views

How would a senior PHP developer design this Login class?

How can I design this class and its implementation so that it looks like it was developed by a seasoned senior level PHP developer that follows all of the best practices? I'm trying to design this ...
14
votes
3answers
5k views

Constant time string comparision in PHP to prevent timing attacks

I've been advised that when checking the password hash for a user I should use a string comparison function that always takes the same amount of time, to avoid timing attacks. So I wrote this: ...
14
votes
2answers
480 views

My final sign up controller

I've asked a couple of questions here before regarding my controller, but I think I've finally gotten to understand controllers completely, but I'll never be sure unless I get my code reviewed. I've ...
13
votes
4answers
3k views

Heavily-criticized tax calculator

I just created this during a live screencast. The people who were on there were very critical of almost every line of code. They say I am a horrible coder and know nothing. Looking at this tax ...
13
votes
4answers
1k views

Human class implementation

I just want an indication as to whether or not I'm on the right track regarding PHP OOP, at least on a basic level. Positive criticism welcome. P.S. Excuse the visuals of the code. This is how I ...
13
votes
3answers
7k views

Basic user registration code

My first attempt at a user registration code. Login.php defines database log in variables (e.g. Database name, Table name, etc) ...
13
votes
3answers
1k views

First domain-driven User entity class

I'm still learning about domain driven design, and I have created my first entity class User. Is this fully compliant with the DDD principles? Particularly my ...
13
votes
2answers
18k views

Forking with PHP (4 different approaches)

I thought about three (now four) different ways how to execute forks with PHP. What is the faster, maybe better solution and why? PHP script included ...
13
votes
1answer
2k views

Object-oriented file upload handler for a CMS

I've started with a bunch of functions, made the code work, then I spent a day rewriting it in an OO way, as much as I can. I've tried to group up the task into objects, letting the relative data go ...