All Questions
186 questions
4
votes
2
answers
209
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
379
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.
...
1
vote
2
answers
753
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
48
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
89
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
117
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
36
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.
...
0
votes
1
answer
53
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
127
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
170
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
122
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:
...