I want to run a Cron job for php File that should run after 30 minutes. But My File has a session varibale And cron job is not working

Here i have a connection in my config file. and when i run this file after login, All queries are working properly but when i added into this in cronjob then this script is not working.
this is my cron job url.

/usr/local/bin/php /home/wi095p7714d0/public_html/fenc/cron.php
<?php
session_start();
session_regenerate_id(true);
include('../includes/config.php');

if(!isset($_SESSION['login_id'])){
    header('Location: login.php');
    exit;
}

$id = $_SESSION['login_id'];
$intiatlamount=0;
$get_user = mysqli_query($conn, "SELECT * FROM `users` WHERE `email`='$id'");
$getuserid=mysqli_fetch_array($get_user);
$userid=$getuserid['id'];

$wallet= mysqli_query($conn, "SELECT * FROM `wallet` WHERE `uid`='$userid'");
$getwalletbalance=mysqli_fetch_array($wallet);
$walletid=$getwalletbalance['id'];
$walletbalance=$getwalletbalance['balance'];

$spent=mysqli_query($conn, "SELECT * FROM `spent` WHERE `wid`='$walletid'");
if(mysqli_num_rows($spent)< 1){
    $insertspent=mysqli_query($conn, "INSERT into spent (wid,amount)VALUES('$walletid','$intiatlamount')");
}else{
   $getspentq=mysqli_query($conn, "SELECT * FROM `spent` WHERE `wid`='$walletid'");
   $getspent=mysqli_fetch_array($getspentq);
   $spentvalue=$getspent['amount'];
   $newspent=$spentvalue + 1;
   $finalwalletbalance=$walletbalance-$newspent;
   $updatespent=mysqli_query($conn,"UPDATE spent SET amount='$newspent' WHERE wid='$walletid'");
   $updatewallet=mysqli_query($conn,"UPDATE wallet SET balance='$finalwalletbalance' WHERE uid='$userid'");
}
?>

RegEx in PHP: match several links in one line of text

I would like to match url with specific text from long line of text. But the problem is that there can be several links in that line. Sample text:

AAAAAA <a href="https://BBB.com">TEST1</a> CCC <a href="https://DDD.com/EEE-FFF/">GGGG</a> AAAAAA

And I would like to match link with “EEE-FFF” to delete this url later by preg_replace, so my goal is to get:

AAAAAA <a href="https://BBB.com">TEST1</a> CCC GGGG AAAAAA

I tried something like this:

/<a.*?EEE-FFF.*?>(.*?)</a>/U

But it match two links as a one. How can I fix it?

Unable to find the socket transport “ssl” pecl packages are unreachable

I’m trying to use pecl, but everytime I got this error message. I don’t have xampp. I don’t have any apache, I’m using only the built in php server. So I don’t have xampp directory, it’s only C:php for me. Now I edited the php.ini file, I removed the semicolon from the extension openssl, but it’s still erroring. Do I have to download any OpenSSL directory? I tried, but it’s only a git repository, what needs a lot of other applications to run… I don’t know if I really need to download Embarcadero C++, and MinGV? That seems too complicated to me… I wanted to use some packages, like php memcache, and oci, but for that I had to install pear (it was NOT included in php), then install pecl, then I have to install these C++ apps, and MinGV to run OpenSSL to be able to download pecl packages? No way…
Windows 10 64x
PHP 8.0.12

how to create array php into blank braces [duplicate]

i’m trying to make a php array, i need to create array with blank braces variable like {}, but if i use array() the data shows [] square bracket, how to create variable into {}

php code:

<?php

    $newArray = array("name"=>"SMK Bina Rahayu", "grade"=>"below", "parent"=>array());

    $afterEncode = json_encode($newArray);

    print_r($afterEncode);

?>

the result :

{
  "name": "SMK Bina Rahayu",
  "grade": "below",
  "parent": [
    
  ]
}

the result that i need or i want:

{
  "name": "SMK Bina Rahayu",
  "grade": "below",
  "parent": {}
}

is it possible to make the blank array from square bracket into braces?
i need to change it because i want to use cloudflare api that only accept braces in blank variable and not square brackets

How to pass a string to a blade component?

As an example there is this component:

resources/views/components/example.blade.php

<div>
    @if($foo === "bar")
        Bar
    @else
        Foo
    @endif
</div>

that I render like

@php
   $foo = "bar";
@endphp
<x-example :foo="$foo" />

what is working.
But to have my code looking cleaner, I want to pass the string directly to the component, but the following I tried are not working:

<x-example :foo="bar" />
<x-example :foo='bar' />
<x-example :foo="'bar'" />
<x-example :foo="'bar'" />
<x-example :foo=""bar"" />

Execute PHP using javascript innerText

I am trying to embed a form in to the Bootstrap 5 modal dynamically, I have 3 buttons each linking to different forms and they have data-bs-* attributes for the form ID and form title so that they can be inserted into the modal, I just can’t seem to execute the PHP action to load the form.

These are the buttons:

<a href="#" data-bs-toggle="modal" data-bs-target="#formModal" data-bs-form="1" data-bs-formtitle="Form #1">Click here to load form #1</a>
<a href="#" data-bs-toggle="modal" data-bs-target="#formModal" data-bs-form="2" data-bs-formtitle="Form #2">Click here to load form #2</a>
<a href="#" data-bs-toggle="modal" data-bs-target="#formModal" data-bs-form="3" data-bs-formtitle="Form #3">Click here to load form #3</a>

This is the javascript I have copied from the Bootstrap 5 modal documentation with a bit of modification:

const formModal = document.getElementById('formModal')
// When modal is opened, do the following:
formModal.addEventListener('show.bs.modal', event => {
    // Button that triggered the modal
    const button = event.relatedTarget
    // Extract info from data-bs-* attributes
    const formid = button.getAttribute('data-bs-form')
    const formtitle = button.getAttribute('data-bs-formtitle')
    // Select title/body containers for the modal
    const modalTitle = formModal.querySelector('.modal-title')
    const modalForm = formModal.querySelector('.modal-body')
    // Update the modal's content.
    modalTitle.textContent = formtitle
    modalForm.innerHTML = `gravity_form(${formid}, false, false, false, '', true, 50);`
})

This just outputs the PHP action as plain text. I have also tried outputting the shortcode for the form but again this just outputted as plain text:

modalForm.innerHTML = `[gravity_form id="${formid}" title="false" description="false" ajax="true"]`

PHP error log does not log when calling AJAX PHP script

I have a problem with PHP error log creation. The error log prints fine when
i access my index.PHP which contains just phpinfo() function to try out the error logging.

However when I’m using AJAX to forward Javascript request to .PHP page, the PHP error
logging does not work.

I have this javascript function on my index.html:

ajax_request.open(‘POST’, ‘search_foodinfo.php’);

On the browser dev tools it says that the POST function succeeded:

enter image description here

In the /var/log/apache2/error.log there’s no new row appearing. New row appears correctly when running index.php with phpinfo() function on it, but not with this POST request. What could be the problem? I’m using the PHP error logging functionality to debug my software in development.

PHP, MySQL, – email isn’t in loop

i have a little problem with loop with my PHP code.
I selecting data from my SQL database.
The column with name ’email’ is looping correctly but when i click on button – send message to selected email which is locating in variable $to, the email is still only sent to the first record ([email protected]) from database.

<?php

    $query = "select * from vodicakyksk_tbl_test";
    $result = mysqli_query($link,$query);
  
  if ($result-> num_rows > 0) {
        while ($row = $result-> fetch_assoc()) {
          
          
        echo '<form action="" method="POST">';
              
          $images = $row['image_name'];
          $images = explode(',',$images);
          
          if(isset($_POST['buttonyes'])) {

          $to = $row['email'];
          $subject = 'Test subject';
          $message = '
          <html>
          <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
            <title>Email title</title>
          </head>
          <body>
            <h1></h1>
          </body>
          </html>
          ';
          $headers[] = 'MIME-Version: 1.0';
          $headers[] = 'Content-type: text/html; charset=UTF-8';
          $headers[] = 'To: Admin <[email protected]>';
          $headers[] = 'From: ADMINISTRATOR <[email protected]>';

          mail($to, $subject, $message, implode("rn", $headers));
             }
          
          echo '<div class="div">';
          echo '<p class="first-item">Meno a priezvisko<br>'.$row['meno'].'</p>';
          echo '<p class="first-item">Dátum narodenia<br>'.'<span>'.$row['den'].'.</span>&nbsp;'.'<span>'.$row['mesiac'].'.</span>&nbsp;'.'<span>'.$row['rok'].'</span>'.'</p>';
          echo '<p class="first-item">Email<br>'.$row['email'].'</p>';
          echo '<p class="skola">'.$row['skola'].'</p>';
          echo '<p>'.$row['prva_oblast'].'</p>';
          echo '<p>'.$row['druha_oblast'].'</p>';
          echo '<p>'.$row['prvy_odkaz'].'</p>';
          echo '<p>'.$row['druhy_odkaz'].'</p>';
          echo '<p class="odkaz-div">'.$row['gdpr'].'</p>';
          echo '<div class="image-holder">';
          foreach($images AS $image){
          echo '<img src="images/'.$image.'" alt='.$image.'>';
    }
          echo '</div>';
          echo '<input type="submit" name="buttonyes" value="YES">';
          echo '<input type="submit" name="buttonno" value="NO>';
        }
      echo '</form>';
    }
    ?>

Can someone help me what I’m doing wrong?

can’t insert data into the database [closed]

I made a form with the code below. As you can see at the bottom of the picture. When I tried submit the data into my database, the data wasn’t inserted.

HERE IS MY db_connection.php 

<?php

 $dbhost = "localhost";
 $dbuser = "root";
 $dbpass = "";
 $db = "test";
 
 $conn = new mysqli_connect($dbhost, $dbuser, $dbpass, $db);

?>

Here is my signup.php
<?
include_once 'db_connection.php';
if(isset($_POST['submit'])){
        if(!empty($_POST['name']) && empty($_POST['owner']) && empty($_POST['location']) && empty($_POST['region']) && empty($_POST['district']) && empty($_POST['street']) && empty($_POST['mobile']) && empty($_POST['address']) && empty($_POST['email'])){
                $name = $_POST['name'];
                $owner = $_POST['owner'];
                $location = $_POST['location'];
                $region = $_POST['region'];
                $district = $_POST['district'];
                $street = $_POST['street'];
                $mobile = $_POST['mobile'];
                $address = $_POST['address'];
                $email = $_POST['email'];

                $sql = "INSERT INTO agency_details ('name', 'owner', 'location', 'region', 'district', 'street', 'mobile', 'address', 'email') VALUES ('$name', '$owner', '$location', '$region', '$district', '$street', '$mobile', '$address', '$email');";
                $RUN = mysqli_query($conn, $sql);

                 header("Location:./index.php?signup=success");
        }
}
?>  

How to set the number of objects created for Sequence (Laravel 8)

I’m trying to create 30 news using Seeder and Factory. But I need to create 10 news with a non-empty field value published_at (Carbon) а для остальных случайное значение (Carbon/NULL)

In the documentation I saw such an example, it creates 5 records with the value admin (Y) and 5 more records with the value admin (N)

User::factory()
    ->count(10)
    ->state(new Sequence(
        ['admin' => 'Y'],
        ['admin' => 'N'],
        ))
        ->create();

So far I’m using this code, but I can’t figure out how to add the number of records being created with a certain parameter value published_at. For example, 10 with Carbon and 20 with NULL.

/** ArticleSeeder */
Article::factory()
    ->count(30)
    ->state(new Sequence([
        'published_at' => Factory::create()->dateTimeBetween(
            now()->startOfMonth(),
            now()->endOfMonth()
        ),
    ]))
    ->create();

Break line in Multi Cell FPDF with various text properties

I’m trying to make a box which contains 2 lines of text which have their own text properties using FPDF library :

I know i can use the multicell here,
but how about text property like text size and font family ?

This is my current code :

public function print()

{
    $this->fpdf->AddPage('L',[100,150]);
    
    $this->fpdf->SetFont('Arial','B',16);
    $this->fpdf->MultiCell(130,8,utf8_decode('Material description :' . chr(10) . 'V-001940 LCMS AA001'),1);
    
    $this->fpdf->Output();
}

my current output :

current output

expected output :

expected output

Is it possible to do this ?

and also its strange that when im using the ‘n’ to insert breaks, nothing happened, hence i need to use this line of code instead :

utf8_decode('Material description :' . chr(10) . 'V-001940 LCMS AA001')

What is the solution ?

Why 2 files downloaded by the same code of php are different?

There are 2 php files

if($_SERVER["REQUEST_METHOD"]=="GET")
{
    if(isset($_GET['testo']))
    {
        if(logged($_GET['testo']))
    {
        $filename = "Demon.zip";
        $filepath = 'uploads/' . $filename;
    
        if(!empty($filename)&& file_exists($filepath))
        {
           $demo_name = "Demon.zip";
           header('Content-type: application/zip');  
           header('Content-Disposition: attachment; filename="'.$demo_name.'"');  
           readfile($demo_name); // auto download
        
            exit;
        
        }
        else
        {
            //comments
        }
    }
    else
    {
        //comments
    }
    }
    else
    {
        //comments
    }        
}
else
{
    //comments
}

From this file I can download from the server but the zip file I downloaded can’t be unzipped by an applications.

<?php
           $demo_name = "Demon.zip";
           header('Content-type: application/zip');  
           header('Content-Disposition: attachment; filename="'.$demo_name.'"');  
           readfile($demo_name); // auto download
?>

Instead this file can be downloaded and can be unzipped. I discovered that the size of the downloaded file from the first file is bigger than the another one… I don’t know why, the download code is same!!! How can I solve this?

Laravel exception: 1366 Incorrect string value: ‘\xC0\xA7\xC0\xA2%2…’ for column ‘user_agent’

Occasionally I will get the following exception thrown from Laravel:

"class": "Illuminate\Database\QueryException",
    "message": "SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xC0\xA7\xC0\xA2%2...' for column 'user_agent' at row 1 (SQL: update `sessions` set `payload` = testpayload, `last_activity` = 1663058232, `user_id` = ?, `ip_address` = ipAddress, `user_agent` = 1 ����%2527%2522 where `id` = blahblah)"

From what I have read, it most likely is that my table is not using the correct encoding and maybe a special character (something like Ö) is being used inside the user_agent from someone viewing the site and therefore it throws an error.

But checking that, I assume if I have the default Laravel setup, how others have not run into the same issue. Checking my setup:

config/database.php

            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',

^ and confirming in the db itself, this is what I am using.

I then suspected maybe when I upgraded from Laravel 5.x > 7.x maybe a migration changed or something and I should be using a different charset. But checking migrations and also the db config for version 7, nothing has changed.

Laravel Version: 7.30.4

Mysql Version: 5.7.33-log

Anyone seen this before or point me in the right direction?