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

learn more… | top users | synonyms

0
votes
0answers
2 views

PHP/Symfony2: Using traits vs services to reduce controller verbosity

At the moment we have a bundle where controllers do most of the work (bad). Having hundreds of lines of code in a controller action makes it hard to read, and also introduces plenty of bugs. This ...
1
vote
1answer
36 views

Generating tables of numbers in PHP

I have this code and this works fine but I think it's too lengthy. I want to know if there can be a less lengthy code. I've heard from people that lengthy code is often not considered good. ...
1
vote
1answer
27 views

PHP class to represent types of refrigerants

I'm relatively experienced with Java and C++ so picking up PHP wasn't too difficult. I wanted to get some feedback on my first PHP class. There's nothing extremely complicated as of now, but its nice ...
1
vote
0answers
14 views

PHP to Powershell - Transport Function

I had previously made a script for an Active directory password changer but i wanted to compress the main component into a function by itself to keep it small. ...
1
vote
0answers
23 views

URL image validation

I'm trying to write a method to validate an image from a URL. The method will accept an array of image URL. The image should be validated by its type, size and dimensions. Right now, I'm able to ...
1
vote
0answers
11 views

Get similar posts with manyToMany relationship: Make faster

I have table 'post' with manyToMany relationship to 'tag' and 'product' tables. post <---> tag post <---> product For example, if I have post, I can get similar posts similar by tags and ...
1
vote
0answers
11 views

JWT with Firebase php-jwt

So my web app requires JWT authentication and I decided to make a mockup wrapper class for php-jwt before implementing it into my web app: ...
-1
votes
0answers
38 views

Deletion after Uploading in PHP? [on hold]

I am uploading a file to a server via JS and then I need to delete that file using PHP. Which of these two solutions would be better? CODE: ...
1
vote
0answers
116 views

Repository pattern in laravel 5.1

I am currently working on an ecommerce project in Laravel 5.1. I have implemented Repository Pattern by learning from this site only for 1 model, namely, ...
-3
votes
0answers
26 views

PHP Messager: Get new messages [on hold]

I am learning PHP and have been reading some books and tutorials, and I have started working on a php messaging site just to learn some techniques. The problem is that i cannot work out how to refresh ...
3
votes
1answer
44 views

Printing a huge document

I have a web page containing n pages of paged data, showing 20 records at a time. The front end has a link to another page that opens the same data, but without the paging and calls ...
-1
votes
0answers
27 views

Base class that records its GUID and creation time

Due to the lack of support for initialized default object values for class properties, I am experimenting with a self factory. ...
2
votes
1answer
23 views

Silex - Guzzle call to external API

I'm at the point where I am happy with the functionality of my code but I dislike how its written. It seems like I can be more modular with it but I can't seem to figure out how to improve on it ...
-2
votes
0answers
22 views

Check if value is empty upon assignment [on hold]

I don't really know where to ask this, but in PHP, is this okay to do? if( empty( $value = file_get_contents("some-file") ) { ... } I find that it works in my ...
1
vote
0answers
39 views

A form builder component

I would love my component to be reviewed. I am looking forward to responses mainly answering the questions: Is my code violating the SOLID principals? If so, where and how? Does my component contain ...
1
vote
0answers
17 views

Util method for generating an INSERT sql dynamically

I'm currently building software that: 'talks' to Google Analytics API, fetches data, persists the data to a MySql db. Insertion of data into the db needs to happen automatically - based on the ...
2
votes
1answer
39 views

Insert and attach tag to the post in same time

I created a form with title, body and tag input and there are 3 tables: posts, tags and post_tag. Now I use this function to add new tags and attach them to the post postcontroller.php ...
-1
votes
1answer
51 views

How to make a switch statement smaller

I have a very long switch statement with more than 18 cases. I want to make it more comfortable and easier for the maintenance, but I have no idea how ... ...
1
vote
0answers
21 views

Selecting random results within Doctrine

I'm new to Doctrine and had a hard time deciding how to get random rows within it without creating custom DQL functions or using a native query. The solution I have come up with is below, this is ...
3
votes
2answers
688 views

Hashing passwords in PHP

When hashing a password, I understand it is best not to use functions such as SHA1 or MD5. This function is working fine and I want to know if it can be improved to increase site security. ...
1
vote
2answers
39 views

Clean regex matches with named matches

I have a regex pattern that will match some elements from a string and give them a particular name. For example, #^(?<foo>.*)^# will match the whole string ...
1
vote
1answer
35 views

Reorganizing a PHP array structure (arrays within arrays)

I have this array within array which contains a lot of values: ...
1
vote
3answers
65 views

Using cookies in PHP

I was wondering if there was a better way to do this. Would that mean there would need to be no client-side refreshing to show the cookies when they are created? ...
0
votes
1answer
58 views

Laravel API class design

I am building my first Laravel web app and I have created a class to handle API requests for a model called Quote. In what ways can the code be improved or reduced? ...
0
votes
1answer
30 views

PDO lastInsertId

In my shop system I'm using the PDO lastInsertId to assign the order_id to the products that belongs to it like this: ...
4
votes
1answer
97 views

CRUD operation using Object relational model and Data Mapper pattern for a Matrimonial website

Database.php As the name says, it create connection and execute query. Although I think I should make it static/singleton class. ...
4
votes
1answer
87 views

Login Authentication & Sign Up

This is a Login Authentication / Sign-up Models for my class project in PHP. I would really appreciate criticisms and any suggestions to improve security, code quality, etc. Hashing.php ...
3
votes
3answers
93 views

Sanitising contact form input for PHPMailer

I would like some insight on this function for sanitising user submitted data into a contact form. No HTML content or anything, just plain text. Are there any vulnerabilities here that I'm missing? ...
3
votes
0answers
40 views

Converting uploaded video and saving preview images

I'm coding a basic video upload system for a client. The uploaded videos will live on the page using the HTML5 video element. Essentially what I've done is call the following PHP script ...
-1
votes
0answers
40 views

Updating fields in a MySQL database

I had to update the question ID of an answer table according to some condition. I have written the following script but it takes more than 700 seconds to execute because the data is huge. ...
5
votes
1answer
66 views

PDO Insert function using PHP

This code inserts data into the database successfully. I was concerned about whether it is a considered good practise to go about inserting data into the database in this way. Is there something I am ...
1
vote
2answers
58 views

Enumerate all items to find those that match a complex condition

Currently, I have a big for..loop with many if..else inside the loop. I just wonder is there any design pattern or other ...
1
vote
0answers
39 views

Codeigniter form flow for model and controller

I'm working with Codeigniter most of the time (about one and a half year now) and I came across many form validation code flows. Here are my best two selected shots which I created for a client ...
1
vote
0answers
62 views

Cron job that sends an email

The following is a sample cron job I've written that sends an email with some conditions. I haven't run it yet but I'm using another cron job (and will rewrite very soon) that does the same thing but ...
3
votes
1answer
50 views

Custom error/fatal error and exception handler in PHP

Introduction I wrote three functions that aims to log errors and exceptions as well as show a user a generic error page. Would appreciate some feedback on it with regards to the PSR standards and if ...
1
vote
1answer
52 views

PHP script to connect to MySQL database using PDO

Introduction I am preparing to use a basic script to cover how you can connect to a MySQL database using PDO. This script is meant for educational purposes (introductory class on PHP/MySQL) and does ...
2
votes
0answers
28 views

Boarding cards route finder

Recently I had an interview project, which I did and sent, so this question is not for avoiding thinking. I am just struggling to build my own opinion about it so I decided to ask in public. My ...
4
votes
0answers
84 views

Handling CSRF protection

I'm currently working on an implementation of a CSRF protection. What is the best practice when we detect a CSRF? Is it better to 404 the page, 403 (forbidden), 200 (OK) with an error message, ...
0
votes
1answer
25 views

Applying prepare statements

I don't feel that my code is secure, and would like some help in using prepare statements for the following; ...
2
votes
1answer
65 views

Using $_POST and $_SESSION - passing variables between pages

I have an index page which gets passed $_POST['timestart'] and $_POST['timeend'] variables. In addition, I have a cart page ...
-2
votes
2answers
73 views

Using a lot of IF in loop WHILE to print information

I made a code and it is doing what I want. But, I would like to know if I am doing it right or in the best way. Could you please give me your thoughts about it? Thank you. ...
1
vote
1answer
62 views

Checking whether a site is up or down

I have this PHP curl function to check if a site is online or not: ...
2
votes
3answers
105 views

Checkout (page) backend

I am developing an e-commerce site and am confused about this. Customers come on the site and add some products to the cart. Customers click on the checkout link if already logged in, then will go ...
5
votes
3answers
233 views

String to Array formatting

I'm tying to convert from this formatted string: $filtersStr = "id:1||name:alex"; to: ['id' => 1,'name' => 'alex'] ...
5
votes
1answer
27 views

Volunteer Signup Report - follow-up

Here is the original question. I've incorporated a lot of the feedback and I'm ready for another round of feedback and suggestions. Here is the PHP file's output. It creates a volunteer signup report ...
4
votes
0answers
138 views

Small PHP-MVC system (for personal learning / use)

I've made an "simple" / "small" MVC-like PHP system. I've used some code of an project I used before and ask questions about it back then to. The thing is, it works (the admin part to begin with), ...
2
votes
2answers
73 views

Registering usernames and passwords to a database

Here is my script that registers a user to a database. I am still very much a newbie when it comes to this topic so any guidance would be greatly appreciated. ...
0
votes
1answer
50 views

Update live table in MySQL

After populating the stock_tmp table, i'm running these SQL queries via legacy mysqli wrapper code. I don't think this code ...
3
votes
1answer
46 views

Loading files or directories based on type

I am building a config class for PHP which initially loads all given config files. To add files, users should be able to provide either a single file or a directory where files can be JSON or PHP. ...
1
vote
1answer
35 views

Handle data received by Ajax request and update database (prepared statement)

I have an Ajax request from a page where the user is being asked to enter their date of birth. The request URL file has the code below and works all good. However, I'll be rewriting all MySQL/MySQLi ...