PHP is a widely-used, general-purpose scripting language that is especially suited for web development.
0
votes
0answers
7 views
How to properly fetch object and list of objects if query have joins
i have this function that returns me list of users with their roles and groups, as you can see this is how i fetch and create list of objects, i'm wondering is this good approach and is there ...
4
votes
3answers
30 views
Setting the page number with a default
Consider this code segment:
if (empty($_GET)) {
$page_number = 1;
} else {
$page_number = $_GET["page_number"];
}
I wonder if there is a better, more ...
3
votes
1answer
32 views
Outsource function from class
I've outsourced the setup functions from my class to another file, I outsourced initDriver from the class PortalController to ...
1
vote
2answers
38 views
Round fractional seconds of MySQL Time
I've written a method to round a MySQL Time to two decimal places. Here's some examples:
...
-4
votes
1answer
18 views
Looking for pattern or Structure, for Object with sub-objects that reference the parent [on hold]
I am trying to work out how to structure my classes to break one big settings class with long methods, so that each method can be its own class.
So I have a parent with the overall settings and each ...
0
votes
1answer
47 views
PHP Singletons Wrapper (Dynamic Admin) [on hold]
I need to create an administration board that allows devs to create or modify options and display them in a panel. The Admin needs to be the same on each call made to it.
I've chosen to make all ...
-1
votes
1answer
41 views
Improving User Class structure/design [closed]
I recently got into OOP, because I'm working on a big project and want to make sure my code is easy to maintain & scalable.
My question is - how could I go about properly structuring the ...
3
votes
1answer
54 views
Show and paginate only child categories with wordpress query
I'm using this piece of code to show and paginate only child categories but this is horribly slow (49 queries in 9,799 seconds.).
Where did I make mistakes and how ...
1
vote
1answer
25 views
Replace template based on placeholder values
I have wrote a PHP template code to replace placeholders based on the value provided within the placeholder. For example the content may have placeholders like
...
5
votes
0answers
45 views
Checking game objects versus each other to determine targets, comparing arrays
I have a flight class that looks like this:
...
1
vote
1answer
60 views
Reduce repetition when sharing data across an application
I have a CodeIgniter 3 application. There is some data every page across the application needs to have.
This is the system I currently have.
Create a model function that will get the data I need
<...
1
vote
1answer
34 views
Authorization checks for editing attributes of a task
Model:
class Task extends Model {
}
with fields
protected $fillable = ['message', 'due_time', 'status'];
I've added ...
5
votes
2answers
74 views
3
votes
2answers
106 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 ...
5
votes
1answer
84 views
PHP download counter script with htaccess
I'd like to show you my script and would like to hear your security hints. Maybe the code is also useful to someone else.
What I want to archive:
Someone clicks on a link on my web page
a htaccess ...
-2
votes
1answer
36 views
Should I enforce the 'one instruction per line' rule? [closed]
I am reviewing the following code:
$creationDate = $order->getOrderCreationDate();
$dir = Mage::helper('moduleX/order')->getPathOfTheDay($creationDate);
...
1
vote
1answer
61 views
Send messages to multiple passed recipients or a default recipient
I have a function that accepts false as a default value but can be passed an array.
...
3
votes
3answers
125 views
Function to check if a date is correct
I have a method that checks if a date is correct or not, which returns a boolean if it is or not. In the method, I first check the format, then the date by using the function ...
0
votes
0answers
31 views
Getting comments and replies into a database
I created an example (for me) of how I must get the comments and replies into the database.
Here is the result for example:
...
4
votes
1answer
131 views
Laravel - Revised Authentication Controller
I'm developing a Social Engineering Awareness Training Application. This is the focus of my thesis for my undergraduate degree. This will be a multi-part review request, however, if you want to see ...
3
votes
2answers
99 views
Damage function for a game
For my game I have a function that resolves FireOrders between units. The function is being called a ton of times and it's only being extended from various classes.
...
2
votes
1answer
47 views
What is the best way to code an array that has same keys as another array's values
I have two arrays as follows:
...
4
votes
1answer
85 views
Email Controller
I'm developing a Social Engineering Awareness Training Application. This is the focus of my thesis for my undergraduate degree. This will be a multi-part review request, however, if you want to see ...
5
votes
1answer
72 views
Laravel - Authentication Controller
I'm developing a Social Engineering Awareness Training Application. This is the focus of my thesis for my undergraduate degree. This will be a multi-part review request, however, if you want to see ...
3
votes
0answers
45 views
Page auto refresh on update
I've written a simple script to refresh the page when the page has been updated.
How it works:
The Javascript polls a PHP script and sends it the current URL and the current version, the PHP script ...
1
vote
1answer
70 views
Getting a connection to the database and executing statements
I've got two classes for getting a connection to the database and executing things, Class 'A' was made by me and Class 'B' was made by a colleague, we were wondering which one is better for use (...
5
votes
1answer
81 views
Building a model-view-controller application in PHP
I've seen at least two recent PHP questions that would do well from a Model-View-Controller ('MVC' from here-on-out in this question) setup. Now, me, being the horrible person I am, I wanted to build ...
0
votes
1answer
44 views
Is there a better flow for returning the response?
So I have the getSessionNamespace method in the below class in which I am trying to return different scenarios but one json response. So my solution is to store the ...
2
votes
2answers
77 views
CRUD operations for a patient database
My code performs CRUD operations in PHP using OOP and dynamic queries. How can I completely separate HTML tables from this code?
Db.php
...
2
votes
1answer
29 views
graphql PHP delete
I have tried to make delete functionality with graphQL and php. I am using this library:
https://github.com/webonyx/graphql-php
It has examples, but it does not have mutations example. I tried to ...
2
votes
0answers
53 views
Simple OO MVC PHP framework
I've been working on a simple MVC PHP framework on and off for the last nearly 12 months, so I thought that I'd put it out there.
The project began as a way to mentor and teach a junior (or a more ...
3
votes
3answers
102 views
An online store, being converted from procedural to OOP
I just start to learn OOP, and it's far more interesting than procedural style.
I have a complete working online store written in procedural style. After realizing that my code is becoming very huge ...
2
votes
0answers
31 views
Custom WordPress Menu
I have recently delved into the world of OOP programming with PHP. I wanted to add my own custom menu to the Wordpress Admin area, and came across a tutorial, which I have followed, and the code is ...
1
vote
1answer
40 views
Making a “remember login” function
I'm trying to make a safe "remember me / auto login" function on my site and as I'm just a hobby programmer I would like someone professional to take a look at my code this far. This site will ...
0
votes
1answer
40 views
PHP Single Type Collection
I have implemented a collection class that stores a single type of value.
At the moment it is immutable.
...
1
vote
1answer
46 views
Confirm regex for validating password policy
I have the following password policy:
At least 8 characters in length
At least one digit
At least one special* character
*I consider any character that is not a letter, digit or space to be a ...
3
votes
2answers
116 views
0
votes
0answers
34 views
Create an instance every loop or use one instance repeatedly?
In this question on SO, the consensus seems to be that creating multiple objects is superior in C#. I am wondering if that is also true for PHP. I have the following code:
...
1
vote
1answer
51 views
PHP MySQLI Wrapper - SqlObject
This is a PHP script I wrote it back in 2015 and have been updating it since.
It is a MySQLI wrapper called SqlObject (class) that was originally created to be ...
2
votes
1answer
89 views
Fizzbuzz function in PHP
Most implementations of FizzBuzz that I've seen rely on 3 modulus operations. Mine does two and a Boolean. (Not implying one is better, just different)
I understand that FizzBuzz is supposedly not to ...
0
votes
1answer
58 views
Show a search input bar depending on which path the user currently is viewing
Im using Laravel with the Blade template engine. Im trying to show a search input bar, depending on which path the user currently is viewing. The three paths is all,...
1
vote
1answer
30 views
Redirecting the web client after deleting an item
In my web-app, it is possible to delete an Item when visiting any of 4 different pages:
the Show Item page
the Edit Item page
the List Items page
the List Items in Room page
If the visitor uses a ...
2
votes
1answer
53 views
Display four random entries from an array
This code will take the array shown and display 4 random entries in the format shown (or near enough).
Any part of this that can be optimised? I'm not happy about the ...
1
vote
1answer
49 views
PHP handle array when query database with one-to-many relationship
Well, I am writing a web service using PHP to return data from a DB in JSON format. I need to query 3 tables, which have a one-to-many relationship, like shown below:
...
2
votes
1answer
86 views
PHP Login and Registration system using BCrypt
I'm new to web development and this is my first website. I was wondering if my login and registration system is secure. I was also wondering how to handle viewing parts of a webpage when the user isn'...
1
vote
1answer
90 views
Sanitizing user input with markdown-like syntax
Since I sanitize all the user-provided string before upload them to the DB, I wanted to give the users the possibility to format text as it happens here on Stack Exchange or on WhatsApp:
...
6
votes
2answers
100 views
Browser-based Mafia game in PHP
Because I'm rather new to PHP and Object Oriented Programming, I'm often looking for some practice. Thus I decided to focus on making a browser-based Mafia game that should work like a Dutch variant: ...
0
votes
1answer
51 views
Dynamic software update system using PHP
I have this code I have made to check after new release, when there is a new one it ask you for install it, and then installs it if you accept.
The file is a zip file with the new folders and files ...
3
votes
1answer
100 views
Registering users bank account and logging in securely
I wrote a php script to register a user's bank account and I've tried to make the login as secure as possible, but I wonder if there are any flaws and is it's free from xss attacks and sql injection ...
-1
votes
1answer
63 views
Directory Filter Class PHP
I'd like feedback on the class below, from the perspective of wanting to write professional code that I would be paid to create. I would appreciate comments on details such as commenting, naming and ...