Writing a function to return common values from different arrays PHP

So iv’e been solving different php problems but I’ve been stuck on this one any solution?

<?php

$array1 = array("banana", "pear", "apple", "orange");
$array2 = array("yellow", "orange", "green");

function commonValue($tab = [], $tabTwo = []) {
    //----------do not modify the code above----------
    
    //----------do not modify the code bellow----------
}

commonValue($array1, $array2); // return ["yellow"];

Always get exception when login with JWT Management Session

I try to learn how to manage session with JWT. But now I’m stuck because i always get exception after login, and it always redirect me to login page again and again.

There is no error detected, and i can’t find what’s wrong in my code. So i hope you all can help me although it is just look like a simple questions

I try to browse to check where is the problem. And i’m sure the problem is in the file session.php. But i don’t know whats wrong

<?php

// use FirebaseJWTJWT;

class Session
{
    public $username, $role;
    public function __construct(string $username, string $role)
    {
        $this->username = $username;
        $this->role = $role;
    }

}

class SessionManager
{

    // public $SECRET_KEY = 'ajfhakjdfhah/A203FHkafhiuefhhncueuvuwevwevwev';

    public static function login(string $username, string $password): bool
    {
        if ($username == "eko" && $password == "eko") {

            $SECRET_KEY = 'AKDJHFEVN123akdhfvbuevmkc';
            $payload = [
                "username" => $username,
                "role" => "customer"
            ];

            $jwt = FirebaseJWTJWT::encode($payload, $SECRET_KEY, 'HS256');
            setcookie('USER-SESSION', $jwt);
            
            return true;
        } else {
            return false;
        }
    }

    public static function getCurrentSession(): Session
    {
            
        if ($_COOKIE['USER-SESSION']) {
            $jwt = $_COOKIE['USER-SESSION'];
            $SECRET_KEY = 'AKDJHFEVN123akdhfvbuevmkc';
            $payload = FirebaseJWTJWT::decode($jwt, $SECRET_KEY, ['HS256']);
            try {
                $payload = FirebaseJWTJWT::decode($jwt, $SECRET_KEY, ['HS256']);

                return new Session($payload->username, $payload->role);                
            } catch (Exception $exception) {
                throw new Exception("User is not login");                
            }
            
        } else {
            throw new Exception("User is not login");
        }
    }

}

I downloaded a laravel project online and its not working

I downloaded a laravel project online from link
I ran the command is composer update and composer install.
The error i’m seeing is:

In ProviderRepository.php line 208:

  Class "CollectiveHtmlHtmlServiceProvider" not found


Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1

Need help solving this urgent

I was expecting this to run in laravel 9

Multiple Query In SQL

I have a table by name material transaction and I want to display data like Table B

Item Name Transaction Type Weight
A Issue Material 60
B Issue Material 80
A Return Material 20
B Return Material 10
A Issue Material 20
B Issue Material 10

I want result like below table
Table B

Item Name Issue Material Return Material
A 80 20
B 90 10
$query = "SELECT item_name, SUM(material_wt) AS issue_material WHERE transaction_type = 'Issue Material' FROM material_transaction GROUP BY item_name UNION ALL SELECT item_name, SUM(material_wt) AS return_material WHERE transaction_type = 'Reject Material' FROM material_transaction GROUP BY item_name";
                        $select_query_table = mysqli_query($connection,$query);
                        while($run_select_query = mysqli_fetch_assoc($select_query_table)){
                 
                     $item_name = $run_select_query['item_name'];  
                     $wt = $run_select_query['material_wt'];  
                        echo "<td>$item_name</td>";                          
                       echo "<td>$wt</td>";                          
                        echo "</tr>";
                   
                    }

I can’t verify if there is a duplicate email in my local db. When I register for the first time it’s working and the second time I got an error

And I know my error is due to email adress because when I submit a new user to the form, it’s working well but when I change all the informations except the email adress I got the error 500 Internal Server Error

My code for register

<?php

include 'DbConnect.php';
$objDb = new DbConnect;
$conn = $objDb->connect();

$data = json_decode(file_get_contents('php://input')) ;

$first_name = $data->first_name;
$name = $data->name;
$email = $data->email;
$password = $data->password;
$password_confirm = $data->password_confirm;


$password_hash = password_hash($password, PASSWORD_DEFAULT);


$method = $_SERVER['REQUEST_METHOD'];

switch($method){
    case "POST":

        $sql = "INSERT INTO register(name, first_name, email, password_hash) VALUES ('$name', '$first_name', '$email', '$password_hash')";
        $stmt = $conn->prepare($sql);

        if($stmt->execute()){
            $response = ['status' => 1, 'message' => 'Record created succesfully. '];
        }else{
            $response = ['status' => 0 , 'message' => 'Failed to create record. '];
        }

        echo json_encode($response);
        break;
}
?>

Parse HTML as PHP on a Azure App Service (Linux) running PHP 8.1

I am really struggling to get an Azure App Service running Linux and PHP 8 or 8.1 to parse HTML files through PHP. The 8.0 and 8.1 versions run on nginx rather than Apache.

I have started by updating the nginx blocked used by the app service, located at /etc/nginx/sites-enabled/default, to read the below. This is as per default, except adding the HTML location alongside PHP:

server {
    listen 8080;
    listen [::]:8080;
    root /home/site/wwwroot;
    index  index.php index.html index.htm;
    server_name  example.com www.example.com;
    port_in_redirect off;

    location / {
        index  index.php index.html index.htm hostingstart.html;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /html/;
    }

    location ~ [^/].(php|html)(/|$)  {
        fastcgi_split_path_info ^(.+?.php)(|/.*)$;
        fastcgi_pass 127.0.0.1:9000;
        include fastcgi.conf;
        fastcgi_param HTTP_PROXY "";
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param QUERY_STRING $query_string;
        fastcgi_intercept_errors on;
        fastcgi_connect_timeout         300;
        fastcgi_send_timeout           3600;
        fastcgi_read_timeout           3600;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;
    }
}

This correctly then attempts to parse HTML files through PHP, however they all then display the following error:

NOTICE: Access to the script ‘/home/site/wwwroot/login.html’ has been denied (see security.limit_extensions)

I have then gone to /usr/local/etc/php-fpm.d/www.conf and added the following line:

security.limit_extensions = .php .php3 .php4 .php5 .php7 .html

Normally, this would then work. Under an App Service however, I still receive the security.limit_extensions error message. Running php-fpm -tt appears to show the correct settings are in place and applied.

Other posts reference SeLinux, which doesn’t appear to be running, and cgi.fix_pathinfo which is set to 1.

I am aware the above files do not maintain on app services after a restart, but are currently in place.

Has anyone (Please!!) got this to work and successfully parsed HTML as PHP on PHP8.1, as an Azure App Service?

WordPress ReWrite rules for custom page

I have a custom WordPress page, and I want to add some rewrite rules.

The page works when I visit it at domain.com/kb and domain.com/kb?kb_cat=123&kb_seq=456

I added this code to create the rewrite rule so I could use domain.com/kb/123/456 but it gives me a 404

add_action( 'init', 'nearme_rewrite_rules');
function nearme_rewrite_rules() {
    add_rewrite_rule('^kb/([^/]*)/([^/]*)/?','kb?kb_cat=$matches[1]&kb_seq=$matches[2]','top');
}

add_filter('query_vars', 'kb_vars', 0, 1);
function kb_vars($vars){
    $vars[] = 'kb_cat';
    $vars[] = 'kb_seq';
    return $vars;
}

I’ve logged into WP and re-saved the permalinks which still had no effect.

How can I properly show the image from the store folder I have

<td><img class="prod-images" src="../CAPSTONE/uploaded_img/<?php echo $values['image'];?>"/></td>

Basically am trying to make the image appear but for some reaon it doesn’t display the image

enter image description here

The image should be displayed at the product image.

Am not really sure if its the path that is wrong or something I tried checking the path file of it, trying different types of path locations but it seems not working

How to write multiple rule in .htaccess for multiple pages

Here is my code, it works properly for the first one but for the second one it redirects me to the blog.php

Options -Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ blog.php/$1  [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ category.php/$1  [L]

How to redirect on the category.php

Recusrive function to calculate scores

I have an array as follows:

$array = [
    [
        'result' => null, 
        'weight' => 50, 
        'children' => [
            ['result' => 5, 'weight' => 50, 'children' => []],
            ['result' => 5, 'weight' => 50, 'children' => []]
        ]
    ],
    [
        'result' => 3, 
        'weight' => 50, 
        'children' => []
    ],
];

What I would like to achieve is run a function, like:

function calculateScores(&$array)
{

}

calculateScores($array);

with the desired result:

$array = [
    [
        'result' => 5, 
        'weight' => 50, 
        'children' => [
            ['result' => 5, 'weight' => 50, 'children' => []],
            ['result' => 5, 'weight' => 50, 'children' => []]
        ]
    ],
    [
        'result' => 3, 
        'weight' => 50, 
        'children' => []
    ],
];

So, basically. If an entry has children, its score must be calculated by multiplying the results with the respective weights of these.

As the $array could have more than one level, a recursive function could do the job.

However, I have a very hard time to come up with an approach at all. I tried several ideas without any success.

Search in multiple array

I am beginner in php.
I have this array: https://ibb.co/qyMrMYp
And this php code:

$trybStatusCzynnosciArray = process::getTrybStatusCzynnosciArray();

$result = findPair(1, 2, 3, $trybStatusCzynnosciArray )

function findPair($trybbm, $statpm, $czynpm, $array)
{


return true / false;

}

In function findPair() i need return true or faile.
When pairs of number exist in array $trybStatusCzynnosciArray – i need true. In not – i need false.

How can i make this function?

Plaese help me 🙂

$trybStatusCzynnosciArray = process::getTrybStatusCzynnosciArray();

$result = findPair(1, 2, 3, $trybStatusCzynnosciArray )

function findPair($trybbm, $statpm, $czynpm, $array)
{


return true / false;

}

Hot to fix this warning? [duplicate]

im new in PHP.
I want to make my first mini project “Todo APP” and i have a problem with $_POST array.

Error:
Warning: Undefined array key “task” in C:xampphtdocsTODOAPPindex.php on line 24

My code:

$task = $_POST["task"];
$error ="";
$todo = array ();

if(isset($_POST["submit"])){
  
if(empty($_POST["task"])){
    $error="najpierw wypełnij pole";    
}
else{
    array_unshift($todo, $_POST["task"]);
    $sql= "INSERT INTO `todo` (`id`, `task`) VALUES ('0', '$task')";
    $rs = mysqli_query($linkDB, $sql);
}
}

How can i fix this warning ?

I dont know how to fix it, i tried to change if with $task=$_POST["task"] in side but i think is bad form for code.

How can i send this getBalance request using curl in php?

Documentation information :

[1](https://i.stack.imgur.com/P41Eb.png);
[2](https://i.stack.imgur.com/w17Tp.png);
[3](https://i.stack.imgur.com/m8RIG.png);
[4](https://i.stack.imgur.com/vz8nR.png);

this is documentation info, please help.

I am at my beginnings in programming and I need help to use this documentation on one of my projects.