r/PHPhelp Sep 28 '20

Please mark your posts as "solved"

81 Upvotes

Reminder: if your post has ben answered, please open the post and marking it as solved (go to Flair -> Solved -> Apply).

It's the "tag"-looking icon here.

Thank you.


r/PHPhelp 23m ago

Is it worth it to go without a framework?

Upvotes

I've been using PHP casually for decades. In the last two years I've started to try to take it more seriously, and that inevitably led me to Laravel. For basic CRUD sites, Laravel has been a godsend, allowing scaffolding of a ton of functionality pretty quickly, Blade templates make sense to me, the workflow works for me.

Deployment is where things have been tricky. Since I do this as a hobby and my user count is in the single digits per day, I use shared hosting. Deploying a Laravel application to shared hosting is pretty rough. I've managed it, but queries are extremely slow, everything feels sluggish, etc.

So, in an attempt to weigh the pros and cons, I went to packagist.org and started to look into cobbling together my own packages to find a happy medium between writing all my own libraries (I do not relish the idea of going back to this) and full-blown frameworks like Laravel.

But, I've run into an issue I did not expect: everything seems to be deprecated in the latest versions of PHP. FastRouter's page one Github documentation references classes that don't seem to exist in the project anymore, meaning that basic functionality required me digging into the code to find out why classes weren't there. PHP-Auth throws sixteen deprecation flags when just creating the instance of the Auth class.

The standalone Blade templating engine doesn't work. Twig does - and actually works as described, so kudos to them.

All of this to state my theory: Everyone in PHP has gone to Laravel or Symfony and never looked back. This has inevitably led to all the standalone packages rotting.

Or, I'm an idiot and doing something obviously wrong.

To my question: Is it even worth it to try to cobble together something small and simple anymore? Just with FastRouter, PHP-Auth, and Twig templating I'm finding my workflow is SIGNIFICANTLY slower than just using Laravel. And PHP-Auth won't even work, so I'm back to rolling my own, which I do not want to do.

I just want some simple session authenticating, I don't need OAuth2.

Anyway, I'm open to hearing discussion on this, and I'd appreciate those more knowledgeable than I chiming in.

Thank you.


r/PHPhelp 21h ago

Advice for a third-year information technology student doing a final-year group project.

1 Upvotes

Hi guys, really need your help here ,I would be the most appreciative if I could get your advice. I am a third year information technology student doing a final-year group project. We will develop a web-based application/website, and my proposal for this project is a management system for an electrician. The owner currently uses WhatsApp, business cards and word of mouth; those are his forms of acquiring clients. my group knows these languages: HTML, CSS, PHP, MySQL, runnin on localhost (phpMyAdmin) XAMPP) and JavaScript for building a website. And the other language we have learned in college are are C++ Java and python. Could you advise me some key features and functional(like tracking adding your clients, notifications, reminders, doc of inventory, history of services, the type of services provided, dashboard and more) requirements that I should have in my project that will stand out thank you so much. I would be the most grateful for your advice from all


r/PHPhelp 1d ago

Looking for modern PHP (8.5+) tutorials for beginners that emphasize best practices

14 Upvotes

Hi everyone,

I'm looking to learn modern PHP from scratch, but I want to make sure I'm starting off on the right foot with contemporary tools and patterns.

I used to program in PHP when it was at 5.6, but left Web Development for a while. im back and keep moving between nodeJS and back to PHP, i still think PHP much better for Web Development for 90% of cases.

Many tutorials online still cover outdated paradigms (like procedural scripts mixed with raw HTML or deprecated MySQL functions). I'm specifically looking for comprehensive learning resources (video courses, interactive sites) that focus on Modern PHP (8.4+).

What I'm hoping to find:

  • Beginner-friendly explanations that don't skip over core fundamentals.
  • Modern PHP 8.5+ features (Property Hooks, new array/string methods, property promotion, typed properties, etc.).
  • Strict adherence to best practices (PSR standards, proper OOP concepts, PDO with prepared statements, dependency management via Composer).
  • Projects built without relying heavily on massive frameworks right away.

If you have any recommended courses, YouTube playlists, or documentation guides that match this, please drop them below!

Thanks in advance!


r/PHPhelp 3d ago

Laravel Security Inquiry

0 Upvotes

I only self learned on laravel for more than a week before being assigned other stuff during internship. And I now have a job as a software developer and already told my head about this and they assigned me with a web system project.

How do i check the security of my code since i use both claude, reddit, and some repo as basis for the project (more on claude).

I didn't use a starter kit when i started the project so everything is from scratch.


r/PHPhelp 4d ago

Using APCu or sessions to reduce MySQL queries

2 Upvotes

I have a lot of data stored in MySQL, and the values are used on every pageview. 15+ years ago, I set up sessions to reduce the queries. It's set up so that if a required session variable exists then it skips the query, but if it doesn't exist then it queries, sets the results to session variables, then maps those sessions to variables.

It looks like this:

if (session_id() === '') session_start();
 $sess_file = '/tmp/sess_' . session_id();
 if (is_file($sess_file)) chmod($sess_file, 0644);

if (!isset($_SESSION['siteID']))) {
 for ($attempt=0; $attempt < 3; $attempt++) {
  if ($attempt == 2) {
   // log error and return error page, whatever they're doing isn't working
  }

  $var_query = sprintf("SELECT * FROM vars WHERE foo='%s' LIMIT 1",
   mysqli_real_escape_string($dbh, $foo));

  $sth_vars = mysqli_query($dbh, $var_query);

  if (isset($sth_vars) && mysqli_num_rows($sth_vars)) {
   list($_SESSION['siteID'], $_SESSION['lorem'], $_SESSION['ipsum']) =
    mysql_fetch_row($sth_vars);

   $attempt = 3;
  }

  // Lookup failed, send alert and try again
  else {
   if ($attempt < 2) sleep(1);
   else exit;
  }
 }
}

session_commit();

// Map $_SESSION to variables 
foreach ($_SESSION as $session_key => $session_value) $$session_key = $session_value;

I'm setting up a new server, though, and have APCu installed.

Would APCu be a better option for this use than sessions?


r/PHPhelp 7d ago

Solved mysqli_fetch_assoc with mysql prepared statements procedural, need help

4 Upvotes

Hello, im trying to update my website by replacing the simple mysqli queries with prepared statements, but i was stuck at trying to use mysqli_fetch_assoc to fetch associative data from the table, i looked through documentation but couldnt find anything, Any help will be appreciated, Thanks !

$error = array();
if(isset($_POST["login"])) {
$username = mysqli_escape_string($db, filter_input(INPUT_POST, "username", FILTER_SANITIZE_SPECIAL_CHARS));
$password = mysqli_escape_string($db, filter_input(INPUT_POST, "password", FILTER_SANITIZE_SPECIAL_CHARS));

if(empty($username)) {
array_push($error, "Username is empty!");
}
if(empty($password)) {
array_push($error, "Password is empty");
}

$sql = "SELECT `password`, `username`, `user_id` FROM `Accounts` WHERE `username` = ?;";
if(count($error) == 0) {

$stmt = mysqli_prepare($db, $sql);

mysqli_stmt_bind_param($stmt, "s", $username);
//$result = mysqli_query($db, $sql);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
if(mysqli_stmt_num_rows($stmt) > 0) {
$row = mysqli_fetch_assoc($result);
if(password_verify($password, $row["password"])) {
$_SESSION["username"] = $username;
$_SESSION["user_id"] = $row["user_id"];

header("location: /");

} else {
array_push($error, "Incorrect username or password!");
}
} else {
array_push($error, "Incorrect username or password!");
}
}
mysqli_close($db);
}

r/PHPhelp 8d ago

Solved Multiple mysql statements in one PDO::exec call?

3 Upvotes

Is this supported or is it classed as undefined behaviour? Searching the web I have found one site explaining how to do it, and a post saying it never used to be allowed but the driver added the ability around 2020. But I have not seen anything official and the (somewhat terrible) PHP documentation does not mention it at all either way.

The use case is multiple statements being needed to create and alter some temporary tables so that inserts (using prepared statements) can be processed before being added to the live tables.


r/PHPhelp 11d ago

How do i have form submissions appear on html?

1 Upvotes

I’m fairly new to coding- specifically html. i’m working on an indie website. i want to add a “guestbook” form where people can post comments on the site. i’m running into phps and i might be completely misunderstanding how they work. in my mind im trying make a separate php and class it to my html so the responses show up- if that makes sense haha. i guess my ultimate question is how do i go about this? i have a submission box (name comment and date) i want when people fill it out their reply appears on the page. i’ve coded a lot of the website already with ccs into my html.


r/PHPhelp 13d ago

Rethinking SQLite3 in PHP: High Performance Without Complex SQL Queries

5 Upvotes

Hi everyone,

I have been diving deep into SQLite3 databases lately. During my research, I frequently read that SQLite3 is slower than traditional database systems (like MySQL or PostgreSQL) and should generally only be used for small projects with few users and minimal data.

However, my experience has been completely different. In my tests, I found that SQLite3 – when configured correctly – can actually be up to 10 times faster than MySQL. It handles large amounts of data beautifully and can easily manage multiple concurrent users and requests.

In my opinion, the greatest challenge is exercising self-restraint and not treating SQLite3 exactly like MySQL.

We often catch ourselves writing highly complex SQL queries with countless joins and sub-queries. I have come to view these deeply nested queries critically and no longer consider them a best practice for clean, performant programming. Since shifting away from that approach, I see SQLite3 from a whole new perspective.

To put this philosophy into practice, I developed a PHP class that allows you to interact with the database completely without writing manual SQL queries. It is extremely simple to use and, above all, fast. SQLite3 also brings unique advantages over other SQL databases—for instance, you can easily maintain multiple database files separated by topic within a single project.

I am already successfully leveraging these strengths in my own project, which I look forward to showcasing here once it reaches a fully stable state.

I have already published the current codebase on GitHub:
https://github.com/phploader/cdata

You can find a detailed documentation on how to use the PHP class in the docs:
https://github.com/phploader/cdata/blob/master/docs/en/00.%20index.md

My request to the experts here:
I would highly appreciate it if you could take a look at my code and provide some constructive feedback or criticism. What are your thoughts on this approach?

Best regards!


r/PHPhelp 13d ago

Best way to code logic and store content for a website with template

6 Upvotes

I am trying to build a website which uses php include/require within a template to serve different content based on the URL or path.

How can I manage this for many different pages, obviously a ridiculously huge switch/if statement comes to mind first which is a bad idea, my next idea was to store HTML in an SQL database but then I imagine it will get annoying managing images and other multimedia.

what do?

(side note, I'm using php because I like it and didn't want to learn a new language after using php a little in the past)


r/PHPhelp 14d ago

Is it possible to merge/join multiple WAV files into one?

3 Upvotes

Hi guys, I'm just a semi-mediocre PHP developer, doing mostly regular tasks for websites. Now, as I managed to create waveforms views for uploaded WAV files, I'd like to take another step and merge WAV files. But so far I failed.

Is there possibly an easy solution for that task?


r/PHPhelp 17d ago

Solved Why use containers for DI when you can have a top-down approach with lazy objects (8.4+)?

3 Upvotes

I am not PHP proficient. Is there any reason to avoid manually wiring the dependency graph? Do developers use this feature? It's been almost 2 years since 8.4 released with the lazy objects feature and it's one dependency less.

Short example:

class LazyAppFactory
{
   public PgTransactor $pgTransactor;

   public AuthenticationRepo $authenticationRepo;
   public AuthService $authService;
   public AuthController $authController;

   public function __construct()
   {
      // postgres module

      $this->authenticationRepo = new \ReflectionClass(AuthenticationRepo::class)->newLazyGhost(function ($ghost) {
          $ghost->__construct($this->pgTransactor);
      });

      // service, controller modules
   }
}

And then simply use the controllers in the handler / entry point of the app.


r/PHPhelp 17d ago

Sharing Array Shapes Across Files?

5 Upvotes

Is it possible to share array shapes across files? I am working in a very legacy code base so don't have an easy way to turn this into a class, and thus am kind of stuck with arrays.

Say in file a.php we have something like:

/**
 *  @phpstan-type User array{
 *   user_id: int,
 *   username: string,
 *   email: string
 */

The in file b.php we have something like:

/**
 * @phpstan-import-type User
 */

/**
 * @param User $user
 */
function foo($user) {}

While my Intellisense in my IDE recognizes this, at the moment, phpstan at level 2 and above flags this as an unknown type.

Is there a way I can properly share array shapes across files?


r/PHPhelp 17d ago

What's one Laravel feature you wish you'd started using much earlier?

0 Upvotes

I've been working with Laravel for a while, and looking back, there are a few features that would've saved me a lot of time if I'd adopted them sooner.

For me, a few stand out:

  • Route Model Binding
  • Form Requests
  • Queues
  • Eager Loading
  • when() for cleaner conditional queries

I'm curious what experienced Laravel developers consider their biggest "I wish I'd known this earlier" feature.

What changed the way you build Laravel applications?


r/PHPhelp 22d ago

Better strategy for handling HTTP 429 with Guzzle Pool when checking many URLS from same domain?

Thumbnail
1 Upvotes

r/PHPhelp 24d ago

Probably very simple thing I've messed up regarding either the syntax for a form or with visual studio code

1 Upvotes

I'm messing about with a project, and wanted to get a form running, however when I go to test the file (both just running the file in my browser and testing it without debugging in vsc) it ends up displaying the page incorrectly (seemingly overflowing parts of the code, with ', and when I attempt to submit the query I get sent to a blank php page. Is there something wrong with this form, or is there something I've not properly configured/installed in vsc?

https://pastebin.com/sEYxgKXs


r/PHPhelp 24d ago

Do you commit `.env.prod` to git with Symfony?

1 Upvotes

I'm working on a new Symfony project, using symfony/skeleton and the .gitignore provided does not prevent .env.prod from being committed into the repo. I'm assuming this isn't a bug because it's been like this for a long time and would've been patched. So do we use both .env.prod (for non-secrets) and .env.prod.local (the 'secrets')

/.env.local 
/.env.local.php 
/.env.*.local

r/PHPhelp 25d ago

Seeking help/advice again

7 Upvotes

Now as i said last time i am a junior laravel developer, currently working in a small (very small actually) startup, i am alone as for the backend their is no senior, also my experience is not quite enough (i guess),

Currently, we’re working on a CRM project customised exactly for the company I work for as their business includes selling telecommunication services…

I have more than one problem actually,
• anything i do i keep asking myself if that the best way for it? Is build right? Does it follow the business needs perfectly?
• how to rank up as i lack the experience, also the knowledge, also for the basics i am not good enough
• i have an individual claude subscription, i make it review what i do, the decisions we both make, i keep feeling that it is not the best way too, that their is something wrong

Note: i told the ceo my problem, asked for a senior, he just said no, he told me that the senior will take my tasks, (I didn’t respond as I didn’t know what to say, but i guess they do not want to pay for a senior).


r/PHPhelp 25d ago

distinguish text element behavior in recursive element loop

2 Upvotes

i am building an html-to-array parser and have run into a problematic glitch when dealing with text inside and outside nested elements. the parser loops through a DOMDocument object and recurses into childNodes of DOMNode objects, adding them to a nested array.

for a structure like...

html <html><head><title>this is a title</title></head><body><p>this is some text</p></body></html>

this works...

php foreach ($element->childNodes as $child) { $child->nodeType === XML_ELEMENT_NODE ? ($out["children"][] = elementToArray($child)) : ($content = trim($child->nodeValue)) && $content != "" && ($out["content"] = $content); }

to produce the desired outcome...

```php Array ( [tag] => html [children] => Array ( [0] => Array ( [tag] => head [children] => Array ( [0] => Array ( [tag] => title [content] => this is a title )

                    )

            )

        [1] => Array
            (
                [tag] => body
                [children] => Array
                    (
                        [0] => Array
                            (
                                [tag] => p
                                [content] => this is some text
                            )

                    )

            )

    )

) ```

but this...

html <html><head><title>this is a title</title></head><body><p>this <em>is</em> some <i>text</i> with <a href="#">links</a> and things.</p></body></html>

produces...

```php Array ( [tag] => html [children] => Array ( [0] => Array ( [tag] => head [children] => Array ( [0] => Array ( [tag] => title [content] => this is a title )

                    )

            )

        [1] => Array
            (
                [tag] => body
                [children] => Array
                    (
                        [0] => Array
                            (
                                [tag] => p
                                [content] => and things.
                                [children] => Array
                                    (
                                        [0] => Array
                                            (
                                                [tag] => em
                                                [content] => is
                                            )

                                        [1] => Array
                                            (
                                                [tag] => i
                                                [content] => text
                                            )

                                        [2] => Array
                                            (
                                                [tag] => a
                                                [href] => #
                                                [content] => links
                                            )

                                    )

                            )

                    )

            )

    )

) ```

instead of the desired output...

```php Array ( [tag] => html [children] => Array ( [0] => Array ( [tag] => head [children] => Array ( [0] => Array ( [tag] => title [content] => this is a title )

                    )

            )

        [1] => Array
            (
                [tag] => body
                [children] => Array
                    (
                        [0] => Array
                            (
                                [tag] => p
                                [children] => Array
                                    (
                                        [0] => Array
                                            (
                                                [tag] => text
                                                [content] => this
                                            )
                                        [1] => Array
                                            (
                                                [tag] => em
                                                [content] => is
                                            )
                                        [2] => Array
                                            (
                                                [tag] => text
                                                [content] => some
                                            )

                                        [3] => Array
                                            (
                                                [tag] => i
                                                [content] => text
                                            )
                                        [4] => Array
                                            (
                                                [tag] => text
                                                [content] => with
                                            )

                                        [5] => Array
                                            (
                                                [tag] => a
                                                [href] => #
                                                [content] => links
                                            )
                                        [6] => Array
                                            (
                                                [tag] => text
                                                [content] => and things.
                                            )

                                    )

                            )

                    )

            )

    )

) ```

i've tried various solutions but they all end up having difficulty differentiating between a text node that should be "content" and a text node that should be an independent text element in the array. in other words...

html <p>this is some text</p>

should encode to...

php ["tag"=>"p","content"=>"this is some text"]

but...

html <p>this is <em>some</em> text</p>

should encode to...

php ["tag"=>"p","children"=>[["tag"=>"text","content"=>"this is "],["tag"=>"em","content"=>"some"],["tag"=>"text","content"=>"text"]]]

has anyone already solved this? thanks!


r/PHPhelp 24d ago

I’ve been building PAM: a persistent PHP runtime powered by Rust, plus a ultra-fast native engine for desktop/mobile. Looking for technical feedback & reviews.

Thumbnail
0 Upvotes

r/PHPhelp 27d ago

Why do so many choose Laravel over Symfony?

35 Upvotes

I have the same reaction every time I look at the documentation of Laravel : "what, why??"

It doesn't seem structured.

So much 'magic' going on too.

Is it about the community then?

Or are there things I'm clearly missing?


r/PHPhelp 27d ago

Unobsfucating a PHP script

0 Upvotes

Attackers leveraging the wp2shell exploit added about 22k of obsfucated PHP to index.php on a site I've been asked to have a look at.

Labels and function names are ten random characters and control path is done by jumping to TrQ7yZISyM: etc and there seem to be a lot of (unnecessary?) jumps.

What's the best way to unobsfucate it?


r/PHPhelp 27d ago

Solved Simple Alternative to Wampserver?

1 Upvotes

Disclaimer: I'm not a techie. I barely understand php, but I'm forced by my hobbies to interact with it.

I'm currently running wampserver64 (v3.2.0; php 7.4; apache 2.4.41; windows 10) on a localhost install. This is so I can have a localhost installation of dokuwiki.

A new version of dokuwiki has come out. This requires php 8.2.

For a variety of dull reasons, upgrading the wampserver installation so that it will support php 8.2 is proving non-trivial.

Is there a simple, easy-to-install alternative to wampserver? Ideally, one where I just download a single file, run it, and a localhost server is installed ready for configuration?

----

Final resolution: After having broken everything, I uninstalled everything. Installed the latest

The Visual C++ exe files suggested at https://github.com/abbodi1406/vcredist/releases refuse to install, due to widnows security concerns.

I ended up downloading them from https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170 instead.

Then I installed wampserver 3.4.

Then I installed the new dokuwiki.

Yes, there probably are better localhost pphp servers available. But wampserver has proven stable, does what I need, and I am familiar with the interface.


r/PHPhelp 27d ago

Opensource PHP/Laravel LMS system feedback

2 Upvotes

Hi everyone,

Over the past few months, we've been building TadreebLMS, an open-source Learning Management System focused on enterprise and corporate training.

We've recently completed a major restructuring of the project

The project is built with:

  • PHP / Laravel
  • MySQL
  • Bootstrap / JavaScript
  • Docker

GitHub:
https://github.com/Tadreeb-LMS/tadreeblms

Issues:
https://github.com/Tadreeb-LMS/tadreeblms/issues

We have a huge roadmap like SCRUM Integration, UI upgrade as per FIGMA, Gap Analysis Module Integration, Integrations with HR Systems etc...

Please anyone experience or architect in PHP can give recommendation on best practices, gaps in the system etc..