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

learn more… | top users | synonyms

2
votes
3answers
29 views

Manual sorting of database output

I have a small (few elements) list of primary keys, sorted by hand. It come from user input. For example $ids = [15, 75, 54, 13]; The SQL command is simple. ...
0
votes
3answers
44 views

Which one is the best practice for DRY?

I always prefer to minimize the code, but sometimes I got int conflict with others people by the DRY concept. In this simple example, which one would be a good choice? ...
0
votes
0answers
15 views

Having critical section for PHP using redis

Currently, I'm using redis to implement critical section for PHP code, to ensure there isn't more than one process/thread to execute the enclosed code block. I was wondering, is there any edge cases ...
-4
votes
0answers
9 views

I'm having problem in image inserting in database based upon gender [on hold]

if user select male then male.png should be inserted into database if he select female at register page female.png should be inserted into database... i have this code but not working for me Im ...
3
votes
1answer
25 views

Ranking and storing scores to a database

I am developing a small website with PHP and am trying to receive user exam scores from the database. I rank it based on the highest score and then store the ranking to the database based on the ...
-4
votes
0answers
12 views

PHP Redirect not working after site hosted [on hold]

I have created a redirect in PHP which redirects to another page depending on if the user is an admin or not. This code worked in WAMP and XAMPP but now I have hosted it online (GoDaddy Hosting) it no ...
0
votes
0answers
15 views

PHP POST for HTML Select using another POST [on hold]

Original Post This ain't something not working but just I'm confusing about how to do it, I want to fetch the values from my DB based on users' preferences that been chosen earlier. These are the ...
-1
votes
0answers
10 views

Trouble with mod_rewrite in PHP [on hold]

I am developing a small website with PHP which has a backend for admin and i want to use mod_rewrite to change the links from localhost/site/adminpanel/index.php?page=sample to ...
1
vote
0answers
25 views

Basic Container class and KeyParser class

I have written a basic Container class, which is able to hold data by key-value-pairs. The keys can be notated as an array (e. g. ['database', 'host']) or a string, ...
2
votes
1answer
36 views

Storing option value

I currently have a design that is used to store user/selected options in a database, but I am not sure what I am doing is good or not. I need some opinion, suggestion and criticise on the design. ...
1
vote
0answers
22 views

Add user and image upload script

This is my Codeigniter Controller and Model for user image and data upload. I have some questions here: Is this good way of writing this script? Can this code be put to production if its need is ...
-3
votes
0answers
13 views

SQLite3 class in PHP not working [on hold]

I'm trying to connect to an SQLite3 database through PHP however all the code that I have tried has failed and now I'm starting to think that I may have set up my system incorrectly. I am running ...
5
votes
0answers
26 views

Counting duplicate tags in a string of many tags

I have a photo list page where each photo has multiple tags (as spaced words). I'm trying to display most of the tags on the page after: Removing duplicate tags Sorting tags by having most occurring ...
3
votes
2answers
64 views

Simple web form in PHP

This is a simple web form handler in PHP that sends a completely filled web form to a email. I see lots of repeating code. What is the best way to reduce repetition? Is my way of checking for fields ...
3
votes
1answer
69 views

Making change using the smallest possible number of coins

I have written code based on the Greedy Algorithm. The example can be found here. Problem: Make a change of a given amount using the smallest possible number of coins. Coins available are: ...
2
votes
1answer
40 views

Setting Class Properties

I am adding classes to some legacy code and wondering if there is a more appropriate way to be setting the properties. I am also trying to understand the trade offs, if there is another way to do ...
-2
votes
0answers
17 views

PHP Event library using Mediator+Observer pattern with best OOP practices [closed]

I'm working on developing this PHP event library for one of my other projects to use. The code is fairly complete, but I have this nagging feeling that some parts of it could be structured better, and ...
6
votes
1answer
48 views

Multiple file upload class

I've written this a few days back, which is not too big. Do you see anywhere I can improve my logic? ...
1
vote
1answer
55 views

Laravel API design

I've been designing and coding my Laravel API boilerplate for couple days now, and I'd like to hear some advice/improvement hints! I'm pretty satisfied with the result, but I'm also aware, there ...
2
votes
0answers
36 views

Secure array encryption and decryption

I have written the below class which encrypts and decrypts a PHP array. The encrypted data and the hash are sent over an insecure connection and I would appreciate if you could check the code for any ...
1
vote
1answer
55 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. ...
2
votes
1answer
43 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
16 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
32 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 ...
2
votes
0answers
29 views
+50

Get similar posts with manyToMany relationship

I have a table post with a many-to-many relationship with the tag and product tables. ...
1
vote
0answers
21 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
vote
0answers
147 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
1answer
47 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
28 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
26 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
1answer
74 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 ...
3
votes
1answer
50 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
53 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
24 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
698 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
43 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
37 views

Reorganizing a PHP array structure (arrays within arrays)

I have this array within array which contains a lot of values: ...
1
vote
3answers
69 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
73 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
38 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
117 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
94 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
99 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
49 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
42 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
73 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
60 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
54 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
63 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 ...