Stack Exchange Network

Stack Exchange network consists of 174 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.

3
votes
1answer
131 views

Displaying text extracted from XML using PHP simplexml

I have this xml file and i am parsing it with php simplexml. My XML file looks like this: ...
0
votes
1answer
37 views

PHP simple template loader

This is not really a question but I'd like to obtain some opinions about this simple class. For an old project I had the necessity to load some php template files that includes some ...
2
votes
2answers
79 views

Adding ID to body tag from variable defined in URL

I have written a small PHP script to get a variable from the URL and echo it in the body ID. An example of the url: http://www.example.com/?var=123 I have added ...
2
votes
0answers
137 views

Simple bank OOP structure in PHP

I don't have much experience using either OOP or PHP since this is probably my first thing ever written in this language. I've had some exposure to OOP but I'm not used to writing programs that way. I ...
2
votes
2answers
164 views

Hacker rank - Left rotation - PHP code feedback for Timeout

Here is the problem description: https://www.hackerrank.com/challenges/ctci-array-left-rotation A left rotation operation on an array of size \$n\$ shifts each of the array's elements 1 unit to the ...
1
vote
1answer
71 views

Class creating dropdown options from MySQL data for multiple scripts

I created this class to handle some dropdowns that I'd been creating using a squirrelly combination of HTML, jQuery, and AJAX. This works much better in the one script that I've deployed it in: <...
2
votes
2answers
52 views

Dynamically displaying or hiding checkboxes based on region selection country. Also select All / None included

This is basically my first real venture into JS coding ... I think what I have put together here is quite long-winded and could be streamlined but I'm not quite sure how. So I have a table with ...
1
vote
0answers
39 views

Is this a good functioning router class?

I'm building my own application and have just started by building my own router since none seemed to be fulfilling my requests. Also, they seemed to have an overly complicated design. There are ...
1
vote
3answers
73 views

Always keep https in url

I wrote this recently, I thought I'd check if it was the best way to keep my url as an https at all times, any advice would be appreciated ...
2
votes
2answers
123 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. ...
2
votes
0answers
52 views

Search query to find articles on website with certain tags

I have the following search query to find pages on my website where I'd like to make as much as possible use of existing functionalities to determine relationship names and to hardcore the least as ...
1
vote
0answers
44 views

Displaying topics in a PHP forum

I am very new to PHP. I've only been using it for a few months. I'm currently attempting to build a forum and wanted feedback on some of the code I have so far. These are two files I feel like could ...
2
votes
0answers
54 views

SQL/PHP Laravel - Looping through records to find relationships

I have two tables in my database, which contains a big list of organisations. They are called orgs_main and orgs_sub. This is ...
0
votes
1answer
91 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
75 views

Recursive function to find the number of ways a number can be generated out of a set of numbers

I had a job interview test and the question I got was about making a function which would return the number of ways a number could be generated by adding numbers from a certain set, where any number ...
1
vote
0answers
88 views

PHP Chess Part 1 - ASCII Board & Import Position

I have been really into chess lately so I decided to program the game in PHP for practice. I want to get more comfortable with classes. Part 1 of the project is complete. I have a working ASCII board ...
0
votes
1answer
110 views

Object for generating HTML for hyperlinks

I have a function that generates HTML for hyperlinks. It's arguments may be string literals or variables read from the database. An example call to this function looks like: ...
1
vote
2answers
71 views

Encoding multiple rows from prepared statement in php [closed]

I have this code that hypothetically returns multiple rows from a database and encodes them in a JSON. I am wondering if this is the best and most presentable way to do it. Note: I am using msqli ...
5
votes
2answers
72 views

National Insurance Number Validation

I'm a beginner to PHP and I've written a function that validates a U.K National Insurance Number. The function works by checking whether the given number against the format below; The National ...
0
votes
1answer
123 views

Shuffle a string in a repeatable way

The following function is designed to accept a string of characters and an integer. The function returns a string that's a reordered version of the original string. The reordering process is ...
-1
votes
1answer
88 views

PHP/MySQL login

I just wanted to ask if this is a secure code (doesn't really matter if it's optimal or not) The code ...
3
votes
1answer
58 views

Conditionally displaying a notice about free shipping in Woocommerce

I wrote PHP code to display a Woocommerce notice - "free shipping for $40 & under" only once on shop page and once on cart page, but also in cart should not be more than 40$. The code works, but ...
-1
votes
1answer
108 views

PHP OOP registration with User class and singleton Database class [closed]

I created registration system with PHP. I have User class that will handle all the input and insert the user input into database, and i created Database class with Singleton pattern that will connect ...
5
votes
3answers
641 views

Counting distinct triangles that have integer-length sides

Problem: We are interested in triangles that have integer length sides, all of which are between minLength and maxLength, ...
1
vote
1answer
68 views

Should I add the “fetch_group” method to my user class or should I create a separate class for group

I have a table of users, where each user has a group (or multiple groups) he/she is part of. Currently I'm handling the users group via a Users class: ...
0
votes
1answer
93 views

Custom MVC framework

So, I've been working on a very simple MVC framework and I wanted some feedback on how it works. I've worked it slightly differently where the controllers don't need to extend the base ...
5
votes
3answers
619 views

Function for creating unique strings for urls

I wrote this function in order to create unique url's for my site. Using these urls, visitors could demo site functionality without having to create a login. The function was intended to return a ...
0
votes
1answer
52 views

Map value to color rgba

I wrote this function to map value to a color I am looking for some general feedback on how I can improve the efficiency of the function. and if there is better way to do it. ...
2
votes
1answer
101 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 ...
3
votes
0answers
106 views

Symfony: Encrypt ID's on postLoad event

I am building an application that is becoming some kind of social media platform. I need to work a lot with the entities ID's in the HTML and Javascript for the purpose of AJAX calls. However, for ...
2
votes
1answer
129 views

CodeIgniter method to get requests for superiors to approve

I'm currently working on an approval system right now using PHP (Codeigniter) and I have this method of getting all the requests according to your department group and position depth. The checking of ...
1
vote
0answers
45 views

PHP approval system [duplicate]

I'm currently working on an approval system right now using PHP (Codeigniter) and I have this method of getting all the request according to your department group and position depth. The checking of ...
3
votes
2answers
63 views

Update game content via AJAX

On my application, I have a JavaScript cycle that updates tag contents on my page regularly: ...
2
votes
1answer
285 views

Connecting 2 databases: one for admins and one for customers

I am working with 2 databases. One for admins ('backoffice') and one for users. Account managers: Use the 'backoffice' database to manage customer accounts. Customers: Whenever a users connects ...
2
votes
0answers
34 views

Many to many (n to m) relationship without insert duplication php

I managed to make a many to many relationship work correctly using mysql, doctrine 2 and symfony 3.4. When a new element A that contains 0 to m element Bs is inserted, the B elements that already ...
-1
votes
0answers
385 views

A basic MVC with routing and login system in PHP

I started working in PHP and I wrote several things before I noticed that I'm not sure if I'm doing DI right. So, I need someone to review an example of my code and tell me what I did wrong, and I'm ...
1
vote
1answer
264 views

PHP Prepare statement shortcut class

I did some looking around and found some more topics on how to use the $stmt->bind_param function inside another function or class what means the reference variables have to be sort of passed on. With ...
1
vote
1answer
3k views

Basic object-oriented PHP login, logout, and registration scripts

I am new to OOP in general and have recently started trying to develop object-oriented PHP code instead of relying on a primarily procedural style, as this is a requirement for my studies. One part of ...
1
vote
1answer
990 views

PDO Dynamic query builder

I'm trying to improve my php oop programming skills. As an exercise I wrote this class that will generate and execute dynamic sql queries. I've also writed a class to call various sanitization filters ...
6
votes
1answer
145 views

Password Hashing and SQL Queries

I am new to web development and am working on a portfolio piece, so I would like to make sure I'm not creating obvious vulnerabilities. I am wondering whether there are any clear flaws in the ...
3
votes
1answer
55 views

PHP function to evaluate comparisons between two values, with debug logging

The following method works fine but it is rather verbose: ...
0
votes
1answer
101 views

PDO insert data through transaction method

I have an import books function to insert more than 5000 rows at once, I did some research and did this one but some other places I saw a different kind of methods to insert without looping and ...
0
votes
0answers
264 views

Implementing Google ReCaptcha and PHPMailer

I have a contact form that performs validation on the server side with error messages being printed by JavaScript. I am curious if my implementation of Google ReCaptcha is correct, since my other ...
0
votes
1answer
63 views

insert multiple tag

I have 3 tables such as books, tags, book_tags. my objective is to insert books info along with tags (tags can be multiple or single). I have two methods one is insert books info 1st and then add tags ...
2
votes
1answer
89 views

Model database for contract renewal

I have made a contract renewal system in Symfony and Doctrine, and it works, but I think it can be improved, but I make too many requests to the database. These are my models: ...
1
vote
0answers
30 views

Dependancy Container

I'm currently creating my own microframework for learning purpose and I want to make it more powerful by providing a way to register classes and instantiate them (once) only when needed. So here is my ...
-5
votes
1answer
68 views

Best practice if statment [closed]

Which is good to use and why? if ($a == 3) { //do something } Or if (3 == $a) { //do something }
2
votes
1answer
82 views

PHP Template: Image file upload handler

I'm trying to develop some templates for common PHP tasks I've been dealing with. One of which is a general image file upload handler. So far I'm using the following reusable code which seems to be ...
1
vote
1answer
66 views

HTML file with a submit form

I have an HTML file that contains a submit form, which asks the users the fill in their personal info: then it will post and store into the DB by method of PHP SQL: ...
1
vote
0answers
36 views

Log in page using MYSQLi

I need to review my code. I used prepared statements to select data from the database. Is there more sanitization needed or any other problem in the code? Rate it, please. Thanks. ...