Questions tagged [php]

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

Filter by
Sorted by
Tagged with
0
votes
0answers
7 views

Page Coming Soon Subscribe for Notifications

I've just downloaded a script from PhpJabbers, which Uses Php & Javascript to Display a Page coming soon animated countdown. PhpJabbers - countdown Script: Coming-soon.html ...
-3
votes
0answers
15 views

My code is trying to pull data and present in a web page from 2 databases using php/pg_connect and postgresql [closed]

My code is trying to connect and use 2 different postgresql dbs (postgres and postgres1) on the same computer (localhost) and same php file. pg_connect is working for the default postgres db - no ...
-1
votes
0answers
21 views

Security PHP, MySQL and Unity [closed]

I'm developing a game using a database for players and purchase elements (I have not implemented this part yet) and I want to know if the way I'm doing it is safe for database and game and the ...
-1
votes
0answers
25 views

Mixing MVC into flat PHP [closed]

I've read up on using MVC in PHP, but I'm still struggling to find an example that I can understand. How would I adapt, say, the following code using the MVC pattern?: ...
0
votes
1answer
45 views

Fetch and add data to MySql

Here is my very first code which fetch data and add it to MySql. Please review my code and let me know if I'm on the right path. Is there anything I can improve? postsData class = fetch and add data ...
0
votes
2answers
61 views

Check if ID exist or not

Here I have a class where I'm checking if model_id exists in the table models_web_tbl. Everything works like a charm but I just ...
1
vote
1answer
48 views

PHP Shopping Website with Cart - Returning a HTML String

Edit If there is a better way to ask this question to avoid negative votes, please let me know. I have looked into https://codereview.stackexchange.com/help/how-to-ask How would I implement a class ...
1
vote
1answer
83 views

PHP MySQLi database object

I've been learning more about PHP Objects and Classes, and my immediate reaction was to create a Database Object for handling the MySQLi Connection, Statements and Results. Its not meant to be an ...
-1
votes
2answers
71 views

Constructing URLs [closed]

I'm a beginner in PHP. Here my script ...
1
vote
1answer
35 views

DI container with auto-wiring feature

So I decided to write my own DI container for educational purposes and would like some feedback on how I can improve the quality of my code. I'm not sure about the documentation as most of my ...
-1
votes
0answers
32 views

anything to replace with preg_match?speed up and refactor the code

I have this code to validate addresses from input. This a sample address: 2 جنت آباد جنوبی- پایین میدان چهارباغ-ساختمان سبز- پلاک 148- واحد In this case my ...
4
votes
1answer
39 views

Extending PHP REST API Controller design to complex routes

I am putting together a php Rest API service that uses Controller and Command pattern to handle requests. Firstly, in Apache config I redirect all requests to a single end point, ...
2
votes
1answer
46 views

Refactor PHP | Laravel Code, Optimisation needed to make code clean

I have made some notification preferences in which there are 4 major preferences SMS PUSH FAX EMAIL And then there are some specific templates such as ...
1
vote
0answers
40 views

A library for creating customized PHP interpreter

The basic idea came from the php-embed SAPI module. I just need a simple customization, but it has too heavy depedencies than I want to do. To create a code ...
2
votes
2answers
76 views

Do I need still to be concerned about favouring str_replace over preg_replace in PHP 7?

I have the following piece of code: ...
2
votes
1answer
97 views

Enhance and Shrink Preg_match lines [closed]

I made a preg_match to get my results and it works fine but I think it can be done with simple lines instead of repeating the code ...
3
votes
2answers
112 views

Is the code prone to SQL injection or to any other kind of threat

I am very new to PHP coding, hence just wanted to know if my coding is prone to any SQL injection attack or any other kind of threat. Below is the code for adding client to the database: ...
0
votes
1answer
62 views

The CRUD interface I created for my new app. Creates, updates, deletes, reads and lists [closed]

Here is the Interface I am using in my working app. ...
-1
votes
1answer
56 views

Storing user and shipping addresses

So on my checkout page when I push final checkout I want to store my users address and shipping address into a database. I am wondering if this could be shorter. Currently, users have multiple options:...
1
vote
0answers
71 views

Throttling - brute force attacks (security php)

After a few weeks of searching and learning "php secure", I created a class Failedlogins. record_failed_login -> recording the logins, if doesn't find the record, he create the new one. If he does ...
1
vote
3answers
52 views

Laravel controller Single Responsibility principle

I have a method in Laravel controller. How can I improve this code? How can I implement single responsibilty here or maybe there are some other tips I can use in this code? I know that controller ...
0
votes
1answer
38 views

Get 3 counts from a table [closed]

I am trying to show the following results to the user All:8000 enabled:8000 disabled:0 What can I do to improve this code? ...
0
votes
1answer
40 views

Refactor the method which is the sequence of the similarly looking steps to (or towards) the design patterm(s) [closed]

I need some help to understand if the code below could be refactored to something less straightforward, less repetitive and more towards any appropriate pattern. What I feel uncomfortable with in ...
2
votes
2answers
88 views

BBC Code Dice Roller in PHP

I do not program PHP too often. I wanted to write a dice-roller bbc code parser for my forums. What do you see that can be improved? You can see the code running live here: https://joshuad.net/misc/...
3
votes
1answer
54 views

Laravel - Repetitive code in store and update functions

I am working on a system and I can see myself using repetitive code that does not look right. I want to clean up my code but I don't really know many ways to do so. I have 2 methods (store and update)....
3
votes
1answer
50 views

User Class and MySQL Connection Handler

Mainly used Stack Overflow, so first time over here for a code review. I am trying to make some enhancements to a legacy application. I have some minor experience using Laravel, but this application ...
0
votes
3answers
64 views

Assign key name based on row while loop

Is it possible to automate the array inside the while loop and automatically assign the key name based on the row so I don't have to spell out each one? ...
0
votes
1answer
50 views

Is my code for a forum page vulnerable for sql injections?

This is the backend code for the page where you upload a post. I have already tried to do a sql attack on this page, but it didn't work. ...
0
votes
1answer
426 views

User class implemented with PHP 7.4 using Active Record

I need some constructive feedback for the working OOPs project which I created to introduce to Object Oriented Programming in a class. Hence is for beginners, I did ...
4
votes
2answers
57 views

Map associative array to another array php

I have an associative array of the states of some country, and the states names are the keys: ...
1
vote
1answer
51 views

Custom PHP MySQL database queries function - Suggestions for improvement or additions

For my website needs I made a custom procedural MySQL function in PHP which can INSERT, UPDATE, SELECT or DELETE data from database. I would like a review and any suggestions for improvement or ...
0
votes
0answers
20 views

Simple function converting image to webp - Any optimisations recommended?

I have built the following function to take an image path, convert the path to a .webp file, check if the .webp file already exists, then return it, or else create it. Can anyone see any ...
1
vote
0answers
42 views

Laravel 5.8: prevent duplicated code

Sometimes we have this code blocks that is repeated in the same controller again and again, I reviewed the Repository Pattern but I didn't understand how to deal with some kind of these duplication. ...
4
votes
1answer
92 views

Laravel controller method that searches jobs using variable criteria

I have custom code where I check request params for existing and make query to database with model ...
0
votes
0answers
35 views

Export an Excel file using Laravel-Excel

I have this piece of code that is used to export an Excel file using Laravel-Excel. But I have doubts about it for the long run. Can the server handle it if there are a hundred requests? ...
3
votes
2answers
57 views

Organise method flow

I have something like a shop. It is limited to a checkout page, which will send an email. Nothing big, but a nice thing to learn more OOP. Almost every time I develop new classes I am wondering how ...
1
vote
0answers
40 views

InnoDB Row Locking with Transaction & Helper [closed]

I have recently started to work with InnoDB as well trying to use "helper" functions. The code below seems to work correctly however I am not sure if the true ...
2
votes
0answers
92 views

PHP Secure Remember Me for Login using PHP Session and Cookies with referer url

I have followed a mysqli tutorial to create a login with cookies and session with remember me authentication in pdo. in tutorial class had a new db_connection, I ...
3
votes
1answer
63 views

(php , mysql) Contact us form mysql injection

I made this anti SQL Injection, I tested if I can still send queries, and it is looks good. could you tell me if you see any problem I missed, before I launch this to the internet? (this is contact us ...
4
votes
1answer
81 views

strategy pattern, good practices on how to switch between classes

i'm using an external API that posts products and orders into a marketplace, and it provides a class that in each request i have to specify an endpoint, ...
2
votes
0answers
28 views

More testable record insertion code

I don't have much experience with testing but I'm trying to make it part of my routine to develop better software. The class below is a service class in Laravel. It needs to save a record on the ...
2
votes
1answer
53 views

Sum of array of strings to bytes

I'm trying to generate the sum of a collection of strings by calcuating each character's byte value into a sum: ...
3
votes
1answer
45 views

PHP code structure for string manipulation tasks

I need to perform a bunch of string manipulation tasks on an original string, then output the final string. Best I could think of is extracting some functionality into functions. Any better way to ...
1
vote
1answer
64 views

Generating a table of contents with collapsible subsections, PhP or JQuery?

The code below generates tables of contents with collapsible subsections from HTML headers. I have done it for a WordPress website, so I can use either PHP or JQuery/JavaScript. I have used PHP to ...
4
votes
0answers
39 views

PHP MySQLi Connection File

I have recently adjusted the way I make create my mysqli connections. Initially I would include the connection file and use <...
2
votes
0answers
15 views

Performance of WordPress Plugin is currently very bad and needs to be improved

I have written the following Plugin, which adds fields to the Media/Attachment Entries and returns all information in one Shortcode. This solution works, however, is pretty slow the more entries ...
3
votes
1answer
34 views

PHP Ngrams comparing two arrays

Is there some more efficient way to calculate and extract that array that is greater than or equal to 0.8. I had to use two foreach to do it, which is not very performant. The idea is to find the ...
2
votes
0answers
43 views

Immutable-Object-like Structure in PHP

I made a closure-based PHP structure that behaves mostly like a classical object. To change the object's state, one must derive a new copy by passing the altered state to the ...
0
votes
0answers
28 views

Using localized pluralization in Laravel mailable

I am using blade templates from Laravel inside a Mailable class. The text of the mail is dynamic and depends on the number of users. The number of users is fixed per mail, but I need to translate each ...
3
votes
2answers
64 views

Using PHP goto Labels for code folding

I've been using PHP labels in my Controllers for code folding. PHP labels are actually used with goto statements. But I'm using labels only because it's so much ...

1 2 3 4 5 81