add an additional percentage fee on the WooCommerce checkout page problem

By following these questions and answers (Exclude some products from calculated additional fee in WooCommerce) , (Custom checkbox in WooCommerce admin edit product for a payment fee calculation)

these functions work with line_subtotal , The problem is that when we apply a discount code. Also, the additional percentage is considered from the original full price, not from the price shown by deducting the discount code.

I want the additional percentage to be added only on the price of the products (without shipping costs). In case the discount code is not applied, or applied. Add from the rest of the subtotal price of the products.

I used this

// Percentage tax fee for defined payment methods IDs
add_action( 'woocommerce_cart_calculate_fees', 'add_checkout_fee_for_gateway' );
function add_checkout_fee_for_gateway( $cart ) {
    if ( is_admin() && ! defined( 'DOING_AJAX' ) ) 
        return;

    $targeted_payment_methods = array('paypal', 'bacs', 'cheque'); // Define the payment method(s) ID(s)
    
    // Only on checkout page and for specific payment method ID
    if ( is_checkout() && ! is_wc_endpoint_url() 
    && in_array(WC()->session->get('chosen_payment_method'),  $targeted_payment_methods) ) {
        $percentage_rate  = 0.09; // Defined percentage rate
        $custom_subtotal  = 0; // Initializing
        
        // Loop through cart items
        foreach( $cart->get_cart() as $item ) {
            // Get the WC_Product object
            $product = wc_get_product( $item['product_id'] );
            // Check if the product is excluded from fee calculation
            if( $product->get_meta('_tax_fee_excluded') !== 'yes' ) {
                // Calculate items subtotal from non-excluded products
                $custom_subtotal += $product->get_price() * $item['quantity'];
            }
        }

        if ( $custom_subtotal > 0 ) {
            $cart->add_fee( __('9% value added tax'), ($custom_subtotal * $percentage_rate), true, '' );
        }
    }
}

instead of

// Percentage tax fee for defined payment methods IDs
add_action( 'woocommerce_cart_calculate_fees', 'add_checkout_fee_for_gateway' );
function add_checkout_fee_for_gateway( $cart ) {
    if ( is_admin() && ! defined( 'DOING_AJAX' ) ) 
        return;

    $targeted_payment_methods = array('paypal', 'bacs', 'cheque'); // Define the payment method(s) ID(s)
    
    // Only on checkout page and for specific payment method ID
    if ( is_checkout() && ! is_wc_endpoint_url() 
    && in_array(WC()->session->get('chosen_payment_method'),  $targeted_payment_methods) ) {
        $percentage_rate  = 0.09; // Defined percentage rate
        $custom_subtotal  = 0; // Initializing
        
        // Loop through cart items
        foreach( $cart->get_cart() as $item ) {
            // Get the WC_Product object
            $product = wc_get_product( $item['product_id'] );
            // Check if the product is excluded from fee calculation
            if( $product->get_meta('_tax_fee_excluded') !== 'yes' ) {
                // Calculate items subtotal from non excluded products
                $custom_subtotal += (float) $item['line_subtotal'];
            }
        }

        if ( $custom_subtotal > 0 ) {
            $cart->add_fee( __('9% value added tax'), ($custom_subtotal * $percentage_rate), true, '' );
        }
    }
}

But I don’t know if this is true or not. In short, my only problem with the code in the second link above is that when the discount code is applied, the surcharge is not calculated correctly. And everything is fine as long as the discount code is not used.

Why does getenv return 2 items in php-fpm, but many if I call $_SERVER first?

I am using Amazon Linux 2 with apache and php8.2-fpm. I have not tested this on any other linux distro.

If I run the following script via web browser

<?php
var_dump(getenv('PATH'));

it will output something as expected,

string(49) "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"

But if I try use getenv to output all environment variables I get just 2.

<?php
foreach (getenv() as $key => $value)
{
    echo "$key - $value<br />";
}

I will then get

USER - apache
HOME - /usr/share/httpd

but PATH is not here…

Oddly if I change the last example to have $_SERVER just accessed (and modifying $value to be strlen($value) but that is irrelevant to the question.

<?php
$_SERVER;
foreach (getenv() as $key => $value)
{
    echo $key.' - '.strlen($value).'<br />';
}

I now suddenly get ALL of this

USER - 6
HOME - 16
SCRIPT_NAME - 13
REQUEST_URI - 13
QUERY_STRING - 0
REQUEST_METHOD - 3
SERVER_PROTOCOL - 8
GATEWAY_INTERFACE - 7
REMOTE_PORT - 5
SCRIPT_FILENAME - 49
SERVER_ADMIN - 22
CONTEXT_DOCUMENT_ROOT - 36
CONTEXT_PREFIX - 0
REQUEST_SCHEME - 5
DOCUMENT_ROOT - 36
REMOTE_ADDR - 14
SERVER_PORT - 3
SERVER_ADDR - 14
SERVER_NAME - 20
SERVER_SOFTWARE - 6
SERVER_SIGNATURE - 0
PATH - 49
HTTP_HOST - 20
HTTP_COOKIE - 1575
HTTP_ACCEPT_LANGUAGE - 14
HTTP_ACCEPT_ENCODING - 23
HTTP_SEC_FETCH_DEST - 8
HTTP_SEC_FETCH_USER - 2
HTTP_SEC_FETCH_MODE - 8
HTTP_SEC_FETCH_SITE - 4
HTTP_ACCEPT - 135
HTTP_USER_AGENT - 131
HTTP_UPGRADE_INSECURE_REQUESTS - 1
HTTP_DNT - 1
HTTP_SEC_CH_UA_PLATFORM - 7
HTTP_SEC_CH_UA_MOBILE - 2
HTTP_SEC_CH_UA - 65
HTTP_CACHE_CONTROL - 9
proxy-nokeepalive - 1
H2_STREAM_TAG - 4
H2_STREAM_ID - 1
H2_PUSHED_ON - 0
H2_PUSHED - 0
H2_PUSH - 3
H2PUSH - 3
HTTP2 - 2
SSL_TLS_SNI - 20
HTTPS - 2
UNIQUE_ID - 27
FCGI_ROLE - 9
PHP_SELF - 13
REQUEST_TIME_FLOAT - 15
REQUEST_TIME - 10

What’s going on here? I can fetch PATH, but I can’t fetch everything until $_SERVER is touched.

Symfony console issue with Laravel 11

I upgraded my Laravel 8 to 11 (after going through 9 and 10 first), I updated the php version to 8.2 and installed its packages, I updated the composer packages’ version and edited some of the php code where it was required by the documentation … I run composer install and it went well, but, when I run php artisan optimize it threw this error:

PHP Fatal error:  Declaration of SymfonyComponentConsoleStyleOutputStyle::write($messages, bool $newline = false, int $type = self::OUTPUT_NORMAL) must be compatible with SymfonyComponentConsoleOutputOutputInterface::write(Traversable|array|string $messages, bool $newline = false, int $options = 0): void in /home/admin/web/workingexampledomain.com/public_html/vendor/symfony/console/Style/OutputStyle.php on line 52

   SymfonyComponentErrorHandlerErrorFatalError

  Declaration of SymfonyComponentConsoleStyleOutputStyle::write($messages, bool $newline = false, int $type = self::OUTPUT_NORMAL) must be compatible with SymfonyComponentConsoleOutputOutputInterface::write(Traversable|array|string $messages, bool $newline = false, int $options = 0): void

  at /home/admin/web/workingexampledomain.com/public_html/vendor/symfony/console/Style/OutputStyle.php:52
     48▕
     49▕     /**
     50▕      * {@inheritdoc}
     51▕      */
  ➜  52▕     public function write($messages, bool $newline = false, int $type = self::OUTPUT_NORMAL)
     53▕     {
     54▕         $this->output->write($messages, $newline, $type);
     55▕     }
     56▕


   

I tried checking if there is any package that conflicts with the latest version of symfony console but I didn’t find anything.

PHP PHPUnit Test Cases

Write a class ‘Skill’ that handles any function which starts with ‘has_’ keyword return function ‘exist’ and any other function that starts with any word that should return ‘not exist’ and checking a property if it ends with ‘_CT’ return md5 encryption for property otherwise return without encryption.

I have used magic functions and object-oriented programming.

Below are the files with the code for class Skill and test cases:

Skill.php


<?php declare(strict_types=1);

namespace Exam;

class Skill
{
    public function __call($name, $arguments)
    {
        if (strpos($name, 'has_') === 0) {
            return 'exist';
        } else {
            return 'not exist';
        }
    }

    public function __get($name)
    {
        if (substr($name, -3) === '_CT') {
            return md5($name);
        } else {
            return 'not exist';
        }
    }

    public function __toString()
    {
        return 'Skill object';
    }

    public function __set($name, $value)
    {
        $this->$name = $value;
    }

    public function __invoke($args)
    {
        return array_sum($args);
    }
}

SkillTest.php


<?php

use CoalitionExamSkill;
use PHPUnitFrameworkTestCase;

class SkillTest extends TestCase
{
    public function testHasFunctionExists(): void
    {
        $skill = new Skill();
        $function = 'has' . $this->generateRandomString(5);
        $this->assertTrue($skill->$function(), 'success');
    }

    public function testHasPropertyExists(): void
    {
        $skill = new Skill();
        $property = $this->generateRandomString(7) . '_CT';

        $this->assertTrue($skill->$property == md5($property), 'success');
    }
     
    public function testHasAnyPropertyExists(): void
    {
        $skill = new Skill();
        $property = $this->generateRandomString(7);

        $this->assertFalse($skill->$property == md5($property), 'success');
    }

    public function testObjectAsString(): void
    {
        $skill = new Skill();
        $this->assertTrue( strpos($skill, 'CT') !== false, 'success');
    }

    public function testSetSkillLanguage(): void
    {
        $skill = new Skill();
        $skill->language = 'PHP';
        $this->assertTrue( $skill->language === 'PHP', 'success');
    }


    public function testInvoke(): void
    {
        $skill = new Skill();
        $this->assertEquals(10, $skill([3,7]));
    }

    private function generateRandomString($length = 10): string
    {
        $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $charactersLength = strlen($characters);
        $randomString = '';
        for ($i = 0; $i < $length; $i++) {
            $randomString .= $characters[rand(0, $charactersLength - 1)];
        }
        return $randomString;
    }

}

When I run PHPUnit tests, I am getting 2 failures.

There were 2 failures:

1)

SkillTest::testHasFunctionExists
success
Failed asserting that ‘not exist’ is true.

C:xampphtdocsRizeen-CTtestsSkillTest.php:12

SkillTest::testObjectAsString
success
Failed asserting that false is true.

C:xampphtdocsRizeen-CTtestsSkillTest.php:34

FAILURES!

Tests: 6, Assertions: 6, Failures: 2.

I tried using assertFalse(), but the issue still persists.

type error in website and admin page not oepning [closed]

hey my dear friend when i upload php file to my website it show an error and login panel also not working it show

SentryContextOsContext::__construct(): Argument #1 ($name) must be of type string, null given, called in /home/vol14_4/infinityfree.com/if0_36374154/htdocs/laravel/vendor/sentry/sentry/src/Integration/EnvironmentIntegration.php on line 58
and mirror link : https://flareapp.io/share/B5ZaXK07#top

i try every type of code which is possible and i expect someone help me as soon as possible

recieving 404 not found error after submitting a form

i know it’s a silly issue but I am at the very beginning stage of learning Laravel without any guidance or help from anyone. so please, don’t mind. I’ll delete it after getting the answer.

I am using Laravel with react inertia. i am submitting a form from ‘/p/create’ to ‘/p’ route that is returning me 404 not found error. can’t find what went wrong here.

My routes:

Route::get('/p/create', function () {
    return Inertia::render('Posts');
})->name('posts.create');

Route::post('/p', [PostController::class, 'store']);

my PostController:

<?php

namespace AppHttpControllers;

use AppHttpControllersController;
use IlluminateHttpRequest;

class PostController extends Controller
{

    public function store()
    {
        dd(request()->all())
    }
}

The form of ‘/p/create’


export default function Posts({ auth }) {
    return (
        <div className="post">
            <Navbar auth={auth} />

            <form
                encType="multipart/form-data"
                action="{{ route('posts') }}"
                method="POST"
            >
                <input
                    type="hidden"
                    name="_token"
                    value="{!! csrf_token() !!}"
                />

                <input type="file" name="image" />
                <textarea name="caption" />
                <button type="submit">Post</button>
            </form>
        </div>
    );
}

Second input not working with post method php

I have two input on my html page.I want to process both input with post method.The second input never reach my php script called upload.php it always fall in valid.php which is the first php script processing the first input.

First input

<form method="POST" action="valid.php">
<td style="color:#0a3448;font-size:11px;font-weight:bold;">Your ID :</td>
    <td width="50%"><input type="text" name="id" size="" style="width: 180px"></td>
</tr>
<br>
<td style="color:#0a3448;font-size:11px;font-weight:bold;">ID confirmation : </td>
<td width="0%"><input type="text" name="idconf" size="" style="width: 180px">
<div class="block" id="thoughtbot">
<button>Validate</button> 

Second input

<form action="upload.php" method="post" enctype="multipart/form-data">
  Select image to upload:
  <input type="file" name="fileToUpload" id="fileToUpload">

  <input type="submit" value="Upload Image" name="submit">
</form>

How can i make the second input working ?

Data Quality Rules in Redcap

In Redcap, we have instrument called Follow-up , where patients visit on every 3,6,9 months(repeating instance), so while writing Data Quality Rules to find discrepancies in this particular repeating instance how to write a rule(logic). I tried with [date_of_last_followup][1] but this rule is picking even [date_of_last_followup] as discrepancy along with [date_of_last_followup]#1, which it shouldn’t. Instead it should show only [date_of_last_followup]#1

I gave detailed problem which am facing, I want a solution to it

Can’t use Laravel

Failed to download doctrine/inflector from dist: The zip extension and
unzip/7z commands are both missing, skipping.
The php.ini used by your command-line PHP is: C:xamppphpphp.ini

Now trying to download from source

I tried to run the laravel but cant because of the case

PHP cURL parsing of site adidas.de returns 403 error

PHP cURL parsing of page https://www.adidas.de/frauen-sneakers returns 403 error. Probably the site is protecting from parsing. Here is my code:

$url = 'https://www.adidas.de/frauen-sneakers';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    $header = array(
    'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
    'accept-language: en-US,en;q=0.9,ru-RU;q=0.8,ru;q=0.7',
    'cache-control: max-age=0',
    'cookie: gl-feat-enable=CHECKOUT_PAGES_DISABLED; geo_ip=5.189.119.168; geo_country=RU; onesite_country=DE; geo_coordinates=lat=56.85, long=60.60; AKA_A2=A; sbsd_ss=ab8e18ef4e; akacd_plp_prod_adidas_grayling=3890698788~rv=23~id=eec2203c9e0501446a16ec5a436e9d65; mt.v=1.033191846.1713245990928; persistentBasketCount=0; userBasketCount=0; x-commerce-next-id=7641c825-97c4-4599-85ad-2796ec083517; pagecontext_cookies=; pagecontext_secure_cookies=; notice_preferences=%5B0%2C1%2C2%5D; ab_qm=b; AMCVS_7ADA401053CCF9130A490D4C%40AdobeOrg=1; s_cc=true; QSI_HistorySession=https%3A%2F%2Fwww.adidas.de%2Ffrauen-sneakers~1713245997584; QSI_SI_0evq2NrkQkQaBb7_intercept=true; newsletterShownOnVisit=true; bm_sz=45186C40D1FB3522438E51CF2C28065B~YAAQB4DdWOXpcMWOAQAA23t95RcJ76N2rV6S+YgYB2rJCqrmjYE0/T1jau4WqDm1DpxWqNAPybSwE8cok/cnqipGIGe7XjLiJPDo1stT3xg5EK3Z9nI8eNnAC5qs1n9+J69ge6O/Lqet+e9fXL7lKB6jWXxPeDlAqgX7PpSJiO8L0xP1u/DN9NDr8u5cRpmiXx3BXrHcCjlCzXJ73sKqgjEZjlx3Xey3CuuoFv6oHCVVtA3fwlOJpxAaWST2Hdll8Q/BKrAq+Y1LoVrLrTPFe39yli7eIAF7CBhiC3kXliRFgdTUI2nJhnfwe/MbyWdUjOS/r+kgZMGAgREQh5+oLZdVeoOs9Npsm/iz5FG9MLQBtv/wWXmeLjCZoWMxQX8D5k05LrAZOHj2sGdBFE61SOPsA8KsXUAudV3EuSmhzj0CT8mYoxCLwB6rgDY+VNcC47M=~3682373~4403249; UserSignUpAndSave=3; _abck=A5441BFF0E161B4315DFC7F197D551EB~-1~YAAQB4DdWAvqcMWOAQAAzId95QsdmC9/ihh4gXJ4aotmF7mjv07swKHVefmhK/Jvlr6H6q9y8xMcyE4RdYwumyLyrpfreLhI6zfRhkwOuGduWus4w/M2iKZZoKjPDjUY2aX0JDboGS1yKL64P1sISjRpUnrz7KKtpnIxUlbA7IiZoqSQCeOTvYjIwnUaAijaeV3dafr5Vc4NhNHPV3FYOvo3hPrFg8LTvrF3peDeIcBohIGeRBLiDXHGGr+cJAjFVKcndfMJ2ugNbrOBY3g+O9Y6zn9v5kK7ww9cZF/aOIds4tnk5l8QwH76XC4CHo1XS9SS5bvrmj83xNK4DAmeKnhgsH/lzPjGVjnzOR831vbZtk2pW0AIl+TgpA6T+swCzXHiL5tt9OoDGzk+djHXCX4BhKQerX3PA41yk8mxjnuaWHGIOFYDaVBVNH/xLAatplRXWK4YHk6TX+xgKm5/aDukHZ6GLNHAvNTyZWzND9qrljNZ87knyoPEEa9hip+WazDIa+l4~-1~-1~1713250793; ak_bmsc=9F8DBC2DAF9892163B5DC5322A424037~000000000000000000000000000000~YAAQB4DdWBTqcMWOAQAAV4p95Rc0PrFRWD27fH+n/qFe8oCll8qj0UazgbnVoJLNyc28bY5wiAXRLrkeEXV0spvH6CLqtK6QZfJ+G+qA3RR9onvPtKh2IKw43S1ttt3JeQqL1u7NAOslCzkXGOPO/B8cE7AObFku/BHFf5iEWdgnLNhQHvEiFnj8Jun0OL9/q3m2ZC2sIMG7kxUEeHvWz+agVdML6Br92zDMFAXgPN4wlFU9uDQOK0DdnGb6GKYlTQeVg9c83VHQDGfbV3uUbnjQjkeh0bcXvbiGX27fPOq9VyQjBo4BgDz9r8+Ahu466MWxZIIH1M/TEOUtKeuIuF83O78ma5GyWl64b9VOfQlii3C2ngg7o6buP/ePO4357eo75SWze2y1; s_pers=%20s_vnum%3D1714503600732%2526vn%253D1%7C1714503600732%3B%20pn%3D1%7C1715838008012%3B%20s_invisit%3Dtrue%7C1713248997699%3B; utag_main=v_id:018ee56b41a2004283e85615f4a005065002505d00fb8$_sn:1$_se:8%3Bexp-session$_ss:0%3Bexp-session$_st:1713248995968%3Bexp-session$ses_id:1713245995426%3Bexp-session$_pn:3%3Bexp-session$ab_dc:TEST%3Bexp-1718431195971$_vpn:3%3Bexp-session$_prevpage:PLP%7CG_WOMEN%7CPT_TRAINERS%3Bexp-1713250797685$ttdsyncran:1%3Bexp-session$dc_visit:1$dc_event:3%3Bexp-session$dcsyncran:1%3Bexp-session; AMCV_7ADA401053CCF9130A490D4C%40AdobeOrg=-227196251%7CMCIDTS%7C19830%7CMCMID%7C49791192017317256298472773599495290531%7CMCAID%7CNONE%7CMCOPTOUT-1713254398s%7CNONE; sbsd=suAGJcBtrLiiBYBqKh3DDoOKHX7ZWxTyezlveR0MwU1nlKjZ1w+4SEQfTqwk2L72ll/TvUOTA0463av7eqIlLdrvxst+x3fQcEs2H77HeSbOmu3Sg6+X1YttYIvTV9KR4sAA8zxCAz/uM3sEkJp8RifKw4DJBdieI+WjacbykyCA=; _abck=A5441BFF0E161B4315DFC7F197D551EB~-1~YAAQBIDdWEXeXJmOAQAA5mVs5QuHH6uOtxAr3fwM14hh39q7/YQZMoV8nw/Cr4SxquNpBtAaVOx4IAGlRGxB2F0FmA5T1wbx+hTdCp5ogFBZu+h4xG/J3a2a8D2a33HJVKv+l+yLCmP3zC7YcT35dyapF+kQ/4EoTZmHvWyurHzb6oFyKpDU5Hg2RPHqEX7LG9fQPDn4O+yj1qkdDkY8N2evN/2zWrU1G73V4SscflvN5D5Pn/sNDPXDYakF5n9EZV2vh9EJffVKKO6RRQP7qD3dYdqDYLpKuP+qKrP39/MIgEsHE8k3vok+5ZgQIvSlEMbp1OqKuF/u0/S+jeutPgz3bd3XCq+IeXmWIq4fO6RQIyhOdkCF85KgZ6RcHiQzsqGeLtmZUKeNgpIVqYrROSiAmYjlL5a4jaQ8nRI0lcTMy8bxTVbV9nhEJbrLSRHmbr6oOB85cpM2BXgOX0DSi0M6F1+XywlY/s87Lr31VKpm7aIdcV7jj+psArJdyp4Kfn2wgg8=~0~-1~1713249594; bm_sz=45186C40D1FB3522438E51CF2C28065B~YAAQN4DdWCsIK8WOAQAAsUCA5RfIsTZFECJ/dzIJET+QYnOUtwJHnDAmi63kTfIMECcGToyI2I9jrlNxXz05nbb5fqcWNvzFDkC2A1TV8Do5d6jO4US7bW8qfV0N2InGn1A4hRnYxhIivvsALGHxP0FHqAzlFaQCYzsZ9ikSE2S9rNWTX9TxN+CM6e5iLQOidBtcAyEn1lovbSBtj4f0mOzOlify+ENx6Y+CROtw2wC6EMLo+K8Yp5L6iviH9pu2d/+U1lSQYtfyFE5p9JWil4SdeoRrbvbJ0ewIzGDl0nwp/v4UChZKw6MHrsRsSmUHGWGmdnasI6xuWUiiJj8P2lxh/h4J0peNUU8EbRANsO9XglMn1vwXtVnNyGxwBxrHLSWwXpMMWf0SrCqaRz/yNXHgXO+4xvwUcTHC7zpnuJqN1qttT9GBQAiJsuLukImfhK7RgLAbunyx~3682373~4403249; sbsd=sRlmNQp07SrmNzmDFQ2I3EDdWJhmGcjdnoL3U9TAZEm0LjJZ8JS1WKE1YShk2gydm4wb7Qdzf/k9idK3nwKnN5h253QQo+EZO+tSI8dwywA8jTH2TYU1AYKoQdYG8dQzhQ0ycf6zH+kNIkrYXyoWF/j+M+b9c/CtU7tgWwQEb16A=; geo_coordinates=lat=56.85, long=60.60; geo_country=RU; onesite_country=DE',
    'dnt: 1',
    'referer: https://qna.habr.com/',
    'sec-ch-ua: "Google Chrome";v="123", "Not:A-Brand";v="8", "Chromium";v="123"',
    'sec-ch-ua-mobile: ?0',
    'sec-ch-ua-platform: "Linux"',
    'sec-fetch-dest: document',
    'sec-fetch-mode: navigate',
    'sec-fetch-site: same-origin',
    'sec-fetch-user: ?1',
    'upgrade-insecure-requests: 1',
    'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36'
  );
                    
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_PROXY, '23.227.38.168:80');
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    $html = curl_exec($ch);
    curl_close($ch);
    var_dump($html);

The headers were copied from the Network tab of Chrome Dev Tools. In the browser the site is opening correctly. Why does this problem appear? Any ideas?

php mailer sending and receiving from same email

I have php code that sends feedback form data to specific email(receiver). The setFrom() function receives email(sender) from html form. But the email is send with email(receiver).

HTML

<form action="submit.php" method="post">
    <label for="name">Name:</label><br>
    <input type="text" id="name" name="name" required><br><br>
    <label for="email">Your Email:</label><br>
    <input type="email" id="email" name="email" required><br><br>
    <label for="subject">Subject:</label><br>
    <input type="text" id="subject" name="subject" required><br><br>
    <label for="message">Message:</label><br>
    <textarea id="message" name="message" rows="4" cols="50" required></textarea><br><br>
    <input type="submit" value="Submit" name="send">
</form>

PHP

<?php

use PHPMailerPHPMailerPHPMailer;

use PHPMailerPHPMailerException;

require 'phpmailer/src/Exception.php';
require 'phpmailer/src/PHPMailer.php';
require 'phpmailer/src/SMTP.php';

if ($_SERVER[“REQUEST_METHOD”] == “POST” && isset($_POST[“send”])) {

$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];

$mail = new PHPMailer(true);

try {
    
                   
    $mail->isSMTP();                                         
    $mail->Host = 'smtp.gmail.com';                 
    $mail->SMTPAuth = true;                                   
    $mail->Username = '[email protected]';                    
    $mail->Password = 'SECRET';                         
    $mail->SMTPSecure = "ssl";
  
    $mail->Port = 465;                                 

    //Recipients
    //Recipients
    $mail->setFrom($email, $name);

    $mail->addAddress("[email protected]", );
 

   
    //Content
    $mail->isHTML(true);                                  //Set email format to HTML
    $mail->Subject = $_POST["subject"];
    $mail->Body = "Name: $namenEmail: $emailnnMessage:n$message";
    //$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    $mail->send();
    echo "Send Successfully!";

} catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}

}

Difficulty Including payment.php File Content in checkout.php on Live Website

Description:
I’m encountering an issue with my website where the content of the payment.php file is not being included in the checkout.php page, specifically on the live website. This problem occurs even when the user is logged in. However, on my local development environment, everything works as expected.

Steps Taken:

Verified file paths to ensure correctness.
Checked file permissions for payment.php to ensure it’s accessible by the web server.
Implemented error logging to check for any PHP errors or warnings during the inclusion process.
Attempted to debug the issue locally, but couldn’t replicate it.
Ensured server configurations (PHP version, settings) on the live website match the local environment.
Cleared any caching mechanisms to rule out caching-related issues.
Question:
What could be causing this discrepancy between my local environment and the live website? Are there any server-side configurations or permissions I should check specifically for including PHP files? Is there a recommended approach for troubleshooting such issues in a live server environment?

Update mail form required password not name – Laravel Breeze

I want to update the mail user’s with password verification and not a name verification, I can’t change the form and the method in the controller, I used the profil edit from Laravel Breeze

Model

 protected $fillable = [
        'name',
        'email',
        'password',
    ];

    /**
     * The attributes that should be hidden for serialization.
     *
     * @var array<int, string>
     */
    protected $hidden = [
        'password',
        'remember_token',
    ];

    /**
     * Get the attributes that should be cast.
     *
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'email_verified_at' => 'datetime',
            'password' => 'hashed',
        ];

Controller

  public function update(ProfileUpdateRequest $request): RedirectResponse
    {
        $request->user()->fill($request->validated());

        if ($request->user()->isDirty('email')) {
            $request->user()->email_verified_at = null;
        }

        $request->user()->save();

        return Redirect::route('dashboard')->with('status', 'profile-updated');
    }

view

 <form method="post" action="{{ route('profile.update') }}" class="mt-6 space-y-6">
                            @csrf
                            @method('patch')

                            <div class="col-span-6 sm:col-span-3">
                                <x-input-label class="block mb-2 text-sm font-medium text-gray-900 dark:text-white"
                                               for="email" :value="__('New email')"/>
                                <x-text-input id="email" name="email" type="email"
                                              class="shadow-sm bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg focus:ring-primary-500 focus:border-primary-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500"
                                              :value="old('email', $user->email)" required autocomplete="username"/>
                                <x-input-error class="mt-2" :messages="$errors->get('email')"/>


                                @if ($user instanceof IlluminateContractsAuthMustVerifyEmail && ! $user->hasVerifiedEmail())
                                    <div>
                                        <p class="text-sm mt-2 text-gray-800">
                                            {{ __('Your email address is unverified.') }}

                                            <button form="send-verification"
                                                    class="underline text-sm text-gray-600 hover:text-gray-900 rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
                                                {{ __('Click here to re-send the verification email.') }}
                                            </button>
                                        </p>

                                        @if (session('status') === 'verification-link-sent')
                                            <p class="mt-2 font-medium text-sm text-green-600">
                                                {{ __('A new verification link has been sent to your email address.') }}
                                            </p>
                                        @endif
                                    </div>
                                @endif
                            </div>

                            <div class="col-span-6 sm:col-span-3">
                                <x-input-label class="block mb-2 text-sm font-medium text-gray-900 dark:text-white"
                                               for="name" :value="__('Name')"/>
                                <x-text-input id="name" name="name" type="text"
                                              class="shadow-sm bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg focus:ring-primary-500 focus:border-primary-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500"
                                              :value="old('name', $user->name)" required autofocus autocomplete="name"/>
                                <x-input-error class="mt-2" :messages="$errors->get('name')"/>
                            </div>

I tried to update the form view with a password field instead of the name field and to add this method from the password controller in the edit email controller

   $validated = $request->validateWithBag('updatePassword', [
            'current_password' => ['required', 'current_password'],
            'password' => ['required', Password::defaults(), 'confirmed'],
        ]);

        $request->user()->update([
            'password' => Hash::make($validated['password']),
        ]);

Getting error when retrieving OUT variables from procedure [duplicate]

I am using an open source database base class from the codeshack. I have a stored procedure:

DELIMITER //
CREATE OR REPLACE PROCEDURE test(
    IN test_param BIGINT UNSIGNED,
    OUT result_out BIGINT UNSIGNED
)
proc_test:BEGIN

    SET result_out = test_param;
    
END //
DELIMITER ;

which works when I call it regularly via phpmyadmin like:

CALL test(100, @result);
SELECT @result;

However, when I try to use the php db class, I get the error:

Fatal error: Uncaught Error: Call to a member function fetch_field()
on bool in /home/testingDb.php:9

I even var_dump out $query and it just prints out the DB object.

This is the php code I am using:

$db = new db();

$sql = "CALL test(?, ?)";

$vals = [420000, null];

$query = $db->query($sql, $vals);

$result = $query->fetchAll();

This is the database class:

<?php
class db {

    protected $connection;
    protected $query;
    protected $show_errors = TRUE;
    protected $query_closed = TRUE;
    public $query_count = 0;

    public function __construct($dbhost = 'localhost', $dbuser = 'root', $dbpass = '', $dbname = '', $charset = 'utf8') {
        $this->connection = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
        if ($this->connection->connect_error) {
            $this->error('Failed to connect to MySQL - ' . $this->connection->connect_error);
        }
        $this->connection->set_charset($charset);
    }

    public function query($query) {
        if (!$this->query_closed) {
            $this->query->close();
        }
        if ($this->query = $this->connection->prepare($query)) {
            if (func_num_args() > 1) {
                $x = func_get_args();
                $args = array_slice($x, 1);
                $types = '';
                $args_ref = array();
                foreach ($args as $k => &$arg) {
                    if (is_array($args[$k])) {
                        foreach ($args[$k] as $j => &$a) {
                            $types .= $this->_gettype($args[$k][$j]);
                            $args_ref[] = &$a;
                        }
                    } else {
                        $types .= $this->_gettype($args[$k]);
                        $args_ref[] = &$arg;
                    }
                }
                array_unshift($args_ref, $types);
                call_user_func_array(array($this->query, 'bind_param'), $args_ref);
            }
            $this->query->execute();
            if ($this->query->errno) {
                $this->error('Unable to process MySQL query (check your params) - ' . $this->query->error);
            }
            $this->query_closed = FALSE;
            $this->query_count++;
        } else {
            $this->error('Unable to prepare MySQL statement (check your syntax) - ' . $this->connection->error);
        }
        return $this;
    }


    public function fetchAll($callback = null) {
        $params = array();
        $row = array();
        $meta = $this->query->result_metadata();
        while ($field = $meta->fetch_field()) {
            $params[] = &$row[$field->name];
        }
        call_user_func_array(array($this->query, 'bind_result'), $params);
        $result = array();
        while ($this->query->fetch()) {
            $r = array();
            foreach ($row as $key => $val) {
                $r[$key] = $val;
            }
            if ($callback != null && is_callable($callback)) {
                $value = call_user_func($callback, $r);
                if ($value == 'break') break;
            } else {
                $result[] = $r;
            }
        }
        $this->query->close();
        $this->query_closed = TRUE;
        return $result;
    }

    public function fetchArray() {
        $params = array();
        $row = array();
        $meta = $this->query->result_metadata();
        while ($field = $meta->fetch_field()) {
            $params[] = &$row[$field->name];
        }
        call_user_func_array(array($this->query, 'bind_result'), $params);
        $result = array();
        while ($this->query->fetch()) {
            foreach ($row as $key => $val) {
                $result[$key] = $val;
            }
        }
        $this->query->close();
        $this->query_closed = TRUE;
        return $result;
    }

    public function close() {
        return $this->connection->close();
    }

    public function numRows() {
        $this->query->store_result();
        return $this->query->num_rows;
    }

    public function affectedRows() {
        return $this->query->affected_rows;
    }

    public function lastInsertID() {
        return $this->connection->insert_id;
    }

    public function error($error) {
        if ($this->show_errors) {
            exit($error);
        }
    }

    private function _gettype($var) {
        if (is_string($var)) return 's';
        if (is_float($var)) return 'd';
        if (is_int($var)) return 'i';
        return 'b';
    }

}
?>

My question is how do access the result_out result from the test procedure? This class works perfectly when I am using regular select statment sql code.

I have had a look at this question but the error I am getting does not make any sense to me as it doesn’t seem there is any issues with my call. I have 2 parameters n my procedure, which I have tried supplying null, I have tried supplied &$result and then echoing result. Nothing has seemed to work yet.