Questions tagged [php5]
The fifth version of the PHP: Hypertext Preprocessor (PHP) scripting language. It features the Zend Engine 2, better object model support, and many other improvements over PHP 4.
229 questions
4
votes
2
answers
229
views
Security of post submission, picture upload and post fetch
I am a newbie and have been following a tutorial I bought on Udemy. But I was told it is old and teaches bad code practices. I used this in some code from my old projects. Now I'd like to know how ...
-3
votes
3
answers
406
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
1
answer
271
views
PHP - Importing columns from uploaded CSV file to SQL database (Laravel 5.7) [closed]
The goal is to upload the columns from the csv into the SQL Pro database. I am able to select the column names that have been uploaded from the csv file, the columns from the csv file are then ...
1
vote
2
answers
780
views
Validate array elements in PHP
$elements is an array, which may contain 'x' or 'y' keys, I want to check if they exist, otherwise assign a 0. I'm looking for a clean way to validate it. I'm new ...
3
votes
0
answers
58
views
Use a pattern for fields validation
I need to validate the fields of user sent by an API. All works fine but the only one problem is that I don't like the solution is not an OOP solution. In the controller I call the service created by ...
1
vote
1
answer
111
views
Merging and summing multi-dimensional arrays
I've found myself today really struggling with this subject and I'm pretty sure that there must be a better way to do this.
First of all my arrays have the same layout, I need to merge them and sum ...
3
votes
2
answers
2k
views
Users management php class
After a little bit of troubleshoots, I've finished this simple users registration and login class. It uses PDO to connect to a mysql database, I've tried also to ...
1
vote
1
answer
137
views
Appending objects to an array based on a field
I am working with PHP5 (Laravel 5.1), and I couldn't optimize my function, which takes more 4 minutes turning, and fails in the end when I have a huge data (around 6500 rows, but working when i test ...
0
votes
1
answer
49
views
Quiz setting users grade
I have made this code to determine the users grade for a quiz. However I've just been thinking that maybe I could shorten the code somehow? as its just a lot of if and elif statements.
...
1
vote
1
answer
91
views
Git Autoupdater
At my office we have an internal monitoring tool we use on customer systems to monitor various vitals and notify us via Slack. Our Lead Dev and Chief Architect are very paranoid about Git, and ...
0
votes
1
answer
70
views
PHP return validate method of if one error is found
My method counts the number of times an error occurs.
I have a feeling my snippet isn't the best practice way of doing this. So when one of the validation methods fails I want to stop the method.
<...
1
vote
2
answers
2k
views
Sync Server Time with User's Timezone
I have a web application which is being used by users from different parts of the world. In order for users of the site, to be able to view the timestamps in their local time, I've a settings page set ...
2
votes
1
answer
147
views
Function to insert a tag into a database
I'm developing a MVC structured RESTful API project (thanks to the help of Mārtiņš Tereško for explaining it).
Almost all of my functions look similar to this:
...
1
vote
1
answer
194
views
Populate two arrays with two different SQL queries
I am using Joomla and connecting to an MSSQL database to store the resulting set(s) in arrays. I am utilizing this syntax, but there must be a more efficient way of coding this.
...
4
votes
4
answers
9k
views
Which is cleaner: a constructor with many parameters or many setters after construction? [closed]
I'm trying to work out which is cleaner, having a large constructor or having to use many setters on a new object before doing some work with it.
Large constructor:
...
4
votes
1
answer
2k
views
Code for a Person DTO, with tests
My needs are to manage DTO in a php5.3 application. I've written few lines of code in TDD with phpunit 6. The scenario I want to implement is a request with following fields:
name
surname
password
...
1
vote
1
answer
135
views
Create an object when you need it! in PHP
Well Iam trying to learn OOP for a while now, My idea here is to create a simple CMS kind of thing.And I did something like this:
App Class:
...
3
votes
2
answers
443
views
Implementation of a Custom Database Class
Following Database Class is what I'm using as a wrapper to connect with MySqli in a application, and below the class is how i'm implementing it currently I'm not sure if this is the right way to ...
2
votes
1
answer
160
views
Retrieving a message from a cryptocurrency daemon
The objective of this piece of code is to get a message from a cryptocurrency daemon through RPC and extract the transactions object to pass it to the view. Is there a simpler / less ugly way of doing ...
1
vote
1
answer
4k
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
1
answer
984
views
Doctrine/Symfony WHERE clause for reports
I'm trying to generate a report from two doctrine entities.
The fields to filter the report are optional. This is the code I've got now and it looks really bad to me. How can I improve this?
...
1
vote
1
answer
10k
views
Searching a CSV with PHP
Given a string, I've done the below to search a CSV for a keyword and display the row if it's found
...
1
vote
2
answers
2k
views
Nested file_get_contents / json_decode
I have this code but it takes over a minute to run. I'm looking at around 400 entries being brought back for the first loop. Any ideas on how it could be improved for speed?
...
2
votes
1
answer
225
views
Merge sort in PHP 5
I have this small program in PHP implementing merge sort. I used one rather simple run time optimisation via using one additional array which allows faster merge operations:
...
2
votes
1
answer
800
views
Array wrapper concept with method chaining that provides a fluent interface
I've been working on a class(2 actually) that wraps around the array data structure of PHP. It doesn't bring anything new to the table, it simple makes the function ...
2
votes
1
answer
348
views
Cookie wrapper made for fun
This was mostly made for fun, so I don't see it having any real world purpose any time soon.
...
2
votes
1
answer
2k
views
Combining json responses of recursive web service calls with PHP and curl
I'm implementing the Hotel Price List API from Skyscanner. This requires a first call to the service to implement a session followed by 1 or more calls to the service to get the actual results. I've ...
2
votes
2
answers
390
views
Split words that are too big
I need to optimize the below code, as much as possible in:
using less resources as possible
being as fast as possible
What the code does is simple, it splits the string by words and only if a word is ...
1
vote
1
answer
149
views
Create multi-dim array from cursor
I'm executing a cursor. I have cut off the code how the procedure is called and executed. This part is efficient. At last I have a small cursor. I'm calling the procedure, which returns this cursor ...
1
vote
2
answers
2k
views
Finding a word with the most occurrences of a character
I am new to PHP development. So Kindly, review my code and guide me make it better/optimize. Currently, it works well with inputs that I have tried.
...
1
vote
2
answers
3k
views
PHP program which extracts attribute lists from custom tag
PHP program which extracts attribute list from the custom tag. It also strips out the single and double quote if it exists around attribute value.
...
1
vote
2
answers
781
views
Lookup class to get descriptions of values
Following yesterday's advice on my Customer class, I have now created a new class which is for looking up descriptions from a MySQL database. I have a Lookup table which contains type, name, value, ...
3
votes
1
answer
4k
views
Simple customer SQL query using a class and function
I have been writing PHP for a number of years but in a procedural style. I have always shied away from object oriented PHP because I just didn't understand it. However now I'm back for another go.
I ...
5
votes
1
answer
130
views
PHP Class code that allow developers to register taxonomies in a CMS
Building complex applications can sometimes be a pain when extending or editing later on; I read online about the S.O.L.I.D principles of OOD, I want to understand if I am following a good approach ...
3
votes
1
answer
191
views
PHP class which preserves line break by splitting the line into as many line break as it have
Can anyone here please review my PHP code which preserves line break by splitting the line into as many line break as it have?
...
0
votes
2
answers
434
views
How to use PHP Visibility method?
At my new job, with new young developers, we are seriously discussing improving code structure and performance. (They keep more than 80 lines of code in a method). However I've read more tutorials, ...
6
votes
1
answer
300
views
A Search Engine Class
I've built a Search Engine class for a website that permits to search companies in base of their locations and their categories (companies pay a plan to be found in the places that they will).
In the ...
0
votes
1
answer
116
views
Authorizing users for POST requests
I've to authorize some users to do POST requests from their CMSs in order to create a new resource on my database. I've to send a JSON response containing the status of the response (successful or not)...
2
votes
1
answer
443
views
Forum project using OOP PHP
I've been developing a forum as my first OOP project, I've successfully built a login/registration and other functionality typical in forums.
I'm looking for some guidance in terms of where to take ...
1
vote
1
answer
118
views
Validation of uploading images and adding records to the database
I am doing a php project with the codeigniter framework. In my controller, I have a function that does the following.
Uploads an image to the server
Add a row to the database. The data would be ...
2
votes
1
answer
1k
views
PHP/MySQLi code for registration/login form
The following code works, I just want to know if there are any suggestions as to how I can make it better or more secure.
config.php:
...
1
vote
1
answer
79
views
Bulk customer creation
Here is my script which takes 50k records from a CSV and does CRUD operation with them. Unfortunately there are a lot of issues with the performance.
CSV fields are: msisdn, resellerid, product
...
2
votes
1
answer
3k
views
Using PHP's password_hash and password_verify for a login function
This is my first time using password_hash and password_verify in PHP. Would this be the correct usage of ...
0
votes
1
answer
144
views
Inserting a role using PDO
My question has to do with :
(a) Can this be made more secure?
(b) Are there best practices in relation to setting timezone?
(c) What best approach should be taken defining use of utf8?
...
3
votes
2
answers
311
views
Get number from N
I'm trying to find the shortest and best way to achieve the following:
Given input integer $N, get the following output:
n = 0, output = 0
n = 1, output = 0
n = 2, output = 10
n = 3, output = 100
...
3
votes
3
answers
148
views
Scrape HTML into separate files for each chapter
I have written a program to read HTML file, find particular text, write text from that particular text to next particular text in a newly opened file. I am interested in code review. I am very new PHP....
1
vote
1
answer
94
views
Mapping a product its corresponding image file
I'm writing this method that elaborates an image name..
I think my logic is not being the best one here but I'm not very savvy in programming yet.
Right now it looks like this:
...
2
votes
3
answers
6k
views
PHP form validation for name, email, and Twitter handle
Given the following input values from a form, create a method or
methods to validate the input based on their requirements. Throw an
exception if any data is invalid.
1.1 ...
5
votes
1
answer
1k
views
Multilanguage class that detects and sets language
I have been learning object oriented programming for quite a while. I understand many concepts about it but I quickly realized that I made a big mistake just reading theory and not doing any actual ...
3
votes
1
answer
120
views
Nesting a flat array in on itself
I have an extremely large function for turning my database output of menu links into a multidimensional array that nests each of the links in a menu fashion. I'm wondering if anyone sees a way this ...