Get origin $_SERVER[‘HTTP_ORIGIN’] cors whitelist domain name get origin is null?

$origin = isset($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : null;

header("Access-Control-Allow-Origin: $allowed_domain");
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Headers: Content-Type, Accept, Authorization");
header("X-Frame-Options: ALLOW-FROM $origin");
header("Content-Security-Policy: frame-ancestors 'self' $allowed_domain");

this code origin cors whitelist domain, but get $origin all null?

Why I can’t get supervisord recognize new .conf files in Laravel Sail/Docker installation?

so I’ve got a scout-worker.conf in /etc/supervisor/conf.d It contains this code:

[program:scout-worker]
process_name=%(program_name)s_%(process_num)02d
command=docker exec cercasemi-laravel.test-1 php /var/www/html/artisan queue:work redis --queue=scout --sleep=3 --tries=3
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=root
numprocs=1
redirect_stderr=true
stdout_logfile=/var/www/html/storage/logs/scout-worker.log

But when I issue a command like this, it doesn’t recognize the new scout-worker.conf:

docker exec cercasemi-laravel.test-1 supervisorctl reread

Why?

PHP executed success query echo breaks favicon

On all my pages I am echoing a success alert if the query was successfully executed, similarly if it does not there is an error message also echoed.

I have noticed every time the query has ran, and the echo is performed, it is breaking the favicon (i.e. the favicon icon does not load and the default grey globe is appearing). It also triggers Quriks Mode.

What methods can be utilised to echo deeper into the HTML (after all meta tags, scripts etc…) rather than at the very top of the opening body tag.

The favicon loads fine when laoding the page before any query is executed and after testing it is the echo that is causing this issue.

if($stmt->execute()) {
    
echo '<div class="alert alert-success alert-dismissible fade show notif-alert" role="alert">';
echo '<strong>Success!</strong> Password was changed successfully!';
echo '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>';
echo '</div>';

} else { 

echo '<div class="alert alert-warning alert-dismissible fade show notif-alert" role="alert">';
echo '<strong>Error!</strong> An error occured, please try again!';
echo '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>';
echo '</div>';
echo "Error: " . $stmt->error;
    
}

After the echo you can see where the div is being inserted

<body>
<div class="alert alert-success alert-dismissible fade show notif-alert" role="alert"><span><strong>Success!</strong> User information updated successfully!</span><button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button></div>

<meta charset="utf-8">

In like-dislike process, icons styling not working properly in PHP [closed]

I am working on a like-dislike process. I am using PHP for the backend. I have a table named comm_rating in my database.

(NOTE:- Suppose there are 2 users Alex and Siri.)

When Alex “likes” and Siri “dislikes” the post, then Siri see two “thumb-up” icons, and Alex see two “thumb-up” and two “thumb-down” icons, which is wrong.

For this, I want the suggestion what I am doing wrong.

The following codes are as follow-

$numSqlCommLike = "SELECT * FROM `comm_rating` WHERE `com_rat_blog_id`='40' AND `com_rat_com_id`='59' AND `com_rat_action`='like'";
$numResultLike = mysqli_query($conn, $numSqlCommLike);
$numRowsLike = mysqli_num_rows($numResultLike);
                                        
if ($numRowsLike>0) {
   echo '<button type="submit" class="like" name="button" value="like">';

   $likeSqlChangeColor = "SELECT * FROM `comm_rating` WHERE `com_rat_user_id`='31' AND `com_rat_blog_id`='40' AND `com_rat_com_id`='59' AND `com_rat_action`='like'";
   $likeResultChangeColor = mysqli_query($conn, $likeSqlChangeColor);
   $likeRowsChangeColor = mysqli_num_rows($likeResultChangeColor);

   if ($likeRowsChangeColor>0) {
      echo '<i class="fa-solid fa-thumbs-up"></i>';
   }else {
      echo '<i class="fa-regular fa-thumbs-up"></i>';
   }
                                                        
   echo '<p>'.$numRowsLike.'</p>
   </button>';

   $like_DislikeSqlChangeColor = "SELECT * FROM `comm_rating` WHERE `com_rat_user_id`='31' AND `com_rat_blog_id`='40' AND `com_rat_com_id`='59' AND `com_rat_action`='dislike'";
   $like_dislikeResultChangeColor = mysqli_query($conn, $like_DislikeSqlChangeColor);
   $like_dislikeRowsChangeColor = mysqli_num_rows($like_dislikeResultChangeColor);
   if ($like_dislikeRowsChangeColor>0) {
      echo '<button type="submit" class="dislike" name="button" value="dislike" style="display:none;"><i class="fa-regular fa-thumbs-down"></i><p>0</p></button>';
   }else {
      echo '<button type="submit" class="dislike" name="button" value="dislike" style="display:flex;"><i class="fa-regular fa-thumbs-down"></i><p>0</p></button>';
   }

}

// Number of comment dislikes
$numSqlCommDislike = "SELECT * FROM `comm_rating` WHERE `com_rat_blog_id`='40' AND `com_rat_com_id`='59' AND `com_rat_action`='dislike'";
$numResultDislike = mysqli_query($conn, $numSqlCommDislike);
$numRowsDislike = mysqli_num_rows($numResultDislike);
                                        
if ($numRowsDislike>0) {
    $dislike_LikeSqlChangeColor = "SELECT * FROM `comm_rating` WHERE `com_rat_user_id`='31' AND `com_rat_blog_id`='40' AND `com_rat_com_id`='59' AND `com_rat_action`='like'";
    $dislike_LikeResultChangeColor = mysqli_query($conn, $dislike_LikeSqlChangeColor);
    $dislike_LikeRowsChangeColor = mysqli_num_rows($dislike_LikeResultChangeColor);

    if ($dislike_LikeRowsChangeColor>0) {
        echo '<button type="submit" class="like" name="button" value="like" tyle="display:none;"><i class="fa-regular fa-thumbs-up"></i><p>0</p></button>';
    }else {
        echo '<button type="submit" class="like" name="button" value="like" tyle="display:flex;"><i class="fa-regular fa-thumbs-up"></i><p>0</p></button>';
    }

    echo '
    <button type="submit" class="dislike" name="button" value="dislike">';

    $dislikeSqlChangeColor = "SELECT * FROM `comm_rating` WHERE `com_rat_user_id`='31' AND `com_rat_blog_id`='40' AND `com_rat_com_id`='59' AND `com_rat_action`='dislike'";
    $dislikeResultChangeColor = mysqli_query($conn, $dislikeSqlChangeColor);
    $dislikeRowsChangeColor = mysqli_num_rows($dislikeResultChangeColor);

    if ($dislikeRowsChangeColor>0) {
       echo '<i class="fa-solid fa-thumbs-down"></i>';
    }else {
       echo '<i class="fa-regular fa-thumbs-down"></i>';
    }
    echo '<p>'.$numRowsDislike.'</p>
    </button>
    ';
}

if ($numRowsLike===0 && $numRowsDislike===0) {
   echo '
        <button type="submit" class="like" name="button" value="like"><i class="fa-regular fa-thumbs-up"></i><p>0</p></button>
        <button type="submit" class="dislike" name="button" value="dislike"><i class="fa-regular fa-thumbs-down"></i><p>0</p></button>
   ';
}

When Alex like-
when_Alex_like

when when Alex “like” and and Siri “dislike” in Alex id-
when Alex like and and Siri dislike @ Alex

when Alex “like” and Siri “dislike” in Siri id-
when Alex like and and rt dislike @ Siri

$_REQUEST[] or $_POST[] Undefined array key error [duplicate]

I have a PHP script that gets two parameters from an AJAX script on another page, but it gets an error on each $_REQUEST[], gets the same error if using $_POST[]

Undefined array key “visitor” in /home/tltl2347/public_html/pagevisited.php on line 7

Undefined array key “pagename” in /home/tltl2347/public_html/pagevisited.php on line 8

Here is the script

<?php

    date_default_timezone_set('Australia/Perth');
    $today = date('Y-m-d H:i:s');
    $logdata = "rn";

    $userAnswer = $_REQUEST['visitor'];
    $pageName = $_REQUEST['pagename'];
    $visitorip = $_SERVER['REMOTE_ADDR'];

    $visitor =  $userAnswer;
    $pagename = $pageName;
    $output = $today . "," . $visitor . "," . $pagename . "," . $visitorip . $logdata;

    if(($visitor !== 'JAMES BOND')) // Avoid registring myself
    {
       if($visitor !== "")
       {
         $file = fopen("pagevisit.csv","a");
         fwrite($file,$output);
         fclose($file);
       }
    }
?>

But the line:

$output = $today . "," . $visitor . "," . $pagename . "," . $visitorip . $logdata;

Is executed down correctly

Is there a way for me to hold on until $visitor and $pagename are taken?

Error when insert data with javascript form

I have an order creation form that allows me to enter information for several products to be linked to the order.
Each product can have production items, and I’d like to add the possibility of entering the number of products to be produced for each task.
The product and job parts of the form are dynamically generated by javascript.

The current problem is that my php file doesn’t handle the input corresponding to the quantity of products for the production tasks.

if i create an order with only 1 product, it correctly processes its production tasks and the quantity of each.
If I create an order with several products, the first one will be processed correctly, but for the subsequent products, the quantity of each task will not be retrieved and inserted.

Javascript product production posts form :

  function addProductField() {
    var productFields = document.getElementById("product_fields");
    var index = productFields.childElementCount + 1;

    fetch("production_posts.php").then(response => response.json()).then(data => {
      var productionPostsOptions = data.map(post => `
          <div class="form-check">
              <input class="form-check-input" type="checkbox" name="production_post_id_${index}[]" value="${post.id}" id="production_post_${post.id}_${index}">
              <label class="form-check-label" for="production_post_${post.id}_${index}">
                  ${post.name}
              </label>
          </div>
          <div class="mb-3">
              <label class="form-label" for="production_post_quantity_${post.id}_${index}">
                  Quantité totale pour ${post.name} du produit_${index}
                  production_post_quantity_${post.id}_${index}
                  production_post_quantity_${index}[]
              </label>
              <input type="number" class="form-control" name="production_post_quantity_${index}[]" id="production_post_quantity_${post.id}_${index}" placeholder="Quantité totale">
          </div>
      `).join("");
.....

php code for inserting products and their production tasks :

// Insérer les détails de produits dans la table order_product_details
    $product_count = count($_POST['product_name_']);
    for ($i = 0; $i < $product_count; $i++) {
        $product_name = $_POST['product_name_'][$i];
        $product_ref = $_POST['product_ref_'][$i];
        $product_attributes = $_POST['product_attributes_'][$i];
        $product_comment = $_POST['product_comment_'][$i];
        $product_rush = isset($_POST['product_rush_'][$i]) ? 1 : 0;
        $product_template = isset($_POST['product_template_'][$i]) ? 1 : 0;
        $product_production_days = (int)$_POST['product_production_days_'][$i];
        $product_production_days_rush = (int)$_POST['product_production_days_rush_'][$i];

        $product_custom_file_comment = $_POST['product_custom_file_comment_'][$i] ?? '';


        $stmt = $pdo->prepare("INSERT INTO products (name, product_ref, product_attributes, rush_option, template_option, production_day, production_day_rush, comment, product_state) 
        VALUES (:product_name, :product_ref, :product_attributes, :rush_option, :template_option, :production_day, :production_day_rush, :product_comment, 7)");
        $stmt->execute([
            ':product_name' => $product_name,
            ':product_ref' => $product_ref,
            ':product_attributes' => $product_attributes,
            ':product_comment' => $product_comment,
            ':rush_option' => $product_rush,
            ':template_option' => $product_template,
            ':production_day' => $product_production_days,
            ':production_day_rush' => $product_production_days_rush
        ]);
        $product_id = $pdo->lastInsertId();

        $stmt = $pdo->prepare("INSERT INTO order_products (order_id, product_id) VALUES (:order_id, :product_id)");
        $stmt->execute([
            ':order_id' => $order_id,
            ':product_id' => $product_id
        ]);

        $production_post_ids = $_POST['production_post_id_' . ($i + 1)] ?? [];
        $production_post_quantities = $_POST['production_post_quantity_' . ($i + 1)] ?? [];
    
        // Insérer les relations entre les produits et les étapes de production avec les quantités
        foreach ($production_post_ids as $index => $post_id) {
            $quantity = isset($production_post_quantities[$index]) ? (int)$production_post_quantities[$index] : 0;
    
            // Vérifier que les données sont valides
            if ($post_id && $quantity > 0) {
                $stmt = $pdo->prepare("
                    INSERT INTO product_production (product_id, production_post_id, production_post_state_id, total_quantity) 
                    VALUES (:product_id, :production_post_id, 1, :total_quantity)
                ");
                $stmt->execute([
                    ':product_id' => $product_id,
                    ':production_post_id' => $post_id,
                    ':total_quantity' => $quantity
                ]);
            }
        }
...

don’t hesitate to let me know if you’re missing any information or if there’s a problem with my code.

I tried changing the data insertion method and the form layout.
For each product, each production task must be inserted with the associated quantity entered in the total_quantity field of the product_production table.
Currently, if there are several products, this only works for the first product.

How do I write a menu using forms for each item that works across several directories?

I am using a header in my website that incorporates a menu that uses forms instead of href so that parameters can be passed. The problem is that when I go into another directory and click on one of the menu link, it tries to find that link in the directory that I am in and not in the root or another directory.

Here is the menu code using href in a directory

          <a href="../index.php" class="active">Home</a>  
          <a href="../membership/join.php"class="joinus">Join Us</a>  
          <a href="../publications/pubs.php?action1=about">About Us</a>

Here is the code in the homepage

          <a href="index.php" class="active">Home</a>  
          <a href="membership/join.php"class="joinus">Join Us</a>  
          <a href="publications/pubs.php?action1=about">About Us</a>

I am looking for a solution where a single menu can be used in the root and directories and sub-directories.

How to upgrade php version in aws docker

Im running an API written in PHP version 8.0.13 and while running any API calls I always see this WARNING on Cloudwatch:

- Deprecated: This installation of the SDK is using PHP version 8.0.13, which will be deprecated on January 13th, 2025.
- Please upgrade your PHP version to a minimum of 8.1.x to continue receiving updates for the AWS SDK for PHP.
- To disable this warning, set suppress_php_deprecation_warning to true on the client constructor or set the environment variable AWS_SUPPRESS_PHP_DEPRECATION_WARNING to true.
- More information can be found at: https://aws.amazon.com/blogs/developer/announcing-the-end-of-support-for-php-runtimes-8-0-x-and-below-in-the-aws-sdk-for-php/
- in /opt/vendor/aws/aws-sdk-php/src/ClientResolver.php on line 1456

The AWS article:
https://aws.amazon.com/blogs/developer/announcing-the-end-of-support-for-php-runtimes-8-0-x-and-below-in-the-aws-sdk-for-php/

Clearly, it says that I need to upgrade my PHP version to a minimum of 8.1.x

FROM amazon/aws-lambda-provided:al2 as builder 
ARG php_version="8.0.13"
RUN yum clean all && 
    yum install -y autoconf 
                bison 
                bzip2-devel 
                gcc 
                gcc-c++ 
                git 
                gzip 
                libcurl-devel 
                libxml2-devel 
                make 
                openssl-devel 
                tar 
                unzip 
                zip 
                openldap-devel 
                libzip010-compat 
                re2c 
                sqlite-devel 
                oniguruma 
                oniguruma-devel 
                file 
                wget 
                libldb-devel

RUN yum -y install https://archives.fedoraproject.org/pub/archive/epel/7/x86_64/Packages/e/epel-release-7-14.noarch.rpm 

RUN yum install -y libsodium 
                   libsodium-devel

RUN curl -sL https://github.com/php/php-src/archive/php-${php_version}.tar.gz | tar -xvz && 
    cd php-src-php-${php_version} && 
    ./buildconf --force && 
    ./configure --prefix=/opt/php-8-bin/ --with-openssl --with-curl --with-zlib --without-pear --enable-bcmath --with-bz2 --enable-mbstring --with-libdir=lib64 --with-ldap --with-mysqli && 
    make -j 5 && 
    make install && 
    /opt/php-8-bin/bin/php -v && 
    curl -sS https://getcomposer.org/installer | /opt/php-8-bin/bin/php -- --install-dir=/opt/php-8-bin/bin/ --filename=composer

COPY runtime/bootstrap /lambda-php-runtime/
RUN chmod 0755 /lambda-php-runtime/bootstrap

RUN mkdir /lambda-php-vendor && 
    cd /lambda-php-vendor && 
    /opt/php-8-bin/bin/php /opt/php-8-bin/bin/composer require guzzlehttp/guzzle && 
    /opt/php-8-bin/bin/php /opt/php-8-bin/bin/composer require aws/aws-sdk-php

RUN yum clean all && 
    rm -rf /var/cache/yum

FROM amazon/aws-lambda-provided:al2 as runtime
COPY --from=builder /opt/php-8-bin /var/lang
COPY --from=builder /lambda-php-runtime /var/runtime
COPY --from=builder /lambda-php-vendor/vendor /opt/vendor

COPY src/ /var/task/

RUN yum install -y oniguruma 
    oniguruma-devel

RUN yum clean all && 
    rm -rf /var/cache/yum

CMD [ "index" ]

The above is my current Dockerfile, How can I upgrade the version, what kind of testing needs to be done, would any functionality change?

How can I configure apache to play video file stored on local hard drive?

So sorry if this has been answered previously. I have searched for a solution without any luck. I have a Windows PC and have been using html files run from local drive using <a href=”file:/// links to various videos stored on local hard drives without any problems. When a link is selected the video will open and play in the video player (ZoomPlayer) I have installed. Only problem was any additions or deleted videos required rewriting the html code. I recently installed WAMP v3.3.5 usng php & MySql to help make the menu more automated and easier to manage. I store the video description and all the file information in a MySql database and use php to retrieve info needed to create the menu page. All working almost as intended, thanks to a lot of help I’ve received from this site. My problem I’ve run into is the file link would do nothing. Just to state that this is running only on a local lan and no ports have been opened on internet facing router. This isn’t intended to be accessed from the web.

I have setup an alias for each of the various drives in the Apache httpd.conf file. Now when a link is selected, the video downloads first to the windows temp folder then starts playing normally in Zoomplayer.
I have place AddType video/x-msvideo .avi AddType video/mp4 .mp4 AddType video/x-matroska .mkv in httpd.conf, but still have same result.

How can I avoid the download step and have it simply open in video player?

Failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in C:xampphtdocsfetch.php

<?php

$url = 'http://www.abc.in/abc/img/';
$base = 'http://www.abc.in/';

// Pull in the external HTML contents
$contents = file_get_contents( $url );

// Use Regular Expressions to match all <img src="???" />
preg_match_all( '/<img[^>]*src=["|'](.*)["|']/Ui', $contents, $out, PREG_PATTERN_ORDER);

foreach ( $out[1] as $k=>$v ){ // Step through all SRC's

    // Prepend the URL with the $base URL (if needed)
    if ( strpos( $v, 'http://' ) !== true ) $v = $base . $v;

    // Output a link to the URL
    echo '<a href="' . $v . '">' . $v . '</a><br/>';
}



error msg

Warning: file_get_contents(http://www.abc.in/abc/img/): Failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in C:xampphtdocsfetch.php on line 9

  1. my remote server is godaddy
  2. allow_url_fopen On
  3. full control access given to directory

display list of files in a directory in a remote server

youtube dgUB1PJCVHk: Sign in to confirm you’re not a bot. This helps protect our community. Learn more

I am using norkunas/youtube-dl-php package in my Laravel application to sync youtube videos in my platform. But recently it was not sysncing videos. When i debug this i got this error
enter image description here

here is the piece of code i am using

$data =  $youtubeDL->download(
            Options::create()
                ->skipDownload(true)
                ->downloadPath(storage_path('app/temp/yt/' . $userId))
                ->output('%(id)s.json')
                ->url($channelUrl)
                ->cookies(storage_path('app/cookies.txt'))
        );

Tried to find solution but didn’t get any proper solution. I tried adding cookies as well but it still not working.

Please suggest on this thanks.

get product by attribute in woocommerce

I have products with many attributes. Attribute values can be size,color,… . I am trying to create a custom search but I can’t get the query to pull any product.

    $product_attributes = wc_get_attribute_taxonomies();
    
    $attributes = array();
    foreach ($product_attributes as $attribute) {
        $attribute_name =  $attribute->attribute_name;
        $attribute_value = isset($params[$attribute_name]) ? $params[$attribute_name] : '';
        if (!empty($attribute_value)) {
            $attributes['pa_' .$attribute_name] = $attribute_value;
           
        }
    }
    
    $ordering              = WC()->query->get_catalog_ordering_args();
    $ordering['orderby']   = array_shift(explode(' ', $ordering['orderby']));
    $ordering['orderby']   = stristr($ordering['orderby'], 'price') ? 'meta_value_num' : $ordering['orderby'];
    
    dump($attributes);
    $args = array(
        'status' => 'publish',
        'limit' => -1,
        'return'            => 'ids',
        'stock_status'      => 'instock',
        'visibility'        => 'visible',
        'paginate'          => true,
        'orderby'           => $ordering['orderby'],
        'order'             => 'DESC',

        'attribute' => $attributes,
    );

    $products = wc_get_products($args);

what`s the problem

Allowed memory size of 134217728 bytes exhausted into Bugsnag library

I see a few errors like this (different parts of Bugsnap):

production.ERROR: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) {"exception":"[object] (Symfony\Component\ErrorHandler\Error\FatalError(code: 0): Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) at /var/www/html/vendor/bugsnag/bugsnag/src/Report.php:683)

But I have memory_limit=3G for PHP CLI and FPM, and I don’t have ‘ini_set’ for memory_limit into PHP code.

So my question is: how I can find and fix the source of these errors?

PHPStan / @return all possible children that extend specific class

I have a problem with @return types. It seems that either it’s a bug in PHPStan or I’m doing something wrong.

Error:

abstract class Aclass {}
final class Bclass extends Aclass {}
final class Cclass extends Aclass {}

final class Factory {
    /**
     * @template T of Aclass
     * @param class-string<T> $param
     * @return T
     */
    public function create($param) {
        // some kind of factory logic
        return new Bclass();
    }
}

No error:

abstract class Aclass {}
final class Bclass extends Aclass {}
final class Cclass extends Aclass {}

final class Factory {
    /**
     * @template T of Aclass
     * @param class-string<T> $param
     * @return Aclass
     */
    public function create($param) {
        // some kind of factory logic
        return new Bclass();
    }
}

Why does PHPStan give me an error? Isn’t @template T of Aclass + @return T the same as @return Aclass?

I’m expecting no errors.