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
2
votes
0answers
72 views

implementation of a mvc url router with low coupling and solid principles

i'm building an url router and i want to improve it to respect SOLID principles, i want suggestions of how can i make it less coupled. here's my current code: Router.php ...
4
votes
3answers
163 views

PHP display Error Wanings Yellow @ bottom of Page with PHP_EOL

I initially started searching for a PHP script which would output PHP errors, to the JavaScript console. As the Default behaviour is just to spit them out anywhere and displace everything else. ...
0
votes
0answers
37 views

Report writing, do the formatting work on database or non-database language?

When report writing, sometimes getting the data you need can be quite straightforward in SQL, but getting the data in the exact format you'll need it in for the specific report can be quite tricky. It'...
2
votes
0answers
76 views

CSRF script in Php

A short script to make a CSRF token to be used in my html elements such as inputs, file-uploads, scripts, iframes & svgs. ...
5
votes
2answers
111 views

A simple but useful error handler

I am trying to make a very simple error handler that would catch and handle all kinds of errors in both development and production environments. The idea is to keep it as simple as possible yet useful ...
3
votes
1answer
422 views

Add post to favorite in PDO and mysql

After lot of research and couple of questions in https://stackoverflow.com/ i managed to create Favorite System in PDO mysql as ...
2
votes
1answer
49 views

Extract users and privileges from MariaDB and MySQL

This was born out of a need to create database users on a new server to allow views to be created correctly when restoring databases. This is designed to be run from a command line NOT via a web ...
2
votes
3answers
171 views

Conditionally truncating a filename to a max length without damaging the file extension

Yes, I'm bad at conditionals. I don't use them so much and I feel a bit lost with them. How would you (if possible) refactor or change this little piece of code? Second improved version: ...
3
votes
2answers
59 views

PHP - Deliberate loose == check and assigning to if statement

...
-4
votes
3answers
138 views

What's the best way to tidy up a PHP array with both indexed entries and associative entries? [closed]

I have two closely related questions: 1) I have a mixed PHP array. Not mixed in that it contains strings, floats, booleans etc. but mixed in that it is a hybrid indexed / associative array. Most of ...
8
votes
1answer
16k views

Phone number extraction with regular expressions

I've been working on my own phone number extraction snippet of Regex code and I'd appreciate your feedback on it. I've tried to make it match as many different types of numbers as I knew existed in ...
1
vote
1answer
419 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. ...
0
votes
2answers
3k views

Protect against XSS with .htaccess file

My .htaccess redirects everything to my index.php, but I wonder if it's vulnerable to XSS attacks. Am I safe? .htaccess file ...
2
votes
1answer
50 views

Display content if form field is filled - Do not display if field is empty

I am using the following code within the footer of my test site. I am using WordPress and Advanced Custom Fields The intention is: To display the HTML container ...
1
vote
1answer
39 views

Symfony rest endpoint for get a number products of one user

I want to improve quality of this symfony rest endpoint (solid principle, Kiss, best practice...) Can you review my code please? Symfony controllController function that return json list of product <...
0
votes
1answer
69 views

Fetch and add data to MySql [closed]

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 ...
2
votes
1answer
78 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 ...
0
votes
2answers
78 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
73 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
votes
2answers
81 views

Constructing URLs [closed]

I'm a beginner in PHP. Here my script ...
1
vote
1answer
109 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 ...
3
votes
2answers
127 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: ...
1
vote
1answer
49 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 ...
4
votes
1answer
73 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, ...
1
vote
0answers
50 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
1answer
106 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 ...
1
vote
0answers
83 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 ...
0
votes
1answer
69 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
60 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:...
2
votes
2answers
253 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/...
5
votes
1answer
177 views

My text comparison algorithm works very slow

I tried to create an algorithm (Translation Memory) that finds similarities between texts and try to predict the closest possible translation of the text, but there is a big problem with the working ...
1
vote
3answers
228 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
41 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
41 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 ...
0
votes
3answers
66 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? ...
3
votes
1answer
103 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
59 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
1answer
56 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
531 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 ...
5
votes
1answer
101 views

its doing multiple nested for loop. How to reduce to 1?

I am writing one logic to iterate numbers first and then additional logic to putting them into particular subset of array. What does this code do: Code accept first ...
7
votes
2answers
2k views

OOP simple contact form

Here is my Code. But I feel that my code isn't really that much object oriented. There is a small piece of "styling" in it as well, the "message error" thing at the end. Should that be in my class ...
4
votes
2answers
138 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
72 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 ...
5
votes
5answers
3k views

Transposing a PHP associative array

The purpose of this code is to change each column to a row, and assign keys to each value for the new array according to the old array. I would like to know if there're other ways to optimize it. <...
4
votes
1answer
108 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 ...
1
vote
2answers
735 views

Security of a custom table in JsGrid

This is my old topic,it is about show table's records by JavaScript using a JsGrid file and can edit or delete by ajax. This is my topic How can I load rows in JsGrid table that got from php file?, ...
3
votes
2answers
66 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 ...
2
votes
0answers
175 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 ...
1
vote
0answers
41 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 ...

1
5 6
7
8 9
85