Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [php]

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

1
vote
2answers
86 views

Notification system same code running twice, simplify it

I have a notification system. If someone posts a new comment to the topic you commented, then you get a notification. The problem is, that the code is looking awful. First I count how many ...
1
vote
1answer
40 views

Showing data for a chat with another user

I have a get route to show the data for a chat with another user. If an existing chat exists I want to return that, otherwise create a new chat and return it. ...
2
votes
1answer
71 views

PHP User management class

Here is my code for a class that is responsible for managing some common users task like registration, login and logout. It implements also a sub class that can be used to check the session of a ...
2
votes
0answers
142 views

PHP Login Checker Stage

I have been working on my script which allows people to sign-up and login to my website. I was wondering if someone could review the code. It works but I can't help but feel it could be optimized. ...
1
vote
1answer
70 views

Auto generate database table

I have written my own little auto-generated table class, and I was wondering if you guys can give me some tips on how to make this code more elegant and secure and maybe compact it so I use only one ...
1
vote
1answer
62 views

Laravel image upload

I'm new to the filesystem from Laravel, but I need an upload script that allows users to upload images to my server. However, i'm concerned about securety, so I thought why not ask for advice, because ...
1
vote
0answers
58 views

PHP OOP front controller pattern

I've started a course about the MVC pattern applied to the web. I want to improve my PHP programming skills so I've decided to write a simple boilerplate for my webapps that use the front controller ...
1
vote
0answers
53 views

Dependency resolver in PHP

I wrote a simple Dependency Resolver in PHP that I'm hoping to get some input on. The main problem that gave me some trouble was when it had to resolve typed arguments ( like type hinting a ...
2
votes
1answer
88 views

Basic PHP user authentication system for an Elm app

I made a simple authentication system with php for an elm webapp that will have a small number (1 - 5) of users able to log in. I am planning to send the users their php session-id at login, and ...
0
votes
1answer
47 views

More readable approach? [closed]

This is a fairly short code snippet, but it made me a little headache, because it is hard to understand, isn't it? ...
2
votes
0answers
48 views

Best approach to parse data from multiple APIs to Entities in PHP

I built an application that extracts and updates data from multiple ecommerces websites. Each eCommerce is either built using platforms/frameworks such as Shopify, Prestashop or WooCommerce. This ...
2
votes
0answers
54 views

Dependency Inversion in constructor

Currently I'm learning OOP and meanwhile I'm trying to keep the SOLID principles. Is it right to inject dependency (GenName - generate file name) on File ...
1
vote
3answers
145 views

PHP script security for new user registration

I would like to ask the experts here if this is secure. If it is not can I get an explanation as to why it would not be secure? I have been reading off and on on sites for this and I have trouble ...
1
vote
1answer
59 views

Check PHP validation code

I have made a form in HTML and the form data should be send via email. For that purpose I have created a PHP script. I did read a lot about the importance of form validation in order to prevent ...
2
votes
2answers
121 views

Simple implementation of LRU caching in PHP

This is my implementation of LRU caching in PHP. It works fine when I tested as. What are the things that I miss or need attention? ...
0
votes
2answers
81 views

Use a comma-separated field in another SQL query

I was just wondering if there was a better way to write this block of code in php. I have a string with values separated by commas. I need to prepare that string to pass it on to the query using IN ...
1
vote
1answer
44 views
2
votes
2answers
338 views

Login System using PHP and PDO Prepared Statement

vir.php ...
4
votes
2answers
50 views

Solve Project Euler #4 in PHP

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest palindrome made from the product of two 3-digit ...
2
votes
2answers
194 views

PHP login/signup validation class

I am working on a blog with PHP, specially in order to practice OOP. Since the blogging system will handle users, i thought that a Validation class would be a good idea in order to not repeat code ...
2
votes
0answers
19 views

How to connect a propery class/object with a collection (its database class)?

I'm struggling with organizing my code regarding 'best practise'. In particular how I link a class with its collection class. I've 2 classes: ...
1
vote
0answers
47 views
1
vote
0answers
20 views

Send single notification script until state change

I could not find the script I was looking for, so I made my own with the knowledge I have at this moment. This is my custom PHP script to send a single notification/SMS/email when a script or site is ...
1
vote
0answers
50 views

Displaying a user profile based on a mock ORM

Overview We are learning PHP OOP and decided to create a simple app with 3 database tables, one a basic users table, the other two containing information about the users' favorite food and favorite ...
2
votes
0answers
648 views

PHP login script using mysqli

Can you guys tell me if my login is secure? Login.php ...
0
votes
1answer
23 views

Results Reporting / Checking with Multiple Results in For Loop

hoping to be schooled a little bit here in showing "no results". This is a working snippet, but I'd like to know if there is a more elegant way to show errors when comparing multiple values in an IF ...
2
votes
1answer
57 views

Showing all records on a webpage

I have a connection with my database to show all my records on a webpage, and I'm not sure if this code is safe: ...
-1
votes
1answer
40 views

Fetch Reattempt and Hold Date count in efficient way

I am using 4 queries to get below 4 values , like this i need to use about 14 queries , Is there any way to reduce queries ? ...
2
votes
1answer
35 views

PHP Factory Pattern : Should I use `create()` or `__invoke()`?

I currently had a colleague reviewing my code and he had a comment on a factory class I created. It's very simple: ...
1
vote
1answer
55 views

PHP validation class for username, email, and password

I'm relatively new to PHP OOP, currently I'm practising how to use it, however I am not really certain I'm building my classes correctly, I think perhaps I'm missing something out but I'm not entirely ...
1
vote
2answers
59 views

Merge both sql queries into one to get the performance

Currently i am using 2 queries - one for reattemptdate & one for holddate.... if we merge both queries & get the results in single query , than will it give better performance? if so how to ...
-1
votes
2answers
69 views

Tracking employee data

We have hundreds of employees and for tracking each employees' data, and I am using this code: ...
8
votes
2answers
235 views

PHP Chess Version 2

For programming practice, I created a chess program in PHP (my most comfortable language). The program reads a FEN (a string with the location of all the pieces on the board) from the URL, generates ...
3
votes
1answer
90 views

PHP class that behaves like enums

I'm relatively new to PHP and one of the things I miss from other languages are enums. After looking around for some samples on how can I have somewhat similar to them, I came up with this ...
3
votes
0answers
26 views

Use a pattern for fields validation

I need to validate the fields of user sent by an API. All works fine but the only one problem is that I don't like the solution is not an OOP solution. In the controller I call the service created by ...
5
votes
1answer
121 views

OOP, one class from multiple database tables

This is an OOP question and probably answerable even if you don’t have PHP knowledge. (A side note – we are learning PHP OOP and decided to create a github to hopefully help others learn this and ...
1
vote
1answer
37 views

Merging and summing multi-dimensional arrays

I've found myself today really struggling with this subject and I'm pretty sure that there must be a better way to do this. First of all my arrays have the same layout, I need to merge them and sum ...
3
votes
1answer
2k views

Send blob image using Ajax/PHP

I have an image cropper that crops the uploaded image, Before sending it to the server using PHP and AJAX. Here is a live fiddle to preview a working cropping example. Here is the code: ...
1
vote
0answers
29 views

Converting an array of users into an array of teams with an array property for listing the users

Jst to clarify, teams and groups are the same thing in this case. $data comes from a database and is an array of objects. Each object contains information about a ...
0
votes
0answers
19 views

Splitting search terms

My problem is, that I want to take a search string, and split it into keywords. I have a function function search(array $keywords) that generates an sql along ...
-1
votes
1answer
42 views

Prevent multiple ifelse statements in php [closed]

I'm trying to figure out a way to make my code more readable and maintainable. While rewriting some ugly spaghetti code, I stumbled across this: ...
0
votes
0answers
31 views

Url routing using php and .htaccess

While I'm learning about the MVC pattern applied to the web using the PHP language, I wrote this code that is supposed to route the requests and instantiate the correct controller and method. I will ...
1
vote
0answers
48 views

Small website with MVC

I'm struggling if this is the correct way to implement an MVC-like pattern for small websites. I have separate controllers and models, my main concern is the view part, did I understand it correctly? ...
0
votes
1answer
37 views

Formatting fractions found in a given string to html fraction

I'm working on a site running woocommerce and wp where the user will add/has added a dimension attribute. The dimension string will take the following format originally: Ht: 30 1⁄2" W: 22 1⁄2" D: ...
-1
votes
1answer
209 views

putting sql-query response directly to foreach-loop?

Is there any reason to not do this? Putting the query directly inside a foreach-statment when the only time the result is going to be used is within that location.. ...
2
votes
4answers
71 views
1
vote
0answers
32 views

PHP CouponGenerator class - preventing concurrent file access

I wrote this php class to generate one time random and unique coupon codes. The Class generates coupon codes, storing it in a json file. My question is regarding the write and get methods of this ...
-3
votes
1answer
41 views

write database connection code in many files

There are many files [ file1.php, file2.php ] in our project & i wrote database connection code in many files instead of single file [ database.php ] , is there any problem with that ? if it is ...
2
votes
1answer
49 views

PHP RSS/XML reader basic class

I write this class to process and output xml/rss feeds. I'm still working on, but any suggestion will be appreciated. As a little trick if the xml file come from an online resource, I've added a ...