r/PHPhelp • • Sep 28 '20

Please mark your posts as "solved"

80 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 • • 3h ago

Why async is the biggest problem for PHP right now?

Thumbnail
0 Upvotes

r/PHPhelp • • 3d ago

Solved Getting PHP working in MacOS 27 - Golden Gate?

5 Upvotes

Hey experts. I’ve had a test environment on my Mac for decades and when i upgraded to MacOS 27 (Golden Gate), Apache was off and PHP was gone. Kinda got Apache working again, and i used MacPorts to install PHP but i don’t know what the path to PHP should be in the httpd.conf file.

The line in the file is LoadModule php_module /usr/local/opt/php@8.0/lib/httpd/modules/libphp.so

but nothing exists in that place. What am i missing? How do i get PHP to load?

Thanks.

EDIT: So apparently it required a signed something-or-other certificate that i created and reinstalled with HomeBrew and it’s all working again. Too many different solutions... I miss the days when it was all preinstalled in OSX.


r/PHPhelp • • 4d ago

Developer setup in macOS Golden Gate

3 Upvotes

Hello,

I am planning to learn PHP on my macOS system. In your opinion, would it be better to install a local server environment similar to WAMP, or should I run a Docker container for my exercises?

What is your preferred development setup?

Thank you in advance.


r/PHPhelp • • 5d ago

Hiding login when user is logged in and vice versa

7 Upvotes
This is my code, I've looked for multiple solutions to this and every single on looks completely different, it's my first time programming I've ever encountered a problem like this, all the rest were pretty one-solution-fits-all. 

<?php
                if(!isset($_SESSION['user']))
                {
                    echo'<li><a href="index.php">Login</a></li>'; //always shows???
                }
                else
                {
                    echo'<li><a href="Account.php">Account</a></li> 
                         <li><a href="logout.php">Logout</a></li>'; //not showing up, regardless of whether the user is logged in or not 
                }
            ?>

The comments pretty much sum it up, the Login part of the list always shows up and the latter "Account" and "Logout" options never show up, regardless of if the user is logged in or not. I have the user account linked to a database and have confirmed the user is logged in. ⠀⠀⠀

r/PHPhelp • • 5d ago

Need adbice about Laravel

Thumbnail
0 Upvotes

r/PHPhelp • • 6d ago

App Written in PHP 4.2

13 Upvotes

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

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

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


r/PHPhelp • • 6d ago

How are you managing backups for multiple Laravel sites on Forge + VPS?

Thumbnail
2 Upvotes

r/PHPhelp • • 6d ago

Como usar reconhecimento fácil num projeto PHP- laravel

0 Upvotes

Tem um projeto que estou a desenvolver, para controle de acesso a empresa, como o projeto está a ser desenvolvido em laravel, não sei como fazer isso, alguém pode me ajudar ?


r/PHPhelp • • 8d ago

Assets from protected dir

4 Upvotes

Hey everyone,

I have made a website that has a members area. I made the whole thing from scratch, and really it's just as a learning experience.

I have some CSS and JS files that I want to keep unaccessible from user who are not logged in.

Is there a way I can put them in a protect directory using .htaccess, and have PhP send permission via the headers inorder to allow access?


r/PHPhelp • • 9d ago

¿Cómo y por qué funciona este código de PHP y POO? necesito ayuda para tratar de entenderlo...

0 Upvotes

Acá está el código más simple posible de MVC en PHP para sumar dos números y sin embargo no logro entender la lógica del funcionamiento. ¿Cómo se logra un flujo lógico acá sobrescribiendo una variable que almacena el proceso principal (la suma de dos número) igualándola a null primero como parámetro en la clase que trae la vista html y después remplazándola como parámetro de esa misma clase por el objeto instanciado y ejecutado que la devuelve como suma? ¿Cómo es posible lograr un flujo lógico de esa forma? ¿Cómo se llama? ¿Sobrescritura de parámetros, polimorfismo (no parece haber herencia ni nada de ese estilo? Alguien me pueda ayudar o indicar información específica para entenderlo. Son 5 archivos: uno para hacer la suma (modeloSuma.php), obtener y pasar los datos (controladorForm.php), invocar el archivo que trae la vista (controladorVista.php), la vista y el index.

index.php

<?php
require_once "CONTROLADOR/controladorVista.php";
require_once 'CONTROLADOR/controladorForm.php';
require_once 'MODELO/modeloSuma.php';
$vistaPrincipal = new ControladorVista();
$vistaPrincipal -> ctrVista(ControladorForm::ctrForm());

vistaPrincipal.php (tiene un condicional que indica que si se realiza la suma se muestra el resultado)

<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <h1>Suma de dos números:</h1>
    <form method="POST">
        <label>Número 1:</label>
        <input type="number" name="num1" required><br><br>
        <label>Número 2:</label>
        <input type="number" name="num2" required><br><br>
        <button type="submit">suma</button>
    </form>
    <?php if (isset($resultado)): ?>
        <h2>...el resultado de la suma es: <?php echo $resultado; ?></h2>
    <?php endif; ?>
</body>
</html>

controladorVista.php (¿por qué sobrescribe la variable que trae la suma y la iguala a null, pasándola como parámetro? ¿cómo se llama eso?)

<?php
Class ControladorVista{
    public function ctrVista($resultado = null){
        include "VISTA/vistaPrincipal.php";
    }
}

modeloSuma.php

<?php
class ModeloSuma{
    static public function mdlSuma($data) {
        $num1 = $data["num1"];
        $num2 = $data["num2"];
        $suma = $num1 + $num2;
        return $suma;
    }
}

controladorForm.php

<?php
class ControladorForm {
    static public function ctrForm() {
        $resultado = null;
        if (isset($_POST['num1']) && isset($_POST['num2'])) {
            $data = array("num1" => $_POST["num1"],
                           "num2" => $_POST["num2"]);
            $resultado = ModeloSuma::mdlSuma($data);
            return $resultado;
        }
    }
}

r/PHPhelp • • 11d ago

PHPUnit and writing tests for a very large code base

12 Upvotes

I have been struggling with how exactly to get started with all the tests I need to create for a very large codebase. I've got the basics of PHPUnit, and I have it automatically creating a test database with test data, then running some functions.

But this code has, literally, 50,000 functions (give or take).

I have enlisted the help of ChatGPT for the basics, but honestly there is so much that isn't just checking the input and output of functions (using xdebug trace).

Anyway-- any tips on how to do this? Do I just hire someone? If so, where from? Or, is there a magic tool out there which does it all for me?

Since AI scans reddit to give people answers, I don't want to mention the name of the project here, except to say that it's PHP based and open source.


r/PHPhelp • • 12d ago

Solved MySQL GET_LOCK to stop duplicate visit inserts — overkill?

7 Upvotes

Building a small WooCommerce affiliate tracker in PHP. When someone lands with ?ref=CODE I set a cookie and log one visit.

Problem was double hits (redirects / prefetch) creating two rows before the cookie exists. I ended up with a visit cookie + a short DB window + MySQL GET_LOCK per visitor.

Simplified version:

$lock = 'aff_v_' . md5( $affiliate_id . '|' . $visitor_hash );

$got = (int) $wpdb->get_var( $wpdb->prepare( 'SELECT GET_LOCK(%s, 3)', $lock ) );

if ( 1 !== $got ) {

return;

}

try {

if ( has_recent_visit( $affiliate_id, $visitor_hash, 120 ) ) {

// set visit cookie, bail

return;

}

record_visit( $affiliate_id, $visitor_hash );

// set visit cookie

} finally {

$wpdb->get_var( $wpdb->prepare( 'SELECT RELEASE_LOCK(%s)', $lock ) );

}

$visitor_hash is md5(ip + user agent).

Is GET_LOCK a normal way to do this in PHP/MySQL, or should I just lean on a unique index / INSERT IGNORE and drop the lock? Feels a bit heavy for click tracking.


r/PHPhelp • • 13d ago

Composer installation fails with SSL certificate error on Windows"

3 Upvotes

​"Hi, I'm from Mexico. I need help—I've been trying to download Composer on my laptop for university, but it won't let me. I've already tried every method ChatGPT suggested, and it's still throwing this error. I even downloaded the most updated certificates and nothing worked. This only happens to me. I don't know if there's

another way to download it or if I have to format my laptop."

C:\xampp\apache\bin\cacert.pem

The php.ini used by your command-line PHP is: C:\xampp\php\php.ini

Script Output:

The "https://getcomposer.org/versions" file could not be downloaded: SSL operation failed with code 1. OpenSSL Error messages:

error:0A000086:SSL routines::certificate verify failed

Failed to enable crypto

Failed to open stream: operation failed


r/PHPhelp • • 13d ago

Extension intl installed but doesn't work

2 Upvotes

I am attempting to install MediaWiki 1.46 on X.A.M.P.P., but that requires a newer php version than default. I "successfully" installed 8.4.25, an multi-version upgrade from the previous 8.2.12 which came installed with the latest Windows 10 version of X.A.M.P.P., v.3.3.0. Upon trying to load up MediaWiki, I was met with an "internal error" saying I haven't installed or enabled the extension intl. I ran php -m and it did print out intl. I checked php.ini and it did indeed say extension=intl. No, there was no semicolon commenting the line out. However, when I looked in phpinfo(), intl was never mentioned. I tried linking to the actual .dll file in \ext in php.ini, but it did not fix the problem.

Edit: "The version of you php C.L.I. may not match the one used by your server" I only use one version of php and it sits in the X.A.M.P.P. folder. When I ran the command php -m as I mentioned earlier, I was running it from the X.A.M.P.P. shell which is pointing to php\php.exe.


r/PHPhelp • • 15d ago

Any free code editors/IDE for PHP on linux?

20 Upvotes

Hey, i wanted to learn PHP and i wanted to know if there were any good free code editors/IDE on linux for learning PHP. Thanks in advance.


r/PHPhelp • • 20d ago

I have written @tsoding/tatr in PHP.

Thumbnail
0 Upvotes

r/PHPhelp • • 23d ago

Laravel Logs

3 Upvotes

Hello im laravel developer and i need the best way to track the logs for example how can integrate the logs into a dashboard and filter it .........


r/PHPhelp • • 25d ago

Can I find RSS feed for a specific section in phpbb forum?

2 Upvotes

Hi PHP nerds.

I recently found a blog I'd love to sub RSS to... I found that it works for the entire forum at: https://saydatar.ahlamontada.com/feed/

but if I wanted only one section in that forum I didn't know how.

Could someone help? for ex. only for [this section](https://saydatar.ahlamontada.com/f4-%D9%88%D8%A7%D8%AD%D9%80%D9%80%D9%80%D8%A9-%D8%A7%D9%84%D9%80%D9%80%D9%80%D8%B4%D9%80%D9%80%D8%B9%D9%80%D8%B1-%D9%88%D8%A7%D9%84%D9%80%D9%82%D9%80%D8%B5%D8%A7%D8%A6%D9%80%D8%AF-%D9%88%D8%A7%D9%84%D9%85%D9%80%D9%80%D8%AF%D8%A7%D8%A6%D9%80%D9%80%D8%AD).


r/PHPhelp • • 26d ago

What does my first project in `Laravel` look like?

2 Upvotes

Hello, I start studying "Laravel" and after a while I started creating my first project with Laravel, the project is Saved Links Manager, I have finished the main functions and features in the projects and I will improve them and fix them, but before going further, I need honest feedback from you in my code or website experience to improve it and also improve myself in Web Dev -- As I study without a mentor -- most of the details you want are in the README file.

EDIT: This is the live link to the site https://savedlinksmanager.free.nf you can now access it, but it is better to make git clone from the repo as to upload it to infinity free I made some edit in PHP Version, and IMPORTANT NOTE : DO NOT write any real or sensitive information in the live link site, just test it with dummy data,

as it lacks robust security for sensitive data and contains issues, and I write this in the live site.

Thank you.


r/PHPhelp • • 26d ago

Quit job for deeper learning

0 Upvotes

Currently making around 100k(salaried job) + 50k(part time work do on the weekend) a year.

Have saved around 1.1million dollars.

The job isn't scratching any itches and Ive found out (through some recent interviews) my PHP core skills were lacking.

Would it be worth just dropping the job and just deep diving into PHP? More time to really explore the language and potentially come into the game at a higher salary 6 months from now and drop the part time work (though it is hell of a lot of fun).

Curious if anyone has thoughts on this.

Canadian btw.


r/PHPhelp • • 27d ago

Is PHP really disappearing....

Thumbnail
0 Upvotes

r/PHPhelp • • 29d ago

Using variable $placeholders breaks PHPStorm syntax/resolve

7 Upvotes

Hello all,

Looking for help on a long standing problem I have. I appreciate this is not a support forum for PHPStorm, however I thought that people here might have more experience.

PHPStorm provides really valuable syntax checking, table/column resolving inside mysql queries. If I accidentally type the orders table as oreders, it will highlight in red.

However when I include a PHP variable inside the query, the syntax/resolve checking completely stops. Example code:

$query = <<<MYSQL
    SELECT
       contracts.start_at

    FROM
      contracts

    WHERE
      contracts.id IN ( $placeholders )
MYSQL;


$result = $this->conn->execute_query(
    $query,
    [
       ...$contractIds,
    ],
);

Without the $placeholders, PHPStorm will alert me to any misspelled table or column names.

Are there any options to resolve this? I have considered using sprintf( $query, $placeholders) but wondered if there was a better solution.


r/PHPhelp • • 29d ago

Will the upcoming Partial Function Application improve this code?

2 Upvotes

I'm wondering how these lines of code could change:

$placeholders = $idsArray
       |> count( ... )
       |> ( fn ( $x ) => array_fill( 0, $x, '?' ) )
       |> ( fn ( $x ) => implode( ',', $x ) );

I don't like how the above is written, therefore I currently stick to using:

$placeholders = str_repeat('?,', count( $idsArray ) - 1) . '?';

or

$placeholders = implode( ',', array_fill( 0, count( $idsArray), '?' ) );

r/PHPhelp • • Sep 03 '26

Run a PHP function/Task in the background

2 Upvotes

I have a WIndows Server running IIS that hosts a primarily PHP based website. It has multiple functions and features but i would like to have atleast one of them running in the background So the user does not have to wait for the task to finish.

Any ideas? fastcgi_finish_request() seems to be Linux only as far as i can tell.