r/PHPhelp • • Jul 21 '17

First PHP project - looking for advice

8 Upvotes

Hey,

This subject has been discussed over and over and I read a lot about it but still can't decide for my specific need. I've started my first PHP project - a "wine cellar inventory" webapp which will probably just be opened to a limited amount of users for personal use. If it's stable and polished enough it will be opened to the public. I've started this project "from scratch", with no framework. I am beginning to feel the need for structure, hence I will definitely refactor to MVC pattern which I'm just starting to understand. I found a nice course based on Silex and I've been wondering : do I need a framework ?

I've already got user registration, login/logout, password recovery done and I understood if I go with a framework I will probably need to rewrite all of this with the framework, which is a bit painful to accept given the hours spent on this, but anyway this is not important. I now have enough functionalities to release a v1, just need to finish css work and it will be ready. I'm concerned about cleanness of the code, even though I will be the only person working on this project. Is going the "MVC with raw php" way enough ? Should I use a framework and why ? Finally if the answer is yes, I can't decide between Silex and Slim, do you have any recommandation regarding the type of webapp I am working on ?


r/PHPhelp • • Jun 01 '17

Writing a large algorithm, is there a better way than using a hundred switch statements? Is this bad practice or the only way to do it?

8 Upvotes

I'm writing an algorithm for an MMO gear optimization site that has to take a lot of things into account. I am wondering if using a bunch of switch statements is considered bad practice, or if it's the only way to get the job done.

An example is the user will input each item equipped in each gear slot, what their gameplay goals are, etc. and I will then process that to show if their next goal should be a gear upgrade (and which of the 10 slots would be most beneficial based on the items stats), or if they should focus on increasing their energy, or if they should focus on doing one of the 5 other things available (of which some would be broken down into even more switch statements depending on their current progression).

I can provide a more detailed breakdown when I get home, I'm stuck in a traffic jam on mobile right now so I figured I may as well post this to see if this would be enough information to get an answer.

Thanks!


r/PHPhelp • • Mar 13 '17

I would like to create a PHP web application, which has a mathematical analysis portion best suited to python or R. What's the best way to incorporate either Python or R?

8 Upvotes

Hi,

Im building an app using Laravel (only on the modelling phase) and Im just thinking how easy/hard it would for users to enter data, maybe large amounts of data, have calculations performed in R or Python, have the results in either graphs or text passed back to the user in the Python web app.

Could someone please point me in the right direction to determine the best way I could do that? Or would there be a different web progmming language I could use? THanks!


r/PHPhelp • • Jan 24 '17

Solved Does negating a non-boolean object have meaning in PHP?

8 Upvotes

I'm new at PHP, and I've come across a statement that doesn't correspond to anything I recognize from my experience with any other object-oriented language:

if(!$result->fetch_object()){ ... }

The fetch_object() method of the MySQLi extension returns an object with string properties, at least according to the manual. It does not return a boolean variable.

What does it mean to negate this non-boolean result and use it as an if-conditional? I've been searching all day, and I can't find anything that explains it. Thank you!


r/PHPhelp • • Jan 10 '17

Best method for validating a date?

8 Upvotes

I have a form that will submit dates as "yyyy-mm-dd" if the user uses the date picker, but if they go ahead and enter their date manually, I need to catch this (I think).

I'm stuck with this hacked together function:

http://pastebin.com/iGY043Fs

It works. But I'm just questioning it a little.

The date is destined for a MySQL TIMESTAMP field, so I could just pass the data to that without validating, but I want to give the user a readable error if they're putting in something that won't work.

Thoughts?


r/PHPhelp • • Dec 14 '16

Upload large quantity of files via FTP and show progress

8 Upvotes

I've written a PHP script thats purpose is for uploading a local folder (containing thousands of files/sub-folders) to a remote FTP server. The script itself works without issue and does exactly as intended, however the code starts immediately upon page load, which prevents the rest of the HTML from being displayed until the process has been completed. As such, I am unable to show the actual progress to the end-user so they are able to see what is actually happening.

As a workaround, I attempted to split it into AJAX. Moving the createDirectory() and uploadFile() methods to a PHP file and calling them that way. As AJAX doesn't stop the thread until it receives a response though, it also doesn't work as intended.

My question is, is there any way to do with with PHP but relay the progress of the loop to the end user while its happening? I believe I would have to somehow delay the PHP from running until the HTML has loaded.

if (!file_exists($source_directory))
{
	echo '<script type="text/javascript">logMessage("Source media not found. Please contact support.")</script>';
	exit;
}
else
{
	function ftp_uploadDirectory($conn_id, $src_dir, $dst_dir)
	{
		$d = dir($src_dir);
		while($file = $d->read())
		{
			// To Prevent an Infinite Loop
			if ($file != "." && $file != "..")
			{
				// Check if this is a directory
				if (is_dir($src_dir."/".$file))
				{
					if (!@ftp_chdir($conn_id, $dst_dir."/".$file))
					{
						// Create directory that does not exist
						@ftp_mkdir($conn_id, $dst_dir."/".$file);
						echo '<script type="text/javascript">logMessage("Created Directory: ' . $dst_dir."/".$file . '")</script>';
					}
					
					// Recursive Part
					ftp_uploadDirectory($conn_id, $src_dir."/".$file, $dst_dir."/".$file);
				}
				else
				{
					// Upload the file
					$upload = ftp_put($conn_id, $dst_dir."/".$file, $src_dir."/".$file, FTP_BINARY);
					echo '<script type="text/javascript">logMessage("Uploaded File: ' . $dst_dir."/".$file . '")</script>';
				}
			}
		}
		
		$d->close();
	}
	
	foreach ($_SESSION['servers'] as $server)
	{
		if ($server['whmcs_id'] == $server_id)
		{
			$mcmyadmin = new McMyAdmin($server['mcma_user'], $server['mcma_pass'], $server['mcma_ip'], $server['mcma_port']);
			$mcmyadmin->stopServer();

			$ftp_hostname = $server['mcma_ip'];
			$ftp_gameport = intval($server['mcma_port']) - 2;
			$ftp_port = FTP_PORT;
			$ftp_username = $server['mcma_user'];
			$ftp_password = $server['mcma_pass'];
			
			$destination_directory = '/' . $ftp_hostname . '_' . $ftp_gameport;
			
			$ftp_connection = ftp_connect($ftp_hostname, $ftp_port);
			$ftp_login = ftp_login($ftp_connection, $ftp_username, $ftp_password);
			
			if((!$ftp_connection) || (!$ftp_login))
			{ 
				echo "Failed to establish FTP Connection for installation.";
				die();
			}
			
			// turn passive mode on
			ftp_pasv($ftp_connection, true);
			
			ftp_uploadDirectory($ftp_connection, $source_directory, $destination_directory);
			
			ftp_close($ftp_connection);
		}
	}
}

r/PHPhelp • • Nov 26 '16

Possible to convert your PHP website to software?

8 Upvotes

So it can be used offline on a computer. People install it and they have the exact website with the PHP functionalities on their computer.

Is this possible and if so, how?

Thanks, Rookie (Drag&Drop developer)


r/PHPhelp • • Jul 27 '16

What are some extremely useful functions everyone should know?

8 Upvotes

I have just started programming with PHP through Codecademy, so if it's really technical, please ELI5.

Also, what resources besides Codecademy would you recommend for practicing/learning more PHP?


r/PHPhelp • • Jun 19 '16

Correct way to implement a class of anonymous functions?

8 Upvotes

Perhaps this is a more of a software engineering question, but I think it is a issue that undoubtedly involves php, in that I am constrained to using php 5.4. Essentially, I am trying to set up a class of anonymous functions that are used only for validating specific elements of a form (I'll deem this class the "problem class"). So essentially there will be a intermediary class that will take an array of strings where these strings will indicate what needs to be validated. For example, "name", "phone" will be examples of input string this intermediary class will get the appropriate function from the problem class and place them in an array and return that array so the functions can be used (E.G "phone" will return a function that can validate a phone number). The problem class itself I am considering two different methods one will be to initialize an array or some data structure and then store the functions in the data structure and then use appropriate methods to return the items in the data structure or skip the data structure path and just return local variables that are anonymous functions. Where I am currently leaning towards the latter method. However, is there a more elegant way of implementing my idea?


r/PHPhelp • • May 25 '16

recovering a php website from a hacker

8 Upvotes

...throw-away account for obvious reasons...

last month we discovered that our website got hacked and was being used for serving ransomeware. we've deleted their files from our server and have been monitoring it to see how they got in, but so far nothing

we are a fully custom PHP site (not wordpress or such), so it isn't obvious how the hacker knew how to get the malware on the site.

my boss thinks we need a security expert to review our code for vulnerabilities. having never hired a security person before, what should I look for? what are some red flags to look for? more importantly, what people/teams should I avoid?

thanks in advance!

edit: we're not concerned with removing malware, we're concerned with finding how the hacker got in in the first place, and we have money to hire an expert, but we don't know who to hire or what questions to ask


r/PHPhelp • • Nov 14 '15

Should I avoid session variables?

8 Upvotes

So I've been learning PHP in school, and our teacher really, really likes session variables. However, I have a web developer friend who says you shouldn't use session variables because...

As a rule of thumb, storing things in the session is discouraged, because it does not scale well (the server runs out of session storage). Ideally your design should be stateless on the server. i.e. no session data.

Since I'm really new at this, do any professional developers on here have a stance on this issue?


r/PHPhelp • • Oct 28 '14

Critique my code please

8 Upvotes

Hi. Tried some php coding last year and ditched it in favour of python, but want to get back to it. Could anyone have a look and let me know how bad/good is it? Many thanks.

https://github.com/mprz/DomainAgent


r/PHPhelp • • Jul 26 '11

array question

8 Upvotes

New to php

function ReturnsArrayNotEmpty()...

Why can't I reference elements in the array like the following:

$value = $this->ReturnsArrayNotEmpty()[0];

?

Whereas, this works fine,

$value = $this->ReturnsArrayNotEmpty(); $another = $value[0];


r/PHPhelp • • Jul 12 '26

Copy Paste Problem on windows

7 Upvotes

Sorry I dunno if this is the right place to post this, I have no clue and php, SQL all that stuff but I'm having this problem with copying and pasting. If I try to copy and paste something I keep getting this code.

<br />

<b>Fatal error</b>: Uncaught mysqli_sql_exception: Too many connections in /www/wwwroot/clip-stash.beer/config.php:6

Stack trace:

#0 /www/wwwroot/clip-stash.beer/config.php(6): mysqli-&gt;__construct()

#1 /www/wwwroot/clip-stash.beer/api/index.php(6): require('...')

#2 {main}

thrown in <b>/www/wwwroot/clip-stash.beer/config.php</b> on line <b>6</b><br />

I have absolutely no idea what it means. I tried googling but its just leading me to stuff about SQL servers and stuff which I have absolutely no clue about. Am I being hacked or something? Hopefully someone can help as I can't copy and paste anything atm. Again sorry if this is the wrong place.


r/PHPhelp • • Apr 19 '26

upgrading vanilla php 5.4 to 8.x with laravel 13

7 Upvotes

Hey guys. I'm in a small company where i'm basically the "guy that does technology", be it data sceince, backend, front end and everything in between.

My boss just asked me to upgrade our legacy php 5.4 crm and I think I'll just bump it all the way to latest stable (8.4?) with laravel 13, because why not (why not?).

I have no prior experience in such migrations and honestly not native in php at all. I read and figured I should use Rector, phpstan and a sniffer. I setup composer and got a running php 5.6 docker environment for testing.

I will make use of lots of claude code, first to complete test coverage for our app.

If anyone here thinks they can be available for questions i might have in the process, via mail or whatsapp, i would super appriciate that.

Our software was built by a non-existant company and I also consider a relativley cheap option to help us with this (Shift?) so i am definitley open to hear either "dont do it youll fuck everything up" or "yea sure it can be done, here are your tools: x y z", or just "pay this service, theyll do it for ya". idk. im honestly a bit scared, as i feel it's outside of my skillset, and there is nobody to consult with.

Yann


r/PHPhelp • • Mar 16 '26

Game Dev Learning PHP, Looking For Info About What A Couple Things Do/Mean

7 Upvotes

I'm learning PHP/SQL, and so far, I don't think i'm doing too bad! But I hit a point where I have to ask what a couple functions/whatever do/mean/are for. For context, what I'm doing is pulling from the database tables, I got to "WHERE created_date =" which is the column I made, but my base/engine is using variable $product_id, which = isset($_GET['product'] ? (int)$_GET['product'] : null;

Now, I understand isset, but I can't find the defining of $_GET to know what it does, and I don't understand what ['product'] is, I don't see it defined, can someone please explain what something in the [''] means/does and why/what for? That way I understand.

Also, if someone can tell me a way I can write a new var, that'll pull the data from that table column, instead of deciphering this, cloning it, and basically doing that anyways, it would be a HUGE help. But because I wanna learn, I would like to know what these syntaxes mean/do so I better understand the program.

I also have several variables that are like $comments[4], in my video game programming, "Name[Index of 0-infinity] is an array. Is this also an array in PHP? If so, I already kind of understand. But I wanna be sure.

I think that's all I need to know for now! I'm not looking for someone to write my code for me, just help me understand it better so I can do for myself! I tried to explain what I understand to show my competency to prove that, so any of you masters that are willing to help explain, I would very much appreciate it! I've learned a LOT in the last 48 hours just by asking questions like this and a few YouTube videos! Please help me keep it up!!


r/PHPhelp • • Dec 25 '25

Force phpdoc @throws tag to use FQN

7 Upvotes

In a larger PHP project, I document exceptions using Phpdoc's throws tag. I want FQN to be used for this.

Does anyone know which CLI tool I can use to check this and, if necessary, force it? I already use PHPStan and PHP CS Fixer.

Edit: I always want FQN in throws tags, regardless of whether the class was imported via use.


r/PHPhelp • • Dec 11 '25

How can I land a remote PHP/Symfony developer job? Any tips?

7 Upvotes

Hey everyone,

I’ve been working fully remotely as a PHP/Symfony developer for about 4+ years now. I’m starting to look around for new opportunities, but the market feels tighter than it used to be.

For those of you doing remote backend work:

  • Where are you finding the best-quality remote PHP/Symfony roles lately?

  • Are there specific job boards, agencies, or platforms worth focusing on?

  • What actually helps you stand out when applying as a remote dev? (Portfolio? OSS contributions? Certifications? Something else?)

  • Are companies shifting away from fully remote for PHP roles, or is it just more competitive now?

I’m solid with Symfony, API Platform, Docker, CI/CD, and general backend architecture, just trying to figure out the smartest path to land the next good remote gig.

Any advice from people who’ve navigated this recently would be super appreciated!


r/PHPhelp • • Nov 02 '25

php vs other

7 Upvotes

Hello

There is a topic I see in many places that say that PHP is no longer modern, go to node.js, python

I have no experience myself

I have no attachment to languages ​​and frameworks

But I was asked what you would recommend for 2025 and beyond

My projects are personal and my goal is not the job market or recruitment, I just want my system to grow and my users not to be too fragmented


r/PHPhelp • • Aug 21 '25

Solved Quick question about input sanitization

7 Upvotes

I see quite a lot of conflicting info on input sanitization, primarily because some methods have been deprecated since guides have been written online. Am I correct when I infer that the one correct way to sanitize an integer and a text is, respectively,

$integer = filter_input(INPUT_POST, "integer", FILTER_VALIDATE_INT);

and

$string = trim(strip_tags($_POST["string"] ?? ""));

r/PHPhelp • • Nov 14 '24

I don't know how to structure a PHP web app.

7 Upvotes

Hello. I'm following a tutorial on YouTube for a project I'm working on.

However, following these steps made me realize I don't know how to structure a PHP web app. Like, what does index.php do? Which folders am I supposed to create and what do they hold? When do I make a feature its own dedicated file and when do I simply insert it into an existing one?

Can you provide me with a resource for how to learn about this?


r/PHPhelp • • Oct 28 '24

Confused between Models and Data Transfer Object (DTO)

7 Upvotes

I'm learning PHP and trying to log activities of the user or system for auditing purposes.

I'm having a hard time understanding the MVC framework when it comes to Models and DTOs.

I'm capturing a few things as an example:

- user or system
- action taken
- date and time

My model currently looks something like:

public function getUser()
{
    return $this->user;
}

public function setUser(string $user)
{
    $this->user = $user;
}

I then have another class that logs the user, action, and timestamp to a MySQL database.

Am I supposed to call the Model to log this information by adding another method like

public function log()
{
    $this->db->insert($this->getUser);
}

so my logging class then looks like

public function logAction($event)
{
    $this->event = new EventModel();
    $this->event->setUser('Michael');
    $this->event->log();
}

or do I create another class that handles the logging to database specifically - like a service or handler?


r/PHPhelp • • Oct 23 '24

Static analysis of magic jsonSerialize() calls

7 Upvotes

So we've got classes that implement JsonSerializable and implement its jsonSerialize() method. The problem is that, at least in PhpStorm, there doesn't seem to be any way to use static analysis to find where the method is called (which normally only happens when you pass a JsonSerializable object to json_encode(). I googled around and couldn't even find any discussion of this issue, much less what to do about it. Any thoughts?


r/PHPhelp • • Oct 01 '24

index.php route with params

7 Upvotes

hello everyone,

I'm a newbie and I'm looking for a way to have an index.php that routes to the pages of my personal "site".

At the moment I'm using herd for convenience since it has everything packaged (I don't use laravel, only smarty).

From what I understood from searching on the internet herd already has the rewrite for nginx that redirects requests to index.php, so I just need to write a correct index.php.

From a tutorial I found this implementation:

<?PHP

$request = $_SERVER['REQUEST_URI'];

$viewDir = '/views/';

switch ($request) {

case '':

case '/':

require __DIR__ . $viewDir . 'home.php';

break;

case '/views/users':

require __DIR__ . $viewDir . 'users.php';

break;

case '/contact':

require __DIR__ . $viewDir . 'contact.php';

break;

default:

http_response_code(404);

require __DIR__ . $viewDir . '404.php';

}

?>

the problem is that if I call http://<mysite>.test/views/users?id=1 it always gives me the 404.php page because I pass variables on the url... what is the correct way to manage the routes on the index.php?

(I could simply do a substring up to the ? but it doesn't seem very elegant...)

thanks to everyone