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
20 views

I need a better way to add css per each page on wordpress

I just started to use Wordpress to start building a website, but as I need to use the get_header() function to retrieve the ...
-4
votes
0answers
24 views

How i can perform this function which parse a string [closed]

i have wrote this function: ...
3
votes
0answers
21 views

Add pivot data from the same pivot model

My project has thee models Cart, Order and Product Cart ...
0
votes
1answer
61 views

Learning factory design pattern [closed]

I'm making the very common example of Factory design pattern which creates a factory of cars and return an instance of a car. I found a example here https://refactoring.guru/design-patterns/factory-...
0
votes
0answers
33 views

Wordpress Ajax Custom Query - High CPU LOAD

I'm developing a fully ajax community WP theme that comes with alot of custom quaries. Everything is fine, there is no bug but recently but I had a few client that have a huge database and my theme ...
5
votes
2answers
125 views

Queries to get unpaid and unpaid invoices

Here is my code: ...
4
votes
3answers
153 views

PHP comment system

Basics I created a simple comment-system. My goal was it to create a system that can easily be used on everyone's server without having to install a load of programs. I also tried to create it as ...
3
votes
1answer
144 views

Sanitizing user form input in php

Security threats in mind: SQL Injections!!! --- Solutions: Prepared Statements (PDO) and including $bpdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); in ...
3
votes
0answers
47 views

Mysql PDO Wrapper that throws Unique Constraint Exception

The main reasoning behind this PDO wrapper, is that I find myself using unique constraints quite frequently in my designs, and I have ...
4
votes
2answers
68 views

PHP Email List Sign Up

See my original post: here. I have one html page and four php files that allow users to sign up for an email list. One of the php scripts is a cronjob that deletes unverified rows older than 24 hours, ...
3
votes
3answers
129 views

Email Validation in PHP

Is this script sufficient enough to validate user email input? ...
2
votes
1answer
34 views

Route Improvement in Laravel 8

I have below route. I am using Laravel 8. ...
0
votes
1answer
40 views

How do a research in all xml file for gived id value?

I have a xml file so formed: ...
2
votes
1answer
31 views

Modify parameter data before creating an instance of a class in PHP

I have an abstract Badge class, every class extending this class should always correctly set the incoming name (string) and achievedAt (date) fields. There might be other classes that extend the Badge ...
6
votes
1answer
81 views

binary data shell echo generator

edit: here is a cleaned-up version incorporating most (but not all) feedback, thanks guys; https://gist.github.com/divinity76/79efd7b8c0d7849b956cd194659c98e5 I need to... generate a linux shell ...
-4
votes
2answers
68 views

Is this a good approach to replace mysqli_num_rows? [closed]

Is this a good approach to replace mysqli_num_rows? $db is a PDO instance. .. ...
2
votes
1answer
37 views

Get all routes that start with rt_

The code reads all my routes and return to my JQUERY AJAX the names of the routes without duplicates and just those that have "rt_" prefix. ...
2
votes
2answers
104 views

Secure file upload for PDF only

I am trying to create a secure file upload using PHP 7+ where I only allow PDF files. I found a lot of posts on this topic on different websites but couldn't find a complete solution that ensures that ...
3
votes
1answer
418 views

Very simple encryption API

I need an encryption system with a super simple API. I'd prefer something as simple as the following. The output should also be browser-friendly and ideally url-friendly. ...
1
vote
1answer
46 views

Improvements on Laravel's base Model and FormRequest

Introduction I've improved, IMO, Laravel's base Model and FormRequest. It's working as expected. But, before actually implementing this any further in my application, i want to have my classes checked ...
3
votes
2answers
173 views

Contact form with spam-prevention - follow-up

Background The basics of this project are already covered here. I received the suggestions to: not create the exercise with JavaScript. use pictures instead of plaintext. I tried to implement the ...
1
vote
1answer
45 views

Class dedicated to transforming API response to the data I need?

I have the following code (in php) that calls the open weather api with my credentials, and returns data for me. Know I'm returning some data I pick from that response, I'm wondering if it's good ...
1
vote
0answers
32 views

PHP Laravel Order generation Custom Class Refactor

Here is a custom class code I use to handle different types of orders in Laravel. This question includes the code regarding Order Type A. I want to know whether I can simplify the code more. I have ...
6
votes
2answers
106 views

PHP Mandelbrot Set Generator

I need to get familiar with web programming, so I decided to write up a fairly simple PHP page that accepts GET requests and serves back an image of the Mandelbrot set... as a table of colored cells. ...
2
votes
0answers
44 views

API Client and usage implementation

I'm really bothered with my approach in this, as I'd like to use the client in multiple projects. The client is just extending Guzzle and I'm using a factory method to initialize the client with the ...
2
votes
0answers
44 views

A UserService method that calls the UserRepository a few times

I'm trying to implement some domain driven design architecture, such as a repository to talk to the database, and a service that talks to the repository. I have an action where I want to see if a User ...
3
votes
1answer
100 views

Contact form with spam-prevention

Idea After a handfull of small javascript-projects, I also wanted to work a bit with php now. I decided to create a simple contact-form. Of course, I wanted it to be as spam-save as possible, so I ...
1
vote
2answers
63 views

Dynamic Accordion in WordPress

I used the Bootstrap v4.0.0 accordion to display my business services. Further, I created a custom post type "service" for my services (Each service is a post). To display my services ...
4
votes
1answer
23 views

Creating formatted “[time] [unit] ago” messages from a seconds value

I have this function which calculates how many seconds, mins, hours etc ago a specific time string was. However, the way I have done it consists of a massive if statement block, and it goes through ...
0
votes
2answers
57 views

Set id in constructor, or generate it when asked for?

I'm using PHP, I have a class that generates an id based on the calling class, so the id of the class won't change after it has been initialised, now I'm wondering which of my two methods is ...
2
votes
1answer
45 views

I want to most efficiently use array values and variables in a WordPress template while abiding by PHP/WordPress best practices and standards

Is it better to validate and put an array value into a variable at the top of a file or to check the array value directly right before output in the file? I work at a WordPress shop and we have a ...
1
vote
2answers
99 views

Displaying filtered user data using Ajax and PHP

I want to get my code cleaner and more efficient. This code gets variables form a PHP file and filters it to show the selected user name, all available usergroups on a list box and the groups he is ...
2
votes
2answers
108 views

Structuring code logic for events on laravel controller

The code below will store a base64 image on another website and create an event to display the image on a Vue page in real time. It works fine and all. My question is, is this a good way of doing it ...
0
votes
0answers
11 views

Structuring code logic for events on laravel controller [duplicate]

The code below will store a base64 image on another website and create an event to display the image on a vue page in real time. It works fine and all. My question is, is this a good way of doing it ...
4
votes
1answer
56 views

Checking for duplicate email in api response data

I am working on a small internal app that works along an external API for provisioning purpose. The code essentially is comprised of a series of forms where the user inputs data, this data is then ...
2
votes
1answer
51 views

Secure way of uploading php images and GIF

I am creating a social network and I want to know if this is a secure way of uploading pics/gifs and videos. ...
1
vote
0answers
28 views

Using exceptions inside CakePHP controller actions to simplify flow

I'm looking to simplify controller logic where multiple validation steps will either result in redirecting the browser or re-rendering the current view. Overall I'm looking to: Avoid excessive nested ...
3
votes
2answers
89 views

“Guess a random letter” game with command line interface

The code below if launched on the command line is a simple guessing game. A random character 'a', 'b' or 'c' is chosen, and the user is prompted until they guess correctly. It's arguable that invalid ...
3
votes
1answer
51 views

Secure upload script

I am creating a social network that let's users upload a profile picture. I just want to know if this is a secure way of doing it. Thanks. ...
5
votes
1answer
66 views

Refactoring a class that counts xml dom nodes and caches the result

I saw this entertaining talk by: Bob Martin on clean code and started refactoring a relatively simple class today. I am, by no means, an expert on coding and still learning a lot every day, so I want ...
3
votes
1answer
70 views

Securely upload multiple image files with PHP

I am working on script to a upload image files Securely. can anyone please review my code and suggest improvements on security. ...
2
votes
1answer
113 views

Request mixed with JSON strings and array fields, in custom function for reduction need Simplify/Refactory

Client From a POST request I get a mixed structure of an array and JSON. To handle multiple type of elements I am using var_dump to get the passes. For ...
8
votes
3answers
1k views

How secure is my PHP registration script?

I coded a registration form and was wondering if anyone could give me feedback on whether I'm lacking any major security mechanisms. I've done loads of reading around the topic and feel it should be ...
6
votes
1answer
73 views

Generic memoize utility function for pure functions

Given the following generic memoize utility for pure functions with type hints: ...
34
votes
6answers
5k views

Parser written in PHP is 5.6x faster than the same C++ program in a similar test (g++ 4.8.5)

I'm absolutely dumbfounded by this. I was trying to demonstrate to myself how much faster C++ is than even modern PHP. I ran a simple CSV parsing program in both that have the same output. The CSV ...
4
votes
4answers
62 views

Create unique string from id to build an link shortening system

I want to build my own link shortening system. Therefore I need a way to create unique strings from the record ids stored in my database table. So far I came up with this. I wonder if you now a faster ...
2
votes
1answer
61 views

Login system in PHP using AJAX

I am beginning the cycle of creating my role based access control into my framework. I now want to log the user into my application and my _user table looks like this: ...
4
votes
1answer
90 views

Rock, Paper, Scissor - Game

This is my first ever created game. I been slowly but continuously learning PHP for the past 2 months and just last night I thought that I might be able to create a simple and very basic game. Due to ...
5
votes
2answers
87 views

Implementing Laravel old data in Vuejs

Users input their pin-code which is checked against the database and returned with the locality, district and state associated with that pin-code. Multiple localities may be returned so the options ...
5
votes
1answer
63 views

Wordpress single post content class customization with if-else function

I have the following code, which displays the content for my custom page template "landingpage.php" and for single posts. The site is based on Bootstrap 4. ...

1
2 3 4 5
83