PHP is a widely-used, general-purpose scripting language that is especially suited for web development.
3
votes
1answer
26 views
Speeding up class that uses an ODBC connection
I have created a class that gets data from an ODBC connection. The code works but it is really slow - I'm talking up to 1.20ish minutes to run. I know my code is inefficient but I'm really not sure ...
3
votes
2answers
72 views
Returning nested array with added key=>value
This works, but do I have to make a new array, result, or is there a way to just insert the field I need into each $key of the ...
2
votes
2answers
51 views
Filling modal from JSON (dynamically)
My Java app converts its modal object to JSON (using the GSON Library).
This is just fine, but I have to get it back into a modal in PHP. Now I've created a modal (in my case it's, for example, ...
5
votes
3answers
117 views
Cleaner or better readability in URL composition
I have a URL that is hardcoded via a config which I extract into a config:
...
3
votes
1answer
16 views
Login system, PDO and me - Part 2
This is a follow up question to: Login system, PDO and me
Is this considered secure for a login script?
...
1
vote
1answer
20 views
Admin page select
This is a follow up question to: Admin page select function
Here, index.php does the following:
Checks for a login status using sessions and a cookie
If logged ...
9
votes
2answers
516 views
SQL injection safety check
I was wondering if my code is safe for sql injection.
This code just checks if the username exists in my db or not.
...
1
vote
2answers
57 views
Simple wrapper for an API
This is a wrapper for an API. For now all it does is get a certain document or search for relevant documents from a document store -- although I plan to build out more features later. I'm new to PHP ...
3
votes
2answers
82 views
Formatting options for a long IF statement?
I have a somewhat unwieldy IF statement and am wondering if anyone has any suggestions on how to make it more readable.
One one line it was all but impossible to understand, so I broke it up into ...
6
votes
2answers
177 views
Displaying content based on the current time
I'm new to PHP and just wrote a bunch of if statements to display content based on the current time.
Is there a better way of writing the following block of code ...
1
vote
1answer
62 views
Is this acceptable usage of try/catch and database transactions?
I am using try/catch syntax in combination with a database transaction to (hopefully) prevent partial registrations.
I am ...
3
votes
2answers
67 views
Controller: Sign up action clean up
I don't know if it's just me, but I feel like my sign up action method has gotten a bit messy.
I think that perhaps instead of setting error messages in a controller, I should set error codes which I ...
1
vote
0answers
6 views
PHP Cache Strategy - Genius or Sheer Stupidity? [migrated]
I have a shared hosting with limited capabilities. Memcache and mod_cache are not available to me. I would like to implement my own PHP caching method to cache the results of load-intensive SQL query. ...
-1
votes
0answers
39 views
How can I get persons to use my applications? [closed]
The internet introduced me to computer programming. At 15 I started learning HTML. At 16, I started learning C#,Visual Basic & some C++. Computer software makes absolutely no money where I live so ...
3
votes
2answers
46 views
Using `exec()` in an autoloader
After reviewing autoloader functions on the site, I didn't see anything like this, and I was wonder what may be wrong with this?
...
3
votes
1answer
63 views
Clean up / refactor this store() method
I'm new to Laravel and trying to figure out how I can reduce/refactor this store() call in my SessionController.
Basically, the ...
1
vote
0answers
58 views
Automatic condensing of whitespace in HTML
One of the things that has occurred to me more recently is that if you add up all of the bandwidth that is taken up by thousands of users downloading the newlines and tabs used to make HTML source ...
0
votes
2answers
61 views
Add a set of querystring params to a URL
Example cases:
Need to add x=1, y=2 and querystring variables to the following URLs:
...
2
votes
1answer
40 views
Factory style pattern in method
I have a method in a class, and its sole purpose is to prepare another class for use:
...
7
votes
2answers
455 views
Protect database from SQL Injection and similar attacks - PHP
I am doubtful about the security of my PHP code. I am new to programming, but want to learn how to secure things, protect my databases from SQL injection, and other best practices. I'd like to know if ...
6
votes
3answers
410 views
Check efficiency of PHP code that will query over 8500 orders
I am querying all orders from a WordPress database that uses the WooCommerce Bookings plugin. I want to display upcoming bookings, and there is a potential to have every hour within 2015 to be booked; ...
2
votes
0answers
34 views
Matchmaking two clients together [closed]
The approach I am using to match two clients together is as follows:
Client sends token to server
Server creates an entry in the matchmaking table
Client sends ...
2
votes
1answer
70 views
Basic PHP Factory Pattern
I have an object, KbArticle, that originally in it's constructor, would try to return null if the SQL query that retrieves the data for its required properties came ...
0
votes
0answers
9 views
What's a good simple way to combat the n+1 problem? [migrated]
I'm trying to better understand performance in PHP. One issue I'm thinking about is the n+1 problem. By n+1 I mean something like this:
...
2
votes
2answers
58 views
PHP Trait Singleton
An implementation of the singleton pattern in PHP using a trait (added in 5.4). Is there anything missing, any ways to create a second copy of the class?
...
1
vote
2answers
75 views
Get user level based on total posts [closed]
Let's say a user has 575 posts and I want to give access based on post level.
In order for the user to be Level 1, that user has to have more than 200 posts, level 2 = 300 posts more (500 in total).
...
1
vote
1answer
37 views
Image upload and thumbnail creation script using PHP GD
Ignoring my shocking use of the mysql_* extension (and any associated issues), could you take a look at my script that uploads an image, adds it to a database, ...
5
votes
1answer
60 views
List files and download
The following code list all files in a folder and allows the user to download one of them. It is working but I think it could be done better.
Is there a way to reduce the number of forms to only one ...
9
votes
2answers
199 views
Sessions and Authentication
I've a feeling I'm overdoing my Auth class, and that it could be done in a simpler and more understandable way.
Could you give me advice on this, please?
This is ...
5
votes
2answers
159 views
DB abstraction, private methods in OOP PHP library
This library registers a new user.
Questions:
Where should the DB class instantiation happen for user class? I tried instantiation in the constructor but that property doesn't seem to be available ...
4
votes
1answer
40 views
Nodes and Boundary Conditions in Finite Element Method
The problem:
A Node is located in a specific coordinate (x, y, z).
A Node can be one of these types: ...
4
votes
1answer
87 views
First attempt at making a user class
I've just begun creating my first user class. First, I need some clarifications.
Am I using try and catch correctly?
To ...
3
votes
1answer
46 views
Rewriting dispatch method
Is it possible to rewrite this piece of code any better when it comes to efficiency and/or readability?
...
4
votes
1answer
51 views
Does my image upload look safe enough?
I have an image upload script that uploads images to the server:
...
4
votes
1answer
68 views
Refactoring of this complex PHP method
I have one complex method with 1890 paths. I don't know how can be this refactored. Can somebody add some tips about it? Maybe the MySQL table structure is wrong.
...
1
vote
0answers
18 views
Application Class Security
Is my Application.php class secure for continuing development?
The Application.php acts as a registry for the whole application. I tried not to rewrite already working code that is being pulled from ...
4
votes
4answers
487 views
Two while for the same query
If I have to loop results of a query echoing first all fields of a column, then echoing something not to loop, then fields of another column.
...
3
votes
1answer
51 views
1
vote
0answers
26 views
DMZ passthru script
I have a server that cannot be connected to from the internet, but I need to get some info to it. I have another server that can, so I have a simple passthru script that I want to see if you all think ...
2
votes
2answers
53 views
Admin page select function
I am using this script to get the admin pages via this query string ?page= once the admin is logged in.
Just needing a review, opinions
Function:
...
4
votes
2answers
50 views
Dynamic array of Years
I wanted to make a dynamic select statement from this year to 10 years. This gets the job done, but I feel like it's a little much.
...
1
vote
2answers
53 views
Lock a process in PHP
We had a situation where it was necessary that a script only be running in one process at a time.
The solution was to make a "LockByProcess" class that checks a database for an existing process, and ...
6
votes
3answers
306 views
Functions to escape CSS rules in PHP
Some context
I've been tasked with supplying an escaping function to arbitrary CSS values that are entered through a form. The goals and caveats are:
I know it's bad practice to let users input ...
1
vote
1answer
53 views
More efficient way to loop through an object
There's a part in my page where you can add, edit or delete school details, and it wasn't supposed to save entries to the database until the user hits Enter, so I save all data in an object first.
My ...
4
votes
2answers
66 views
Finite Element Method analysis
Please take a look at this class and point out its flaws. I am developing a simple Finite Element Method analysis with PHP.
What this class basically does:
Given an input set (coordinates, ...
1
vote
1answer
49 views
Better PHP Autentication Class [closed]
Authentication and keeping information secure is my goal with writing my Authentication class while making sure it is extendable completely as possible over making it usable for anything over just ...
4
votes
1answer
105 views
7
votes
1answer
89 views
Login system, PDO and me
I have run into a bit of a dilemma. Binding user input and building a prepared statement is all well and good, but what if I need the user input as a variable for a compare?
Can I just create a ...
3
votes
2answers
148 views
Updating necessary data using just one function
My objective is to update necessary data using one function instead of having different functions to update different fields. So, I've created one and I think this is not really elegant, efficient or ...
4
votes
2answers
57 views
Form builder improvment
What can I improve in this form builder? I'm looking for code review, optimization, and best practices.
...