PHP is a widely-used, general-purpose scripting language that is especially suited for web development.
0
votes
0answers
6 views
Database fetch class
The active column in the database only contains a boolean. The country column contains ISO 3166 A2 codes (2 char). Do you have any advice on improving this class?
...
-2
votes
0answers
26 views
How can I optimize this curl script? (PHP) [on hold]
When I run var_dump($title), I get results really quick, but my script fetchs the whole page in order to get one result, then do it again, again. How can I do this ...
1
vote
1answer
44 views
URL checker is very slow
I have +-645 IRL links I need to validate. The code below is my attempt, but my problem is that it takes forever to check all links and sometimes times out. Is there a better way of validating so many ...
0
votes
1answer
21 views
All-purposes AJAX handler made with PHP and .htaccess that speaks JSON - Part 2
Earlier, I've posted a question about a file used to handle AJAX requests.
I've followed some of the advices given and made some changes on the code itself.
You can go on "All-purposes AJAX handler ...
0
votes
2answers
27 views
All-purposes AJAX handler made with PHP and .htaccess that speaks JSON
In a project I've started, I decided to implement some new code to handle AJAX requests.
The requirements are that it can ONLY access the /ajax/ folder, load ...
-2
votes
0answers
13 views
0
votes
0answers
38 views
How to make a class to public? [on hold]
I have a class, where I have some private, and protected variables.
They are protected, because I do not want to be able to access it directly. Let's call this class ...
4
votes
2answers
64 views
Aggregate array values into ranges
In five minutes I made a pretty ugly looking function. Can you help before I have to commit the code into history?
Requirements:
I would like a function that takes an array of numbers, and ...
1
vote
0answers
20 views
Custom 503 page for MySQLi connection error
I redirect all my requests to index.php via htaccess and the code below is in my index.php.
I want to ask if my code is properly set for a custom 503 page for an unsuccessful MySQLi connection trial.
...
6
votes
2answers
111 views
Splitting three comma-delimited strings
I've been reading about loops this morning, to try to improve this snippet of code:
...
1
vote
1answer
47 views
Car store implementation using abstract factory
I'm studying design patterns and I made this car store implementation. Although I'm confident that the idea is right, I'm not confident that the implementation is good. I would like you to check it ...
3
votes
1answer
44 views
Changing a user's password
I wrote this class for the project I'm currently working on. It's basically used to change a user's password. I'd like to know your thoughts on the basic structure/design of this class and how it can ...
0
votes
1answer
34 views
Sort by a custom date field
I've got this code to work, but being really new to PHP, I don't know if this is proper. I've sorted a CPT loop by a custom date.
I'm displaying items from most recent (or future date) to oldest
if ...
0
votes
0answers
32 views
Change color of link if radio button is not checked
I have created an online exam system in PHP and JavaScript. In the HTML page, my questions are fetched from the database. If any question is unanswered or the radio button is unchecked, then the ...
1
vote
1answer
29 views
Merging website info into an array
I'm scraping a title and a link from a website and placing them in a single array.
The $i variable seems a bit wrong to me, or is it perfectly fine?
...
3
votes
0answers
44 views
Caching in PHP using the filesystem
I wrote a simple class to cache data on a filesystem. The class also provides an internal cache using a static variable to avoid reading from disk for each request.
...
3
votes
2answers
77 views
Is my login system secure?
I am recently making a CMS and I need a secure login system, so this is my code. How is it?
First: the HTMLcode for signup and login:
...
1
vote
2answers
46 views
Alternate for nested Ajax requests
I have one button on clicking I need multiple things need to be done, so I went for AJAX and PHP:
...
4
votes
1answer
285 views
Polyglot array_extend() function for Javascript and PHP
This is a polyglot function I've made out of fun.
The goal is to grab n arrays (or Javascript Objects) and 'extend' them in ...
-2
votes
0answers
10 views
0
votes
1answer
37 views
Design pattern proper usuage where a decorated object may ask for things like “status updates” from the decorator to perform its role [closed]
Here's a situation that has haunted one of my open-source projects for quite some time:
Imagine if you could represent every front-end input form with a single backend object? An object that contains ...
1
vote
1answer
34 views
Moving repeated files from one folder to another
I want to scan my whatsapp images folder and move all the repeated images to folder named recycle bin to delete them later:
...
5
votes
3answers
48 views
Performing database interactions
I wrote this CRUD class in PHP that has methods to do database interactions, but I want to know if it is good/secure/elegant?
It works fine and all and it hasn't ever given me any troubles, but I'm ...
1
vote
1answer
51 views
Login with password_hash()
I am learning from a book, which uses SHA1. I've changed the code to password_hash(), by checking online. Here I query only the password and verify it. I managed ...
2
votes
1answer
19 views
Formmailer safety
I am currently working on a PHP-Formmailer. I`m completely new to PHP but I do have knowledge about HTML, CSS and Javascript. I would learn PHP starting with the basics and everything but I´ll be ...
0
votes
0answers
22 views
HTTP Responce randomization
I've made some unethical code giving HTML responses at random and masking what is there for fun. It targets mainly crawlers and scripts that run through your website that are looking for ...
-2
votes
1answer
29 views
standard and common config file for core php project
I am creating config file for every other project and try to set all necessary things at once but sometimes miss the things.I have used many framework but most of time I need core and minimal config ...
1
vote
1answer
24 views
Incrementing and displaying a field if not empty
I've got this code to work, but being really new to PHP, I don't know if this is proper. This is my first time using PHP to increment.
I have 10 fields for YouTube videos (using Advanced Custom ...
3
votes
2answers
117 views
Correctly coding an OOP object
I have a couple of functions in WordPress that I'm rewriting to OOP. All these functions are interlinked in some way and also reuse code from other functions.
This is an example of the first class ...
4
votes
3answers
391 views
Using goto to wait on the result of a database query to change
This is a small personal project where most non-sensitive data is distributed to some globally hosted CDN servers, which store the JSON. Now one problem we've seen during testing is a few deadlocks ...
3
votes
1answer
21 views
Formatting database results to be consumed as multiple tables by the view
In the code below, $rows is the result of database query. In the view that consumes this, I need to break the results into a separate table for each vendor.
The below creates a structure that allows ...
0
votes
0answers
25 views
apply_filters for validation function
I am using the function below to validate my color options, but I am not 100% sure if I am doing it right, particularly this bit of code:
...
2
votes
4answers
83 views
User class and 'generic' Database class
This may be a bit overwhelming, but me and a friend of mine have written a Database class with methods for our queries. All of these queries should be generic so we can use them in multiple ways. We ...
0
votes
1answer
63 views
PHP framework building: initializer and object loader classes
I am building a PHP framework and would like to get some feedback on a few different sections of the project. I consider myself still a neophyte in PHP so I would like to ask if I'm going about ...
4
votes
1answer
59 views
Simple Pizza Factory with tests
I implemented the Simple Factory Pattern with some unit tests, but I'm with a feeling that I did something wrong and that I can improve it.
Tell me what you think about the code (source and tests).
...
1
vote
1answer
35 views
A shorter way for getting variables
I have the following piece of code in my project, and that a few times:
...
0
votes
1answer
31 views
8
votes
2answers
2k views
How much is 2 + 2?
I'm currently working on a kind of PHP Quiz about mathematical calculations. We show a mathematical equation, and user need to input his answer.
Currently, this is what I have written:
...
3
votes
2answers
71 views
Displaying a random poem from a database
I'm new to web development, and I'm constantly torn between good code and bad code. I was wondering if you could help me improve my following code and see if I'm doing it right in terms of how I use ...
-1
votes
1answer
71 views
Lower amount of redundant code
I have as recently as last week picked php back up to code in. My experience with it has always been quite limited, but as I am now making a simple application for my job (for internal use) I am ...
4
votes
1answer
41 views
Bitwise operators for permissions
I'm trying to create a read-write-execute permissions system for items using user-group-world system.
I already have the user/group system set up, just not the permissions.
This is what I wrote:
...
1
vote
1answer
13 views
Finding the year using strtotime vs calculating manually
I need to calculate at which year a school class has started, given the year they currently are in. For example a class of 2nd graders have started school in 2013, if I pass 2 to the function it ...
0
votes
1answer
56 views
Join 2 arrays together
There are 2 arrays. One that consists of Categories and one of Products. Each product pertains to its specific category. I want ...
-1
votes
1answer
67 views
Php code not efficient [closed]
This code works but I am assuming it is very inefficient.
Basically it does:
Add to the variable $a if the scoreavg is over 3
...
2
votes
0answers
35 views
Creating chat box with comet
I'm writing chat application. I would like to know if there are problems in this code.
This function sends message:
...
1
vote
1answer
45 views
Random retrievable number based on day and month
I wrote a function to get a 2-digit random number for each day, but it should be retrievable.
For example, today's random number is 72, but later I can provide "day and month" and get this 72 again.
...
3
votes
1answer
35 views
Immunity of login/signup class to all types of attacks
I am going to use the following class which is very simple to use and get user info in pages:
...
3
votes
0answers
66 views
PHP login script security check
I made an admin login script for my own CMS website that I'm making in Code Igniter 2.2.1 and I'd like to know what are the potential threats or some holes that I might have left open.
This is how it ...
0
votes
0answers
50 views
A client with transports that have unique options
How can I improve the following interface implementations and client using it? I feel the transport ideally should be hidden from the user of Client but then how ...
2
votes
0answers
25 views
Which pattern could help to refactor this controller code?
I know I should use services and patterns to refactor this controller action, but I can't imagine one that could fit/be appropriate for this problem.
It seems a strategy or template, but a strategy ...