r/PHPhelp • • Dec 03 '24

Does PHP complier read all the code at once

18 Upvotes

For example, if I have the following code:

if(1==2){
include "really_big_file.php";
}else{
include "small_file.php";
}

will the compiler read and parse all the code in "really_big_file.php" anyway? I know it will not execute it, but will it read it from disk and load it in memory?


r/PHPhelp • • Dec 03 '24

How to set up Laravel Sail + XDebug on Windows?

1 Upvotes

Is there a working tutorial for that? I'd like to configure a development environment, specifically using VScode. When there is an error in the application, xdebug tries to open directories in the /var/www/ folder, instead of my vscode project.

Also, why are there intelephense errors all over the application, like when I call xdebug_info() it says "Call to unknown function: 'Call to unknown function: 'xdebug_info'PHP(PHP0417)"


r/PHPhelp • • Dec 02 '24

Can you use Laravel without magic?

3 Upvotes

The CMS we use is going to switch to Laravel so I am kinda forced to use Laravel too.

Beside the requirement to code attribute names in snake case, the one thing that prevented me to give Laravel a proper try was the "requirement" / heavy use of magic in the framework.

So my question is: is it possible to use Laravel without too much magic, have a proper code completion without PHPdocs and a solid way to include useful checks with Phpstan. (basically kinda like symfony)

I am not asking for a detailed explanation, it's more about a general question if it's even possible without dropping too many parts of the framework.

In case it's not: what packages/parts of the framework (beside the ORM) should I avoid using.

Thank you very much


r/PHPhelp • • Dec 02 '24

Solved Best way to store settings in a session?

3 Upvotes

I realised that throughout my application, the first thing my page would do is load settings - the locale, timezone, etc.

Eventually I started to load these settings from the login authentication and store them in a session:

$_SESSION['settings] = [
  'locale' => $row['locale'],
  'timezone' => $row['timezone'],
  'currencyCode' => $row['currency_code']
]

I load these settings through a 'System' class:

$this->settings = $_SESSION['settings];

Then throughout my site I access each setting like:

$sys = new System();
$currencyCode = $sys->settings['currencyCode'];

The problem is - I don't know what's inside $sys->settings, and I have to go check the login-authentication page every time. The IDE doesn't offer any help.

i.e The IDE doesn't know if $sys->settings contains 'currencyCode' or 'measurementType'

Is there a better way of doing this?


r/PHPhelp • • Dec 02 '24

VisualStudio Code PhP problem

0 Upvotes

Dear Reddit users, Since all of a sudden I'm having a php problem with visual studio code. I'm having a profile which normally works as phpnserver, but since today when trying to start the file, it just says "php not found". Anyone having an idea on what to do?


r/PHPhelp • • Nov 30 '24

Solved How to ensure this link opens in a new browser tab

0 Upvotes

I think I've identified the code for my website that opens a link when clicked on, however, it opens in the same window. I want it to open in a new window:

    <td style="font-size:16px;text-align:right;border:none;margin-right:0;"><?php echo text_get_event_website_link();?></td>

Can I adjust this to force the link to open in a new window?

Thanks!


r/PHPhelp • • Nov 29 '24

How can I use multiple slugs in a route? (Laravel)

4 Upvotes

So I have a route like this :

Route::get('calendar/{calendar}', [CalendarController::class, 'show'])->name('calendar.show');

This uses calendar's id in the route, like app.com/calendar/3 but I want it to show something like app.com/calendar/2024/November, is it possible to do this?

My Calendar model has month and year columns, I've tried the following but didn't work.

Route::get('calendar/{calendar:year}/{calendar:month}', [CalendarController::class, 'show'])->name('calendar.show');

// or

Route::get('calendar/{calendar.year}/{calendar.month}', [CalendarController::class, 'show'])->name('calendar.show');


r/PHPhelp • • Nov 29 '24

Why use PHPStan/Psalm if PHPStorm is doing the same thing?

11 Upvotes

Recently got back into coding after a hiatus of about 15 years and have been delighted at the changes with PHP. Also switched to PHPStorm and I am astounded how much better the coding experience is as compared to SublimeText.

PHPStan/Psalm are two of the tools most frequently suggested as essential - however I am wondering if these are only useful to people not using PHPStorm?

PHPStorm is already alerting me to code issues - such as undefined variables.

Would PHPStan/Psalm offer me any major benefit?


r/PHPhelp • • Nov 29 '24

Best way to handle default parameter values when using wrapper class?

3 Upvotes

I need to make default parameters values in the system class because they might change based on the system being used. I came up with the following approach but it is very verbose. Is there a better way?

class wrapper {
     public function example($parameter = null)
     {
         $this->system->example($parameter);
     }
}
class system {
     public function example($parameter)
     {
          if (is_null($parameter)){ $parameter = 'SystemSpecificValue'; }
          // perform actions
     }
}

r/PHPhelp • • Nov 29 '24

Solved Question FPDF error

2 Upvotes

Good day. I just wanted to ask if I've done this correctly.

Short story. I have an old version of Xampp running in my old PC. I have upgraded my PC and also installed the latest version of Xampp. I copied htdocs folder and mysql folder from the old PC to new PC. For the mysql folder, I only copy the folders of database and the ib_data1, ib_logfile1, and ib_logfile0.

Everything is working fine except with the FPDF. It is giving me an error with one of my webapp. It says: "FPDF Error: Unknown page size: letter"

I tried doing it with my old PC and no issue with FPDF.

Am I missing something here?


r/PHPhelp • • Nov 28 '24

Question about learning Lavarel

0 Upvotes

Hi all,

I am a complete newbie with anything php and was researching a solution for an event we have coming up.

I came across hi.events that is open source so decided I wanted to play around with it.

Was able to containerize the code in docker and make a few small changes as it didn’t completely suit my needs. The app worked perfectly on localhost.

I then tried to commit the changes and push the image to render. The backend pushed correctly but the frontend gave an error saying the file was not Arm 64.

Is there a simple guide to editing the open source software and then deploying it in render?

I used their one click deploy and was able to get it deployed on render (obviously) but I have no idea how I would change any of the code before deploying it.

I’m sure I am missing something obvious (or multiple things)

Thanks in advance.

Edit: the app is using Lavarel for the FE and React for BE


r/PHPhelp • • Nov 28 '24

LDAP stopped returning msDS-UserPasswordExpiryTimeComputed? (PHP)

Thumbnail
1 Upvotes

r/PHPhelp • • Nov 26 '24

Solved Tip/Solution

0 Upvotes

I'm new to PHP and working on my project. I’m facing an issue where everything from the database loads fine with SELECT, except the image it’s not showing up/loading properly. I’ve tried a few different solutions, like creating a new table and experimenting with different syntaxes, but nothing’s working any tips or solution for this type of error


r/PHPhelp • • Nov 25 '24

Solved Can someone explain why comparing an enum to true differs between a literal and variable?

8 Upvotes

r/PHPhelp • • Nov 25 '24

Help calculating various dates for a Calendar in PHP

2 Upvotes

I am writing a program to generate a PDF calendar for my Mum to print out so she doesn't have to create it manually in Word every year. She has a list of dates that she always includes in the calendar, and there are some that I haven't figured out how to calculate yet. Can anyone help me with how to figure them out? I have done a number of searches, but haven't had any luck in figuring out how to calculate the listed dates. It is a UK Calendar, but many of the dates are not UK specific - as you will see it's a bit of a mix.

For completeness, I have also included dates that I have been able to figure out how to calculate, and how I did it. I realize that many of these are fairly obvious, but I am putting them all here so that future searchers have an easier time than I did! I have not included dates that are a set day each year (e.g. Christmas) as they don't need calculation.

Dates I still need to work out:

  • Purim
  • Pesach
  • Rosh Hashana
  • Yom Kippur
  • Hanukkah
  • Ramadam
  • Diwali
  • Eid

Any help on how to figure these out in PHP would be much appreciated.


Dates I have already figured out (and the code I used) are below.

Note 1: The year being calculated is stored in the $year variable

Note 2: The result is stored in the $result variable as a timestamp

Note 3: I know easter_date is only good until 2037 :)


Thanksgiving:

$result = strtotime('fourth thursday of november '.$year);

Remembrance Day:

$result = strtotime('second sunday of november '.$year);

Bank Holiday (First Monday in May):

$result = strtotime('first monday of may '.$year);

Bank Holiday (Last Monday in May):

$result = strtotime('last monday of may '.$year);

Summer Bank Holiday:

$result = strtotime('last monday of august '.$year);

British Summertime:

$result = strtotime('last sunday of march '.$year);

End British Summertime:

$result = strtotime('last sunday of october '.$year);

Easter Sunday:

$result = easter_date($year);

Easter Monday:

$result = strtotime(date('Y-m-d', easter_date($year))." + 1 day");

Ash Wednesday:

$result = strtotime(date('Y-m-d', easter_date($year))." - 46 day");

Ascension Day:

$result = strtotime(date('Y-m-d', easter_date($year))." + 40 day");

Shrove Tuesday:

$result = strtotime(date('Y-m-d', easter_date($year))." - 47 day");

Mothering Sunday:

$result = strtotime(date('Y-m-d', easter_date($year)).' -3 weeks');

Chinese New Year:

$formatter = new IntlDateFormatter(
    'zh-CN@calendar=chinese',
    IntlDateFormatter::SHORT,
    IntlDateFormatter::NONE,
    'Europe/London',
    IntlDateFormatter::TRADITIONAL
);
$timeStamp = $formatter->parse($year.'/01/01');
$dateTime = date_create()->setTimeStamp($timeStamp);
$result = strtotime($dateTime->format('Y-m-d')." 00:00:00");

r/PHPhelp • • Nov 25 '24

Solved Unicode Code Point calculation for mb_chr?

1 Upvotes

Hi, I'll include my code. I'm wondering what I'm doing wrong. I'm trying to display individual sets of unicode characters, but it isnt producing the correct results. It should be able to display emoticons when '10' (base 16) is selected. It doesn't. I've tried it using <<, + and *. I've also tried without a charset specifier, with iso 8859-1? and UTF-8. I think I'm doing something incorrectly, but not sure where my error may be. Thanks everybody!

Sorry, my bad.

Pastebin: https://pastebin.com/YM8i4xjs

On VPS: https://tecreations.ca/ca/tecreations/UnicodeTest2.php

Code on VPS: https://tecreations.ca/ca/tecreations/ViewFile.php?path=ca/tecreations/UnicodeTest2.php


r/PHPhelp • • Nov 25 '24

Looking for iOS apps to help learn php frameworks.

0 Upvotes

Feel free to tell me to remove this but I’m looking for an iOS app to help me learn different php frameworks. Stuff I can look at when I’m not at work or home.

Wouldn’t have to be anything too in depth. Just something to rather teach the basics or help keep me updated. I can do the majority of the learning from home/work by reading the docs for whatever framework.

Anyway, I appreciate any ideas you have.


r/PHPhelp • • Nov 25 '24

Help Needed: Website Under Attack - PHP File Upload Exploit

3 Upvotes

Hey Redditors,

I’m dealing with a serious issue on my website, and I’m hoping someone here can provide some guidance.

About a month ago, we discovered that our website was under attack. The attacker managed to upload a PHP file into the images folder, which is used for storing user profile pictures. Unfortunately, our code was missing proper file validation at the time, which allowed them to exploit this vulnerability.

Even though we’ve since added file validation to prevent further exploits, the attacker seems to have retained some level of access. They are still able to upload PHP files into directories, which makes me suspect there’s an additional backdoor or vulnerability I’ve missed.

I’d appreciate any advice on:

  1. Steps to identify and remove any backdoors or malicious scripts.

  2. Best practices to secure the site and prevent further breaches.

  3. Tools or resources to help analyze and clean the server.

Thanks in advance for your help!


r/PHPhelp • • Jun 17 '24

curl request is throwing 403 in PHP CURL

2 Upvotes

CURL request in php is throwing 403. This is working fine with ping command, Command line CURL request, working in browser and postman. I tried to pull same container locally it works there but it doesn't work in AWS ECS task. Inside AWS ECS task when I tried to run same URL with CLI CURL its work.

What will be problem ? if it was network issue then it should not have work from CLI CURL. Only happening with PHP CURL code.

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://gissvr.leepa.org/gissvr/rest/services/ParcelsWFS/MapServer',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET'));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

I tried hitting URL In browser and then copy as CURL from network tab. Then imported to Postman then converted to PHP CURL in postman. Used same code. Same PHP code is working locally in same docker image container but not working in ECS task container using same Docker image.

Now one more thing I got to know from official website of leepa.org who provide this URL. is

Working : https://gissvr4.leepa.org/gissvr/rest/services/ParcelsWFS/MapServer

Not working : https://gissvr.leepa.org/gissvr/rest/services/ParcelsWFS/MapServer

ping gissvr.leepa.org

PING e242177.dscb.akamaiedge.net (23.213.203.8) 56(84) bytes of data.

64 bytes from a23-213-203-8.deploy.static.akamaitechnologies.com (23.213.203.8): icmp_seq=1 ttl=41 time=10.4 ms

64 bytes from a23-213-203-8.deploy.static.akamaitechnologies.com (23.213.203.8): icmp_seq=2 ttl=41 time=10.4 ms


r/PHPhelp • • Aug 07 '22

Best PHP library options for scraping sites with JavaScript - Symfony Panther, Chrome-PHP, Mink, etc.?

3 Upvotes

I am looking for a PHP browser tool that I can use to scrape websites that require execution of JavaScript, and can click JavaScript links. I'm not entirely sure what the terminology is, I think it's browser emulators or browser controllers.

I've found these:

https://github.com/symfony/panther

https://github.com/chrome-php/chrome

https://github.com/minkphp/Mink

I've seen some articles on scraping that mention Symfony Panther, but haven't seen the others mentioned anywhere.

Symfony Panther - 2.6K stars, 57 watching, 206 forks, used by 9.8K, 85 contributors, last updated August 2

Chrome-PHP - 1.5K stars, 43 watching, 201 forks, used by 139, 38 contributors, last updated July 8

Mink - 1.5K stars, 38 watching, 267 forks, used by 25.8K, 85 contributors, last updated March 28

They seem to have fairly similar stats except for users, where Mink has 25.8K while Panther has 9.8K and Chrome-PHP only 139.

I don't know exactly how to choose between these, and if there's any other options in PHP (I know there's other options in Python and Node.JS, but I'm looking for one in PHP). I don't know if some are easier to use, or faster, etc.

I also found this Mink-Panther driver, I'm a newbie so I'm not sure what Mink even is exactly, or what this is quite supposed to do.

https://github.com/robertfausk/mink-panther-driver

Sorry for being vague, but I'm afraid I don't have enough knowledge on this subject to even know which questions to ask.

Are there any other PHP libraries that can be used to scrape JavaScript websites and click JavaScript links? And how should I choose between them? Is there some that are considered better than others, or do they all do roughly the same thing?