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

learn more… | top users | synonyms

5
votes
1answer
62 views

Is there a more elegant solution than this spaghetti code without completely revamping the whole page?

I use 'GROUP_CONCAT' to get comma separated lists of a person's educational background. Included in those lists are the type of degree, major, issuing establishment, and year received. ...
-1
votes
1answer
70 views

Is this shopping site safe from SQL injection attacks? [on hold]

Please verify security from SQL injection attacks. homepage.php ...
1
vote
1answer
28 views

Creating accounts in a cpanel/whm account

I am trying to make this code that creates accounts in a cpanel/whm account more secure. Could someone please let me know what needs to be done to make this more secure? ...
1
vote
0answers
31 views

Automatic submenu

The goal here is to create a Top Level Menu that automatically pulls child pages without the need to manually add them to said menu. I didn't know any other way to accomplish this without a walker, of ...
1
vote
1answer
39 views

Optimized solution for a rolling dice code puzzle

I was asked to provide the solution of this rolling dice problem in an interview. When I showed him my solution, he said that there is another way to find the solution. I am looking for answer in PHP ...
14
votes
6answers
1k 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 ...
3
votes
3answers
67 views

Password hashing/handling on a form

Does my code look secure right now? I know that I still have the password hashing and so forth, but what about SQL injections? Do I have any? Are there any other security issues? ...
3
votes
0answers
42 views

Handling page requests in MVC

Is this an efficient way to handle page requests in MVC? index.php: require 'Classes/Autoloader.php'; Autoloader::start(); Session::start(); new Bootstrap(); ...
-1
votes
0answers
19 views

Object oriented PHP [on hold]

I'm diving into object oriented PHP now, and I'm not sure I'm doing it right. Suppose I have a class ...
8
votes
4answers
644 views

Is this function vulnerable to SQL injection?

I've this function to list products from database by category. I'm using prepared statements but wouldn't this make it pretty pointless to use them? ...
3
votes
1answer
62 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
19 views

Show PMD violation report in netbeans editor [closed]

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
2answers
98 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
27 views

What is this file structure method called? [closed]

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
3answers
60 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 ...
4
votes
0answers
28 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
71 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
1answer
45 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
43 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
67 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
2answers
102 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
62 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
95 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
47 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
41 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
168 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
67 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
32 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
55 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
37 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
58 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
139 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
67 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
27 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
42 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
80 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
35 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
105 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
131 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
341 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
33 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
66 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
182 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
33 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 ...