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
1
vote
2answers
118 views

How clean is my close_account code?

Hello i'm coding a social site and I need to know how clean this code is. I read other answers people told me from my previous questions like this and used it as guidelines. So now I wanna know if ...
2
votes
1answer
65 views

Controller in Laravel with parsing, creation and relationships

The following code represents the store method of a resource controller. A user can create an training offer on my website and can pass various information like ...
3
votes
2answers
64 views

Getting data from database through Ajax post request

Is the method used below to get data from a database efficient and optimal? The data is in a MySQL database, and in my server I have a PHP file with the following code to return some information: <...
1
vote
1answer
53 views

Google People PHP best practise to get OOP

I need to log in users to web app in Javascript and PHP. So I have Javascript interface which send me accessToken to PHP which stores users data to DB and log user in. But the result code does not ...
3
votes
1answer
108 views

How secure is my login and signup code

I am creating a social network and I've been told a few times a lot of things are outdated and prone to SQL injections so I am going over everything with a very fine comb and checking what's good and ...
3
votes
2answers
350 views

messages.php file security and efficiency

I am creating a social network and I want to know how secure and clean this code is. I had to update it to prepared statements because I was following a tutorial and even though it was made in 2019 it ...
4
votes
2answers
370 views

Very simple login script review

I'm relatively new to PHP and have recently created a small website for friends and family to upload and share photos, protected by a very simple login system. While I'm aware what I'm doing isn't ...
6
votes
4answers
1k views

Regex to validate font names

/((([\w -]+)|("[\w -]+"))( *, *)?)+/ http://refiddle.com/18ql I'm trying to use a PHP regex to sanitize a user input for a list of fonts. The above one seems to ...
1
vote
2answers
96 views

Shorten and optimize php custom code for wordpress page template and use shortcodes

I'm pretty new to php coding, but i know wordpress for a long time. Also experimenting with bootstrap. I created a new Page Template and modified it a bit. What I'm looking for is to optimize this php ...
3
votes
1answer
37 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 ...
2
votes
2answers
79 views

Unnecessary loop in database population

I was looking over some code that I wrote years ago (that is still technically working, albeit on a very quiet production server) and I came across this segment of code. ...
2
votes
2answers
53 views

Is this code is safe or not (img upload) ? [PHP]

I'd like to know if this code is usable, because I'm not sure, thank you. The code is used to upload images to a predefined folder for users. ...
0
votes
1answer
57 views

Recursively displaying json data on website [closed]

I am displaying the data from a json file onto a website, with recursive and iterative tables side by side. i have the iterative code working, but I have no idea on how to make it recursive. Here is ...
3
votes
1answer
83 views

Parse and format var_dump data to become more readable

I have a class that exposes var_dump data in order to get better human readable layout. I have achieved this with a lot of ...
36
votes
7answers
96k views

Setting a default value if a variable is empty

This is the pattern I've been using for "if the variable is empty, set a default value", and for variables like $muffin, it has all seemed well and good. But in ...
1
vote
2answers
156 views

Is this code written safe from attacks?

I have small question. I don't know much about JavaScript (jQuery) or AJAX and I don't know whether I'm doing it safe from XSS Attacks, SQL injection and that stuff. I think the PHP with MySQL would ...
7
votes
2answers
5k views

Generate 6 random numbers for lottery in PHP

This program generates 6 random numbers between 0 and 45 and the numbers cannot be repeated. Can this code be improved? ...
2
votes
1answer
70 views

What is the best way to use serverside validation in PHP PDO?

I have a form on my page. I am using jQuery validation for client-side and PHP for server-side validation. I am using PDO. I don't have any issues with client-side and server-side validation. My form ...
2
votes
1answer
70 views

Using method trait to return something in laravel model

I have question about scope yesterday, and someone gives an answer to don't return anything in scope. Is return something in scope really bad practice? Should I not return anything in the model ...
7
votes
1answer
344 views

Using TinyMCE with responsive file manager PHP and Javascript

I use TinyMCE with responsivefilemanager and I wanted to know that is my code well-written maintainable and readable, Sorry If this sounds like a stupid and basic question because this is such a basic ...
3
votes
2answers
62 views

PHP Status class : pattern or anti-pattern

I want to abstract some code which does a bunch of checks and returns a boolean - since I am using the business logic in several places. But I also want to get back the reason why, if it was returned ...
1
vote
0answers
41 views

Secure/Bulletproof Image Upload Using PHP

Here is my code that check and upload an image to my website. Is this code really secure against uploading of malicious codes ? Anything i have to add to this code to make it more secure?, I have ...
1
vote
1answer
54 views

Handling multiple try-catches in a for loop

Good day! I would like to know if this is possible to be refactored into a cleaner code. The reason I'm doing it like this is to catch the column that the error appeared on and then potentially output ...
5
votes
2answers
254 views

SOLID principles breaking in interview task (file parser)

Originally asked on Stack Overflow I recently had an interview where interviewers asked me to Rewrite following code with SOLID principles. Add a new file handler (...
7
votes
2answers
597 views

PHP MySQLi Connection File

I have recently adjusted the way I create my mysqli connections. Initially I would include the connection file and use ...
2
votes
1answer
96 views

Does this PDO process look protected from SQL injection?

Does this process look protected from SQL injection attacks? Is there something I could possibly change to make it more protected? ...
3
votes
2answers
110 views

Checking if naughts or crosses win in Tic Tac Toe

I am working on a coding challenge for Tic Tac Toe. I am calculating the results and inserting them into the database. However I have a long and messy if statement, which checks if the array's values ...
5
votes
1answer
217 views

SQL QueryBuilder

I've made a simple querybuilder for my job, but I'm kind of insecure about starting to use it because I'm afraid of errors happening when I start using it. I've done some tests with ...
2
votes
1answer
1k views

Composing an HTML email body in PHP swiftmailer

The following code is what I'm using to send a password reset email. The specific part I'm referring to is how I'm setting $message. Would there be a cleaner way to ...
0
votes
0answers
51 views

This service submits an application to a 3rd party API and returns a URL to redirect to. It does too many things. How can I refactor it?

A user applies for a lease for a car and on approval, can submit the car they want to buy. The service is consumed like so in the controller one layer above: ...
1
vote
1answer
57 views

Reduce database touches for one to many data pull

I have the following function which works properly and grabs all of the rows from a specific table, then loops through each row to add data related to it as a subarray. ...
5
votes
1answer
93 views

getRandom() - Randomize array and get result

I've written a function that allows you to pass an array of values, which is then shuffled and returned based on a parameter $preserveArray. This is the code: <...
-3
votes
3answers
330 views

Registration code [closed]

I was following a tutorial for a social network. I want to know how secure this code is because I plan on launching it to the public web. ...
0
votes
1answer
110 views

REST API PHP find by id

Description: The web server retrieves data from file database (pdf, doc, 3d file, zip and rar) and financial program such as inventory, price, indexes, order status and so on. I'm doing REST API PHP ...
2
votes
1answer
42 views

Using dynamic methods to build SQL queries in CodeIgniter

I'm using this class as Modal in my CodeIgniter project, as I'm newbie in CI, I wanna know if this has some issues, I'm using this modal for all queries, like I call this with parameters and it ...
-2
votes
1answer
51 views

Laravel Page Controller [closed]

Aim: To make pages located in site.com/page-1, site.com/page-2. Those pages are pretty much static so I won't use database. First, I've created the PageController. ...
1
vote
1answer
99 views

How secure is my registration code

Hello I am a beginner in PHP and I need some opinions. How secure is my registration code ? If I launched this on the web would you feel safe signing up with personal info ? ...
2
votes
2answers
19k views

Merging two multidimensional associative arrays

I just wrote a function that will loop through two multidimensional associative arrays and merge them together based on the key names and their values. While I'm satisfied that this function works, I ...
3
votes
1answer
38 views

PHP get minDateTime from array

I've written a function to get the smallest date from an date[ ] and check for null. If null == infinity ...
1
vote
2answers
147 views

PHP - How can I refactor this store function (which handles different database operation for user types) in order to reduce duplication?

I'm simply using Slim PHP MVC framework in my API project. PDO::FETCH_ASSOC is used in the database calls. So no data objects. The router handles requests and pass to the controller. controller calls ...
1
vote
1answer
66 views
3
votes
1answer
61 views

More protection needed? PHP secure

I am busy on a protected page with login and I want know if there is more protection needed. It is a very simple system without database etc... authentication.php ...
3
votes
1answer
112 views

New comments after a user's last comment

Edit: I've added everything I can... I have the following query, which gets the last comment from the user in a given topic, then I check in the while loop if there are newer comments. My problem is, ...
5
votes
3answers
3k views

A demonstrational example of a Data mapper ORM

I want to create an educational example of a Data mapper type ORM. You know, it is always interesting to know how the stuff works, but when you take a fully functional software package, it's just ...
2
votes
1answer
72 views

PHP OOP - Login & DB adding/removing script

I've created something that I called System, where you can login, create the files and delete the files. It's not any kind of big project, but it's the biggest project I made in PHP OOP so far. It ...
2
votes
1answer
60 views

Create user in users table and insert data into second table with one form in Laravel Relationships

I'm trying to create a user while adding data to a second table via one form: users table: ...
1
vote
1answer
85 views

Is this an good OOP Design in MVC PHP for getting User Details?

I was given a API project by my co-worker to work on half created a system in slim PHP. The project consists of the Models and controllers. When the route is called it calls the Controller with the ...
5
votes
1answer
94 views

Defining routes and controllers relationship for given pages

I'm building a CMS app with the help of a custom framework. The back-office is composed of the following pages: post list page list user list post edit page edit user edit Actually, my routes are ...
4
votes
3answers
49 views

PHP/HTML Table and Modal Forms that display information

Its been a while since I have written PHP or HTML for a project, so I could use some thoughts on improving the code below. I wrote all of this going off of old knowledge, so I imagine its really ...
2
votes
2answers
65 views

Continually refresh game data using AJAX

I've been working with JavaScript and AJAX a lot in the past, and now I'm moving towards the backend and working with databases more. I want to update my game data in as close to real time as possible ...

1 2 3
4
5
84