Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [php]

PHP is a widely-used, general-purpose scripting language that is especially suited for web development.

1
vote
1answer
21 views

httprequest to php login system benefits and disadvantages

I'm trying to make a login system for my website which I'll be releasing in public later on. I have inserted some main samples of my code in here and I would like some useful advise or suggestions. ...
3
votes
1answer
740 views

Laravel LoginController

I have a LoginController in Laravel, but I think it could use some improving, can anyone tell me where I am going wrong? It just seems overall a bit messy, but I can't think of a logical way to ...
1
vote
0answers
17 views

performing SQL SELECT query inside the loop [on hold]

I have a table leave_muster inside which I have to update all the records of the previous month on every start of the new month. My Code ...
1
vote
1answer
73 views

Live search project

I have a live search project and I don't know if it's secure enough or not. I don't access it directly, but I get data by JSON so I shouldn't worry about slashes or quotes, right? The PHP code: <...
0
votes
1answer
35 views

Delete directory tree function

I made this function to delete a directory with all its contents recursively, will it work as expected in a production environment ? is it safe ? I don't want to wake up one day with ...
1
vote
2answers
47 views

Secure a class for an hydratation from ma form POST

I use PHP classes for managing users accounts and I wonder if what I'm doing is correct. I directly use the $_POST['form'] for hydrate ...
1
vote
2answers
71 views

Statistical methods using PHP (mean, co/variance, standard deviation, skew, correlation)

Functionality This class has a list of statistical functions such as mean, variance, standard deviation, skewness, and it works okay. These functions are applied to arrays of charts data. It is an ...
4
votes
1answer
873 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 ...
2
votes
1answer
46 views

Store a hash in a cookie to identify the user's account to keep logged in after close browser

I made a option to user choose to stay logged in even after he closes the browser. It's really simple to implement, but i'm not sure about the hash i used to identify the user that is stored in a ...
2
votes
1answer
135 views

Retrive relation on a polymorphic model

I have a Game model that is "static". Containing game information and such, and users can comment on all games. Games model <...
1
vote
1answer
64 views

Back end validation as front end validation

I am trying to use the back end validation for front end validation and this is what I got. Maybe there is a better way to do this? If someone knows please share the knowledge. HTML: ...
2
votes
1answer
112 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
1answer
52 views

Simple MySql or MySqli Class

Which one of these methods is better/safer to use? And what benefits could I get using one or other? Simple mysqli: connection.php ...
5
votes
1answer
152 views

Reimplementation of Laravel's config system

I am trying to create a config class identical to Laravel's but wanted to do it myself, to test my knowledge on the PHP language, can anyone help me improve it? Each config file is located in the /...
3
votes
2answers
137 views

Simple single-file PHP login system

This is something that I initially came up with to protect a bunch of scripts on my personal webserver, but am now planning on using with a few public projects too. ...
1
vote
3answers
331 views

Clamp a PHP variable to a 0-to-4 range

I have a legacy code written as below: if($value < 0) { $value = 0; } if($value > 4) { $value = 4; } Is there an easier and more elegant way to do ...
2
votes
0answers
25 views

Wordpress plugin to create page-specific categories

I would love some feedback about this very simple Wordpress plugin (my first one). It's intended to create page-specific categories (via the creation of a custom taxonomy). It's working on my ...
-2
votes
2answers
105 views

Sanitizing name strings using PHP

Functionality: This method removes a list of specific terms (e.g., LLC, INC, Inc, Company, etc.) from a list of public companies names. It is part of a class that can be viewed in this link. I'd ...
-5
votes
0answers
41 views

5 different inputs from same [closed]

im working with laravel and i want to ask you how can i insert more then one different input data from 1 form to same table field, for example: I have that 2 migrations: ...
1
vote
0answers
38 views

Controller and Model Session handling classes (MVC OOP PHP)

Models/Session.php This file performs basic conditional checks and defines a function for each distinct action regarding Session initialization and ID regeneration. Is it OK, in this context, to ...
3
votes
1answer
129 views

Initializing a controller that uses Selenium

I've outsourced the setup functions from my class to another file, I outsourced initDriver from the class PortalController to ...
0
votes
2answers
83 views

User interface HTML string generated using PHP

Goal This is very basic beginner script, only for prototyping, probably never to reach alpha/beta prototyping/production, is being designed/tested for performance. Its performance quality might be ...
4
votes
1answer
142 views

Bill settlement for multiple users

I want to improve the logic for bill settlement and calculation of amount due. I managed to write code with T.D.D., but I think those loops could be improved somehow. Do you have any ideas on that ...
3
votes
1answer
125 views

Bool function in PHP to check if you run the script inside docker

I had to do a CLI script that does something, I also had to add a validation that checks if it runs inside the Docker. After some research I found a solution that people check some processes via ...
2
votes
2answers
1k views

Sorting a list by country name

A couple of weeks ago a company sent me this coding challenge: Please write a PHP web application and send it back to me as zip file: Which waits for a user action, like clicking buttons. ...
2
votes
1answer
27 views

Edit button toggles modal and load data from PHP using AJAX and JQUERY

I've been working on an edit/update button that will toggle a modal that looks like this: Is there a better code for this JavaScript code that I made? ...
2
votes
1answer
153 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 ...
0
votes
1answer
80 views

Updating values in a database

I'm using standard jQuery Ajax to update values in the database and reflect the result in an output. This repetition seems like bad practice and I don't know enough about jQuery to consolidate this ...
4
votes
3answers
6k views

Function to combine arrays of associative arrays

I recently create a function to combine some arrays of associative arrays in a single array in response to a stackoverflow question, where you can found more details about this. The function works as ...
5
votes
2answers
90 views

Avoiding code repeating in RESTful APIS PHP

Since my last question related to this I have managed to create a working base and to understand how MVC works. I'm writing RESTful APIS in PHP, they serve the purpose but I see that my code is ...
5
votes
2answers
26k views

Hiding $_GET variables using encryption

I use the following functions to encrypt my $_GET variables (whenever I can't easily get away with using $_POST or some other ...
1
vote
0answers
70 views

Commission calculation using PHP

Task is to read file(input.csv) and calculate each operations commission depending of operation type(cash_in or cash_out). I dont have any specific questions, just want overall feedback, like code ...
4
votes
3answers
90 views

Regex match comments and quotes

UPDATE New regex - covers escaped slashes and uses lazy qualifiers: ...
1
vote
2answers
3k views

Get collection in blade and check if empty

If I want to display the addresses of a user in a blade file I do it like this: ...
2
votes
1answer
415 views

Sort by value in multidimensional array

I have a multidimensional array of house properties: ...
5
votes
1answer
319 views

Filtering queries based on the current user state

I have a Symfony2 project. I have an Entity Asset which can have relations with Category. I store a ...
3
votes
1answer
679 views

Multi-query PHP Parser for SQL files

I have an external project, which needs to run an SQL file containing multiple SQL queries (a bit like mysqldump, if you like, but is user-created, with any kind of SQL statement/definition). PHP ...
2
votes
0answers
29 views

PHP - Transforming text content according to rules then persisting to database

I have a web application where my users can upload text documents and emails into what I call Streams. A stream is like a "stack", that holds all emails / documents. My users can then add ...
1
vote
2answers
598 views

Hide or show table rows as a hierarchy

I'm using PHP HTML and JavaScript to write questions that need to be shown/hidden based on inputs from the user. I have several rows in a table, each row contains a ...
0
votes
3answers
151 views

Codeigniter 3: how can I avoid repeating this chunk of code in my controllers? [closed]

I am working on a basic blog application in Codeigniter 3.1.8 and Bootstrap 4. Several entities are present in all controllers (except Login.php and Register.php): static data, categories and pages. ...
2
votes
2answers
330 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 ...
2
votes
1answer
91 views

PHP Mad Libs with OOP and SQL

I've been learning PHP and I've just gotten into using OOP. Classes/objects/methods etc. My end goal is to take an old Mad libs program I did with PHP, and convert it to OOP. The gist of the project ...
4
votes
5answers
1k views

Transposing a PHP associative array

The purpose of this code is to change each column to a row, and assign keys to each value for the new array according to the old array. I would like to know if there're other ways to optimize it. <...
1
vote
1answer
124 views

PHP Laravel - Improving and refactoring code to Reduce Queries

Improve Request to Reduce Queries I have a web application, where users can upload Documents or Emails, to what I call a Strema. The users can then define document fields email fields to the stream, ...
1
vote
1answer
45 views

Wrapping certain elements in an array with an array with PHP

I have a function that's doing this correctly, but I feel as though this can be done (possibly) with minimal code, with recursion, but I'm just wracking my brain. Basically I have JSON that gets ...
2
votes
3answers
165 views

Fill an array with last non-zero element to the end in PHP

I need to fill an array with the last non-zero value. Points of note I guess are that the array will either have all 0 values or end with ...
2
votes
2answers
111 views

PHP - Packing widgets into the fewest number of boxes, plus minimum order quantity

The problem is this: A company supplies widgets in a set of pack sizes: 250 500 1000 2000 5000 Customers can order any number of widgets, but the following rules apply: Only whole packs can be ...
2
votes
2answers
76 views

PHP find cheapest permutation

I have multiple products that all have sizes and I need to find the cheapest configuration that meets the minimum required size. For example, John needs a minimum of 10 litres of storage - it can be ...
0
votes
0answers
21 views

A smarter way to build custom wordpress permastructures and keep them updated in admin?

I've done this many times.. Breafly speaking, I've got a custom post type with custom taxonomy (say products_categories), and want model single urls like this structure: ...
1
vote
1answer
222 views

Equity data processing: Fast and/or efficient file writing using PHP

Problem This project gets the past ~20 days of an equity data (such as $AAPL, $AMZN, $GOOG) plus the current equity "quote" (which comes every 60 seconds using a free API) and estimates seven "real-...