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

learn more… | top users | synonyms

1
vote
1answer
30 views

Simple CSS Parser

I wrote a very simple CSS parser and would appreciate some general feedback regarding the security, code style etc... Basically, this does the following: Take user's uploaded CSS file Save it to ...
3
votes
1answer
23 views

Web application to insert into MySQL database

I'm currently learning PHP, SQL/MySQL and HTML to develop a web application project (I have very little practical experience in all of these.) To get started, I spent far too long and many questions ...
3
votes
4answers
94 views

Returns values for a specific array and key

This code is intended to take an array and a key as inputs, and return an array of the values paired with that key. ...
2
votes
2answers
101 views

Are either of these better than other performance wise?

I have these few lines of code (written inside a Smarty .tpl file). ...
4
votes
3answers
34 views

Controller method - Ajax request

I'm quite new to Laravel, and I'm not sure what am I doing is the best practice. I'd like to return JSON if the request is Ajax, or return a view otherwise. This is the way I made it, and it works ...
0
votes
0answers
9 views

laravel: controller method - ajax request [duplicate]

I'm quite new to Laravel and I'm not sure what am I doing is the best practice. I'd like to return json if request is Ajax, or returning view otherwise. This is the way I made it, works fine, but I'm ...
12
votes
3answers
947 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 ...
1
vote
1answer
39 views

Case of the Hidden Memory Leak

Somewhere in the code below seems to be a memory leak. A couple of users were exceeding 512Mb and I'm not sure how. Adapted the following SO code to try and test memory usage of each function on the ...
0
votes
0answers
13 views

Trying to convert what I currently have into a new Javascript powered section [on hold]

I am currently building a site in Drupal, and have setup an article page to look as I want it. ...
6
votes
2answers
422 views

Animal choir simulator

I got a PHP developer interview test to solve for a company. I didn't get the job but I would like to know where I was wrong. Did I understand the test completely? ...
3
votes
0answers
28 views

Use of die() in flow control - proper and sensible?

Designed for OpenCart, vQmod places or replaces bits of code based on XML files. The following three versions of the code achieve the same goal, which is to ...
9
votes
2answers
99 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 ...
5
votes
2answers
78 views

Initiating class objects and arrays

I have a class that always has 14 instances. I'm just wondering if there is a better or more effective way of doing this. In this class I also have an array that is filled by calling 4 functions ...
1
vote
1answer
34 views

Calculating the price of digital media

I have taken over maintenance of some code, and have restructured it after reading some documents about PSR-2; this is the result: ...
0
votes
0answers
62 views

Foreach with the aim of removing the need for a $global

Below is a function (part of a procedurally written Wordpress plugin) which iterates through a multi dimensional array of regions, adding them to a custom hierarchical taxonomy. In the spirit of ...
11
votes
2answers
499 views

PHP URL Shortener

I just developed a URL shortener. index.php: ...
5
votes
3answers
114 views

Regex to validate font names

/((([\w -]+)|("[\w -]+"))( *, *)?)+/ http://refiddle.com/18ql I'm trying to use a PHP regex to sanitize a user input for a list of fonts. The above one seems to ...
1
vote
0answers
36 views

After refactoring using template class, PHP file takes forever to load, timeout after 30 seconds at times

I've been learning how to code for the past 3 years about. I have made some really good progress I think, and right now I'm trying myself on creating an MVC framework. I found this awesome idea on ...
5
votes
1answer
39 views

Clarity of encryption class

I have recently gotten back into development and I am wondering if the script I have just created is clearly documented and easily understandable throughout each step. Is it easy to understand? ...
6
votes
2answers
48 views

Attempting to utilize OOP with a user-management class

Originally, this isn't how I would have done this at all. I was told by someone I know who is a programmer that I needed to include several functions: one for removing and adding users, one for ...
5
votes
1answer
77 views

Proper way of using the MVC concept - update

Original question: Is this the proper way of using the MVC-Concept? I updated my files as instructed, and now I require a review. Please point out the most minute things out to me for me to have ...
5
votes
2answers
210 views

Is this the proper way of using the MVC concept?

I've just completed coding my template engine. I'm willing to have a review on how to increase the quality, efficiency, elegance and performance of the code, perhaps by shortening the code, etc. I'm ...
4
votes
1answer
35 views

Speeding up class that uses an ODBC connection

I have created a class that gets data from an ODBC connection. The code works but it is really slow - I'm talking up to 1.20ish minutes to run. I know my code is inefficient but I'm really not sure ...
3
votes
2answers
78 views

Returning nested array with added key=>value

This works, but do I have to make a new array, result, or is there a way to just insert the field I need into each $key of the ...
2
votes
2answers
59 views

Filling modal from JSON (dynamically)

My Java app converts its modal object to JSON (using the GSON Library). This is just fine, but I have to get it back into a modal in PHP. Now I've created a modal (in my case it's, for example, ...
5
votes
3answers
124 views

Cleaner or better readability in URL composition

I have a URL that is hardcoded via a config which I extract into a config: ...
3
votes
1answer
25 views

Login system, PDO and me - Part 2

This is a follow up question to: Login system, PDO and me Is this considered secure for a login script? ...
2
votes
1answer
30 views

Admin page select

This is a follow up question to: Admin page select function Here, index.php does the following: Checks for a login status using sessions and a cookie If logged ...
10
votes
2answers
528 views

SQL injection safety check

I was wondering if my code is safe for sql injection. This code just checks if the username exists in my db or not. ...
1
vote
2answers
71 views

Simple wrapper for an API

This is a wrapper for an API. For now all it does is get a certain document or search for relevant documents from a document store -- although I plan to build out more features later. I'm new to PHP ...
3
votes
2answers
89 views

Formatting options for a long IF statement?

I have a somewhat unwieldy IF statement and am wondering if anyone has any suggestions on how to make it more readable. One one line it was all but impossible to understand, so I broke it up into ...
6
votes
2answers
181 views

Displaying content based on the current time

I'm new to PHP and just wrote a bunch of if statements to display content based on the current time. Is there a better way of writing the following block of code ...
1
vote
1answer
68 views

Is this acceptable usage of try/catch and database transactions?

I am using try/catch syntax in combination with a database transaction to (hopefully) prevent partial registrations. I am ...
3
votes
2answers
69 views

Controller: Sign up action clean up

I don't know if it's just me, but I feel like my sign up action method has gotten a bit messy. I think that perhaps instead of setting error messages in a controller, I should set error codes which I ...
1
vote
0answers
6 views

PHP Cache Strategy - Genius or Sheer Stupidity? [migrated]

I have a shared hosting with limited capabilities. Memcache and mod_cache are not available to me. I would like to implement my own PHP caching method to cache the results of load-intensive SQL query. ...
3
votes
2answers
46 views

Using `exec()` in an autoloader

After reviewing autoloader functions on the site, I didn't see anything like this, and I was wonder what may be wrong with this? ...
3
votes
1answer
72 views

Clean up / refactor this store() method

I'm new to Laravel and trying to figure out how I can reduce/refactor this store() call in my SessionController. Basically, the ...
1
vote
0answers
64 views

Automatic condensing of whitespace in HTML

One of the things that has occurred to me more recently is that if you add up all of the bandwidth that is taken up by thousands of users downloading the newlines and tabs used to make HTML source ...
0
votes
2answers
67 views

Add a set of querystring params to a URL

Example cases: Need to add x=1, y=2 and querystring variables to the following URLs: ...
2
votes
1answer
41 views

Factory style pattern in method

I have a method in a class, and its sole purpose is to prepare another class for use: ...
7
votes
2answers
467 views

Protect database from SQL Injection and similar attacks - PHP

I am doubtful about the security of my PHP code. I am new to programming, but want to learn how to secure things, protect my databases from SQL injection, and other best practices. I'd like to know if ...
6
votes
3answers
422 views

Check efficiency of PHP code that will query over 8500 orders

I am querying all orders from a WordPress database that uses the WooCommerce Bookings plugin. I want to display upcoming bookings, and there is a potential to have every hour within 2015 to be booked; ...
2
votes
1answer
77 views

Basic PHP Factory Pattern

I have an object, KbArticle, that originally in it's constructor, would try to return null if the SQL query that retrieves the data for its required properties came ...
0
votes
0answers
9 views

What's a good simple way to combat the n+1 problem? [migrated]

I'm trying to better understand performance in PHP. One issue I'm thinking about is the n+1 problem. By n+1 I mean something like this: ...
2
votes
2answers
61 views

PHP Trait Singleton

An implementation of the singleton pattern in PHP using a trait (added in 5.4). Is there anything missing, any ways to create a second copy of the class? ...
1
vote
2answers
78 views

Get user level based on total posts [closed]

Let's say a user has 575 posts and I want to give access based on post level. In order for the user to be Level 1, that user has to have more than 200 posts, level 2 = 300 posts more (500 in total). ...
1
vote
1answer
49 views

Image upload and thumbnail creation script using PHP GD

Ignoring my shocking use of the mysql_* extension (and any associated issues), could you take a look at my script that uploads an image, adds it to a database, ...
5
votes
1answer
64 views

List files and download

The following code list all files in a folder and allows the user to download one of them. It is working but I think it could be done better. Is there a way to reduce the number of forms to only one ...
9
votes
2answers
201 views

Sessions and Authentication

I've a feeling I'm overdoing my Auth class, and that it could be done in a simpler and more understandable way. Could you give me advice on this, please? This is ...
5
votes
2answers
163 views

DB abstraction, private methods in OOP PHP library

This library registers a new user. Questions: Where should the DB class instantiation happen for user class? I tried instantiation in the constructor but that property doesn't seem to be available ...