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

learn more… | top users | synonyms

0
votes
0answers
5 views

Possible to shorten my code of error displaying (if-statements)

Is it possible to shorten this piece of PHP code? Honestly, I think it does not look clean but like a mess. ...
0
votes
0answers
18 views

Show PMD violation report in netbeans editor [on hold]

So, I have a PMD violation report, it was generated by sensiolabs insight, I want netbeans to read this report and color files that contains violation and when I open the file I want netbeans to put a ...
1
vote
1answer
57 views

Creating a Party Game to learn OOP

I've been developing sites using Dreamweaver for the last 15 years, I do a lot of code editing manually so I have quite a good knowledge of the PHP language. I'm diving into object orientated ...
0
votes
0answers
25 views

What is this file structure method called? [on hold]

I have been using this file structure for a while now and I'm not sure where I got the idea from (possibly PHPBB? Maybe Wordpress?) Basically, I create a page, like ...
2
votes
2answers
40 views

Inline PHP IP access log

For a website, I've got some inline PHP, posted below. It's supposed to log traffic to the website, and it does its job fine. But at the end of the day, I'm not even close to a PHP developer, and ...
3
votes
0answers
21 views

Filtering queries based on the current user state

I have a Symfony2 project. I have an Entity Asset which can have relations with Category. I store a ...
3
votes
2answers
66 views

Is there a “prettier” way of forming this query, or a more efficient way of joining the tables?

Yesterday I posted a question involving multiple nested queries. The queries pulled information from the database and created a directory listing of all employees. There are two many-to-many ...
1
vote
0answers
36 views

Optimized Form fields generating class

I am building an application full of forms and so I thought it is good idea to create a class to populate form fields. Here is my class and I am sure it can be optimized more than now and could be ...
0
votes
1answer
41 views

Would multiple joins boost performance, or are the nested queries an acceptable way to handle the situation?

I'm working on a directory that lists employee information. Each employee can belong to multiple departments and each employee can have multiple job titles. I have 5 ...
5
votes
2answers
61 views

Avoiding globals in gumball machine class

I'm planning to transition from years of forced procedural programming to OOP. I decided I'd start off small with a little gumball machine object to get my bearings. Everything seems to run ok, but I ...
1
vote
0answers
27 views

Binary search with heurisitcs or something else

Currently I'm using a binary search algorithm to search an index of a tree that represents an XML file. Can I use heuristics to improve the search? What can I do to improve this search function? ...
5
votes
1answer
70 views

UK tax calculator

I'm very much on the beginner end of the PHP scale but I have read plenty of the entry level books and completed the online training at teamtreehouse.com so I know the basics. I'm at a point where ...
4
votes
1answer
56 views

Generating random and secure CSRF tokens

I googled around for secure random number generation and random string generation, combining them with some user data. Is this good or am I totally off-base? I don't know much about cryptography but ...
4
votes
1answer
93 views

Throw exception in favor of an error?

I've been reviewing my previous projects for the last few days. I've found that I never return an error from any of my methods. I always throw exceptions. I googled about exceptions vs errors and I ...
0
votes
1answer
40 views

Class that handles header and footer includes looks like a mess

I tried making a class that handles my header and footer of my site. It looks like a mess, because I like to preserve the indentations as is. But I'm wondering if there maybe is an even cleaner or ...
2
votes
2answers
44 views

Assigning array keys based on the values of another array

An optimisation question: Currently I have entities stored in text files in the following format: ...
2
votes
2answers
38 views

Submit form data to MYSQL table with PHP execute

I have written code to send a simple email submission form to a sql table so that I can manage the data. I would like feedback on whether or not the code that I have written is efficient and secure. I ...
6
votes
2answers
165 views

Pattern to avoid Variable Functions?

I have some PHP code where I use Variable functions to call the right function. I need to build a chart array (for example), and the chart array that comes out has a fixed format. But the data that ...
4
votes
2answers
62 views

Reduce similar methods via pattern?

I've put together a simple application in order for me to learn sqlite and OOP in PHP. The application basically outputs two random words, e.g. "Angry Badger", from two database tables, one called ...
3
votes
1answer
65 views

Redunancy Issues in PHP Class

I've been studying PHP for a while now and decided to dive into OOP. Most of my code was a mess and I've begun to refactor much of the website to OOP; however, I'm having an issue with redundancy in ...
0
votes
0answers
30 views

Codeigniter ActiveRecord Wrapper Model

Can someone help me refactor this to be more optimized? Performance seems to be very optimal, but I think more can be squeezed from it. ...
3
votes
1answer
45 views

Flat-file DB with CRUD

I just finished writing a flat-file DB class for PHP which supports selecting, updating, inserting and deleting. I was wondering if there are any ways to make it faster or if I'm doing anything the ...
0
votes
0answers
35 views

First Laravel Package [Social User Login] ? 4.1x

This is my first Laravel package it uses hybrid Auth package to authenticate users using their social network accounts. It can retrieve information to store in a local database. It's purpose is to be ...
4
votes
1answer
50 views

Security - Login system

For a school project I have been asked to create a login system for a website. The language I have to use is PHP with no database as of yet (for a later assignment). I'm just wondering if this code ...
2
votes
1answer
132 views

How to prevent SQL injection PHP and MySQL?

I have been reading about SQL injection and I want to secure my code. I am not asking anyone to write me a code, but I just want to learn it in simple terms. The best way for me to learn is to edit ...
2
votes
2answers
64 views

Type hinting for scalar types

As you're probably aware, PHP doesn't support type hinting for scalar types. I feel this might be good practice to build into my framework, although I'm aware some of you might disagree seeing as PHP ...
3
votes
1answer
35 views

Generate regular expression based on inputted number

This is my first PHP script (although I like to think I'm a good general coder). The script accepts a number from the user, uses it to generate a regular expression, and then returns all dictionary ...
3
votes
0answers
25 views

Is there a simpler or more efficient way to display random “ads” from an XML document?

I have an xml document that contains "ads" and includes information about the department name, image name, link to URL, and alt text. I have a ...
1
vote
1answer
41 views

Optimising and consolidating multiple PHPMailer functions

So the two functions below both send emails via PHPMailer but both hold different messages (which use different data from the db). I was just wondering (as I plan to use PHPMailer more) a way to ...
1
vote
2answers
78 views

Too many nested blocks fixed but not sure if this way is right

I have previeous;y posted my php code with way to many nested blocks I hope I fixed it right. I'd also like some tips on my OOP, as this is new to me. ...
4
votes
0answers
34 views

Making a FileHandler more OOP friendly using SOLID

I have a class created for the sole purpose is to help handle files. The class holds a path(folder) that contains a single file at a time. Some extra properties to this class are: age of a file and ...
4
votes
1answer
102 views

Am I over-engineering?

So I just jumped to a new project, which uses activerecord pattern. It's a subscription service website. I have the following User object that extends a framework specific ORM object. ...
5
votes
4answers
126 views

Neatest way of including a header and footer on every page

I just got into Object Oriented Programming, and it made me think about certain code how I can make them as efficient as possible. Right now I am just including my header and footer like the ...
5
votes
3answers
333 views

Calculate a month later than current month (without rolling over to next month)

I needed a script for working out billing dates over a period of time. The date should be the same day every month however if the billing date starts on a date that doesn't exist in another month, ...
1
vote
0answers
32 views

Refactoring Data lookup table with Redis and API call

Background to the code: This class' function is to change a given array's data into an ID. The list is set by a configuration file. I have DI the outer array and objects into the class so that if ...
2
votes
3answers
63 views

If/else that contains HTML blocks, which contain additional PHP functions

I have a form that posts (a,b) values into the following .php file, and displays an error message when the user tries to reach the .php file directly, instead via POST request. This code is probably ...
7
votes
6answers
1k views

Shorter way to write multiple if-then-else-if

if($row['best']){ $id = $row['best']; } elseif($row['average']){ $id = $row['average']; } elseif($row['bad']){ $id = $row['bad']; } If ...
4
votes
3answers
179 views

I have a huge function filled with nested blocks

Could someone help me on how to eliminate some nested blocks or improve this code? I am concerned this will slow down my site dramatically. ...
1
vote
1answer
31 views

Test 2 time ranges to see if they overlap

I am doing a project for school and had to create a function to check if 2 time ranges overlap. I searched the net a bit but failed to find a simple function to do that. I played around a bit with my ...
1
vote
0answers
39 views

Persistable specifications in symfony

I'm creating an app where the user will be able to create HTTP request matchers. So the RequestMatchers will match HTTP method, path, query parameters, etc., for ...
2
votes
1answer
92 views

Is this right structure for MVC / MVP application?

I have written a code for an application/website that I wanted to be structured similarly to MVC design pattern (but I think it's rather MVP based on comparison I read). This functions as a kind of ...
3
votes
3answers
616 views

Any simpler and more efficient way of writing this code?

I've noticed I've got quite a few repeated lines in my code. ...
3
votes
1answer
50 views

Return current URL

I was unable to find how to get current URL so here's what I've made. Brief tests didn't reveal anything bad. Your thoughts, educated opinions, suggestions, and comment on potential bugs or ...
3
votes
0answers
37 views

Sorting a PHP array in a discontinuous manner

I start with an array containing some 'ids' and some 'values'. What I need is to organize the 'ids' in a new array to be, if possible, apart when the 'values' they are associated with are alike. So ...
3
votes
2answers
76 views

Simple design pattern for authorization in PHP [closed]

What do you think about the following class? Do you think it is a good approach to solve the authorization problem? I'm looking for a very simple design pattern. ...
5
votes
1answer
70 views

Extract code and convert special characters to HTML entities

I want users to enter their code into my blog and keep original styling tags intact. So I had to develop a function that extracts user's code (between two tags) and convert special characters to HTML ...
7
votes
2answers
74 views

Merge some child values back into the parent multidimensional array

This is a wonky PHP function I came up with to merge some select values from child arrays into the original. It could really use some help simplifying / making it more elegant. Is there a built-in ...
4
votes
2answers
360 views

Is there a PHP security exploit with $_POST in my code?

I posted this question here. And an answer stated that I should not do: $table_name = 'survey_'.$_POST['surveyid']; because It is easy for a hacker to ...
3
votes
1answer
42 views

Better Way for PHP Array Offset Without Losing Values

After looking through PHP.net documentation for hours, is this the best way to offset an array from start to finish by using array_slice() with ...
4
votes
1answer
58 views

Am I organising my PHP code effectively?

I'm very new to learning PHP & MySQL (I've got past experience with Java) and I'm doubting whether my code is organised well. I've got an index page which has two forms; the first is a form to ...