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
-3
votes
1answer
20 views

Display errors without static function calls

I'm trying to avoid using static functions as much as possible. But the code is so clean when I use them. How would you cleanly refactor this without static functions? ...
1
vote
1answer
28 views

Dynamically inserting html from external file and updating the database

I need some suggestions on how to approach this. I want to allow users to create sections of website. The code so far is working but since I am new to back-end I feel like there is better, more ...
1
vote
1answer
45 views

A method to get a document's path

I have a model called Document, in this I have a method that I use throughout my website to get the full path to the specific document: ...
2
votes
3answers
49 views

PHP recreate array if it contains certain values

I have $fruits_arr: ...
0
votes
1answer
26 views

Upload image with GD library

First of all I just started learning OOP. My priority is to make safe code. I think my code is safe, because I use GD to make a copy of the uploaded image and I use an image proxy to make sure nobody ...
-1
votes
0answers
18 views

Can I avoid htmlspecialchars with header? [on hold]

In my website, when a user makes a post, the PHP header function kicks them back out to their home page. If I wanted to use the following line of code... ...
1
vote
1answer
34 views

Create a pump object from either one of pump model number or pump product id

Consider this code: ...
1
vote
0answers
20 views

pausable and chunked file upload

I am trying to create a file hosting website where the file upload is chunked (to help large files) and allow users to pause the file upload. Maybe each chunk would save separately to allow users to ...
1
vote
5answers
59 views

PHP function to obtain model_name from Namespace\To\ModelName

Would there be a more clear/efficient way to write ...
4
votes
2answers
117 views

Calculate payback

I want to know if there is a better way to do this function. The function calculates a payback. Basically, the company spend x amount of money and per year they will save some money overtime. They ...
3
votes
0answers
27 views

PayPal Checkout API with PHP - Sending and retrieving additional data safely

I am learning to use the new API version of Paypal, and I have some doubts. Note: I've tried this on https://www.sandbox.paypal.com and it works, I have not done the tests on Live. onApprove: I ...
1
vote
1answer
41 views

Test Driven Development Roman Numerals php

I just learned about Test Driven Development on a podcast yesterday. So I decided to try it out today by writing a roman numerals to integer converter (per their suggestion). I've never written Unit ...
1
vote
0answers
17 views

PHP/Apache - Production/staging consts file path

Is there anything wrong with having a file path as an env variable and using that as-is in a require_once? ...
1
vote
3answers
83 views

PHP - check if array includes value and return value if true

I developed the function array_includes which checks if an array contains a value and returns it. I would like to know if there is already such a function which is ...
3
votes
1answer
43 views

Displaying a user's uploaded posts

I'm working on prepared statements for my website and I'm wondering if it's possible to have multiple prepared statements one after another. In this example, I have 2 select statements. I'm hoping ...
0
votes
0answers
23 views

WordPress hook to add URL-rewriting rules for articles with language variants

Please look at this working WordPress code: ...
6
votes
3answers
261 views

Single method for different parameterized mysql command

I currently have these two methods. One method returns all records, while the other one returns only a specific record. ...
1
vote
1answer
35 views

Database connection and DataMapper

Following my previous question Database interface and PDO adapter, I wrote a new simple class to connect to Database and run a query returning a PDO statement. ...
0
votes
0answers
52 views

Is there any better approach on this rows to columns table?

I pass a function into the variable ($monthly_receivable) to get the value of each months to pass and get the result of a function.. but the process is dumb slow. ...
2
votes
0answers
32 views

A cleaner way to track model changes

The application I'm currently working on have two main user types, let's say user and reviewer. I need to create a functionality ...
2
votes
1answer
54 views

Database interface and PDO adapter

I'm writing my own framework in PHP and I want respect the SOLID principles. I made this interface: ...
2
votes
2answers
55 views

Shopping cart with Ajax

I build a cart for an ecommerce website, and I want to know if I did well. I want to record the changes in the DB and display the information from the DB to the customer. To be sure that what he sees ...
3
votes
1answer
65 views

PHP Error handler class

I set up an error handler class to handle all server errors, I know there are already quite a few out there, but I like creating my own for better learning and understanding of how things work. I am ...
2
votes
1answer
46 views

Abstracting a SQL Server Table builder

I'm working with SQL Server 2008 and wanted to make table builder, similar to Laravel's migration classes. I would like to be able to expand this down the road but the main purpose of this code will ...
3
votes
2answers
74 views

Elegant and secure way to create a dynamic query

I want to create a dynamic query to display: all the invoices if the user has moderator rank only his invoices if the user is a simple member code ...
-2
votes
1answer
85 views

Parse header information [closed]

Concrete Context: I parse the header information from curl execution/request and get the array named $headerARR. At this point it looks like the next example, but ...
1
vote
2answers
56 views

Combining two queries in one

What I want is getting all names (first, middle, last) of the users along with each of their total hours of work which will be calculated by the SQL statement: ...
2
votes
1answer
64 views

Using Curl/Post to execute a HTTP request

I have a loop in a php file to HTTP_Request Server Via CURL->POST. But I don't know if I'm missing any security considerations. Also, is there a better way to perform this http request? ...
1
vote
0answers
29 views

Webshop Conversion - Binary testing is not even [closed]

Everytime a new visitor comes to my webshop I write a cookie (1d) which sets a session entry with mt_rand(1,2) to A or B group. ...
4
votes
1answer
38 views

Codeigniter models optimization

I have two tables: tableA aid name age sex ...
3
votes
1answer
56 views

OOP in PHP. Exercising on creating a blog

I am attempting to do object oriented programming in right way, and appreciate any review to see if my approach is correct. class_blogpost.php as below: ...
2
votes
1answer
40 views

PHP LDAP credentials validation and error handling

I developed this group of scripts to validate users againts a LDAP server and presenting the appropiate message to the user after sending the information. I wonder if I'm handling everything properly ...
4
votes
1answer
46 views

List of previous and upcoming months to a given date (year and month)

I need a menu with buttons of months previous and after a given month, something like this: | month | month | month | current month | month | month | month | Can this function further be improved? ...
4
votes
1answer
104 views

A small PHP library for styling terminal output

I've attempted to make a small PHP library for styling terminal output using ANSI escape sequences. The repo is located here. To be honest, I am not really satisfied with the current structure of my ...
0
votes
1answer
50 views

Register Script for a website [closed]

I'm still new in web development and I am trying to develop a website with free access to doctors listing with option of booking. This is a personal project that my local community can benefit. I ...
2
votes
1answer
24 views

List products based on slug and sidebar filters

This method shows the list of manufacturers' offered products based on the slug and sidebar filters. Most of the time I have to write the same query with only some changes: you can say I am repeating ...
1
vote
0answers
13 views

Custom WordPress SQL query to get posts and users using term_id

I have a WordPress site with multiple custom post types, that all share a common custom taxonomy. Users can also be tagged with terms from this taxonomy. After giving up on ...
2
votes
1answer
41 views

Secure file upload in PHP

I've coded this function as a secure file upload function in PHP. Currently I'm woking on an academic grading system (PHP script) which's really sensitive, so tell me what you think, and if you have ...
1
vote
1answer
54 views

Displaying a paginated list of forum topics using PHP PDO [closed]

Can someone tell me if this code is safe? Can be sql-injected or something else hacked? Code get some rows from db and show in pages with pagination... if i can improve let me know and show me how, ...
7
votes
1answer
139 views

Build a set of REST interfaces using Symfony framework

I have got a technical challenge from a company but they reject my code and I'm not sure how to do this challenge in a more efficient way so I'm here to get some guidance. The Technical challenge was:...
1
vote
0answers
37 views

Proper image sizes in WordPress

I wanted to create a set of functions that would allow me to easily implement images for multiple screen resolutions in my custom page templates. WordPress offers some functionality for implementing ...
3
votes
1answer
52 views

Whitelist for textarea and save input to file

I'm working with product codes, so a user can only scan these type of product codes into a textarea. I don't know if my code is written the best way possible, or has good performance. I'm using a ...
4
votes
1answer
230 views

Codeigniter 3 micro-blogging application

I am working on a basic blog application in Codeigniter 3.1.8 and Bootstrap 4. The application allows Registration (as an author), Login, adding Categories and Posts. I have created an installation ...
1
vote
0answers
44 views

correctly implement PHP OOP in blog Post Class [closed]

I would like to know the best way to setup my PHP Blog classes. I have created a Post class which creates a blog post. ...
4
votes
2answers
74 views

Building object identity in PHP

I am trying to build object identity in PHP so that when I have a collection of objects, each one can have a string as identifier and all of these identifiers are afterwards combined to form an unique ...
1
vote
2answers
30 views

Dynamically create table colmun into checkboxes

I have table which contains different permissions. Currently i am render all those permsion columns into check boxes manually. Like this ...
6
votes
3answers
231 views

Dynamically loading CSS files based on URL or URI in PHP

I have written out the following code in the head section of my document, which should load 3 separate style sheets for each page based on the URL/URI that the user is visiting. It is working as ...
4
votes
1answer
82 views

PHP program to generate random phone number

I created a PHP program to generate random phone numbers. A valid phone number: must be exactly 11 digits in length, and must start with any of the values mentioned in the ...
2
votes
0answers
52 views

Make Pagination using Ajax with Jquery, PHP [closed]

This is the first time that I have add (I mean, I try) Ajax with Jquery to PHP and Mysql (pagination). This is a link to the test page: testpage1 I think everything works, but is it done correctly? ...
1
vote
2answers
47 views

PHP unit test to confirm that a validator is being called correctly

I have a Responder class whose prepare method takes an entity, checks it with a validator, and returns a response or errorResponse based on the results of validator....