Google Cloud API php authentication fails

I closely followed the docs

https://github.com/googleapis/google-api-php-client/blob/main/docs/oauth-server.md

https://developers.google.com/android-publisher/getting_started?hl=en

  1. Created an service account on Google Cloud Console

  2. generated the key json file and saved as credentials.json

  3. enabled Google Play Android Developer API

  4. invited the service account email in the Google Play Console

  5. granted the permissions

  6. i use this code in php

     putenv('GOOGLE_APPLICATION_CREDENTIALS='.__DIR__.'/credentials.json');
     $client = new GoogleClient();
     $client->useApplicationDefaultCredentials();
     $client->addScope('https://androidpublisher.googleapis.com');
     $service = new Google_Service_AndroidPublisher($client);
    

We get this error message:

"error": {
    "code": 401,
    "message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
    /n"errors": [
      {
        "message": "Invalid Credentials",
        "domain": "global",
        "reason": "authError",
        "location": "Authorization",
        "locationType": "header"
      }
    ],
    "status": "UNAUTHENTICATED"

May or may not be relevant, but the google account on Google Cloud and Google Play Console is the same and part of Google Workspaces but not the organisations account (the same procedure with the organisation account yields the same error message though)

How to display created custom fields on front end – ACF plugin in WordPress – PHP Code

I have a custom field called “number of flags” created using ACF plugin in WordPres.

What I’m Trying to do is to give all admins of the site a ( number of flags ) option to assign to each user they want and then display these number of flags in ( my account page ) in a shape of small flag icon.

So if the user ( Katie ) has 4 flags for example she can sign in and go to my account page to see 4 flags somewhere in the page (in the shape of 4 small flag icons ). and so on for each user.

I assume this can be done with some PHP code but I’m still new and learing PHP.

Any help would be aprreciated. Thx PHP Experts

ScreenShot 1
ScreenShot 2

Adding custom data to middleware response in laravel 9 or 10 php

I want to implement a user tracking system, after searching I realized that I have to do this in the middleware. The problem I had was that I could only add values to the response header in the answers that were in the middleware. And after saving their information, delete them in the middleware response. Please guide me how to add custom data to the middleware response, thanks

For this, I found 2 examples that work in json mode, but in the case that I want to transfer the user to the route, I have to use headers.

Sample code for json response:

return $response->json([
                    'status' => $status,
                    'code' => $code,
                    'errors' => [$errors],
                ], $status);

An issue with Ajax to add or remove class with php

The problem that has arisen is that completely randomly and after I toggle some notes to get the done or pending theme, some of them do not show the class change. For example, the first one turns from red to green, the second one turns green. Yes, the third one does not turn green!!

By refreshing the page, I realized that the theme has also changed, but the page must be refreshed. This problem is only for toggle and not for remove. See the codes …

html:

<ul class="todo-entry <?= $doneClass ?>">
    <li>
        <span onclick="noteToggle(this, <?= $record['note_id'] ?>)" class="btn"> * </span>
    </li>
</ul>

jquery:

function noteToggle(sender, noteId) {
    sender = $(sender);
    var parent = sender.parentsUntil().parent();
    $.ajax('<?= baseUrl() ?>/note/toggle/' + noteId, {
        type: 'post',
        dataType: 'JSON',
        success: function (data) {
            if (parent.hasClass('done')) {
                parent.removeClass('done');
                parent.addClass("pending");
            } else {
                parent.removeClass('pending');
                parent.addClass("done");
            }

        }
    });
}

php : note/toggle Controler

public function toggle($noteId)
{

    if (!isset($_SESSION["user_id"])) {
        exit;
    }

    $userId = $_SESSION["user_id"];
    NoteModel::toggle($noteId, $userId);
    echo json_encode(array("status" => true,));
}

noteModel Class:

public static function toggle($noteId,$userId){
        $db = Db::getInstance();
        $db->modify(" UPDATE table_name SET isDone= NOT isDone WHERE note_id = $noteId  AND user_id = $userId");
    }

I tried many options and I didn’t get JavaScript error in the browser either. By hitting the toggle, the classes are applied and the theme is changed, but this does not happen only for some notes, which is applied by refreshing the theme page.

php array sorting with national signs and lowercase and uppercase letters

As I can see, this problem has not been properly solved. I think I went through all the suggested solutions, but it was based on patching a specific problem. Which clearly, in my opinion, indicates a lack of PHP support for a correct solution to the basic, nastiest situation. It’s about correct sorting (ascending or descending) for an array containing lowercase and uppercase letters and specific national characters. The solution below, which I am currently using, sorts lowercase and uppercase letters correctly but throws out national characters at the very end. None of you would like it. Array_multisort, mb_strcasecmp and collate are not working properly.

(pl-PL)

f.eg.

balkon
Bażant
goleń
Gęś
Koza
kuchnia
mąka
mięso
Struś
Wiewiórka
Zając
Łopian
Świnia

 usort($file_info_all, function ($a, $b) {
   return strcasecmp($a['file_info_01c_text'], $b['file_info_01c_text']);
    });

correct

balkon
Bażant
Gęś
goleń
Koza
kuchnia
Łopian
mąka
mięso
Struś
Świnia
Wiewiórka
Zając

alphabet:
a ą Ą b c ć Ć d e ę Ę f g h i j k l ł Ł m n ń Ń o ó Ó p r s ś Ś t u v x y z ż Ż ź Ź

Foreach iterating for most but not all items [closed]

I don’t know enough PHP, but for a while I had the code below working successfully. Now the output list has grown and the code now iterates most but not all the items:

<table>
    <?php
    
    foreach($TTFallOtherList_result as $TTFallOtherList_row){ ?>
    
    <tr><td><span class="title"><?php echo $TTFallOtherList_row['fieldData']['FCSTTFh_BiblioInfoDisplayCSS']; ?> by <?php echo $TTFallOtherList_row['fieldData']['FCSTTF_AuthorDisplay_calc']; ?></span></td><td><?php echo $TTFallOtherList_row['fieldData']['FCSTTFh_0BibleBookAllCSS_calc']; ?></td><td><?php if ( $TTFallOtherList_row['fieldData']['FCSTTFh_FileNamePDF'] !== "") { ?><a class="linkred" href="PDFFiles/<?php echo $TTFallOtherList_row['fieldData']['FCSTTFh_FileNamePDF']; ?>">Download</a> <?php } ?></td></tr>
      <?php } ?>
  </table>

Is there a maximum number of items foreach iterates that might be limiting the number? I need the full list, and it will never be more than 1000 items, but I can’t get them with the code above.

Trying to use while instead of foreach may be better, but I am afraid of breaking the code. (Like I said, I don’t know PHP enough).

Thanks.

Tailwind with php files

I I have a project that consists of css, js, php files.

Css and js files are located in the /src folder and php files are simply in the root folder of the project.

I want to use tailwind and gulp with this project and get ready tailwind styles in the dist folder. But for some reason tailwind does not generate styles for php files.

So when I run – npm run dev I see styles for html,scss,js files but not for php files

tailwind.config.js

/** @type {import('tailwindcss').Config} */

export default {
  content: [
    './src/**/*.{html,scss,js}', 
    './*.{php}'
  ],
  theme: { ...

gulpfile.js

import { copy } from './gulp/tasks/copy.js';
import { copyRootFiles } from './gulp/tasks/copyRootFiles.js';
import { reset } from './gulp/tasks/reset.js';
import { html } from './gulp/tasks/html.js';
import { server } from './gulp/tasks/server.js';
import { scss } from './gulp/tasks/scss.js';
import { js } from './gulp/tasks/js.js';
import { images } from './gulp/tasks/images.js';
import { otfToTtf, ttfToWoff, fontStyle } from './gulp/tasks/fonts.js';
import { svgSprive } from './gulp/tasks/svgSprive.js';
import { zip } from './gulp/tasks/zip.js';
import { ftp } from './gulp/tasks/ftp.js';

global.app = {
  isBuild: process.argv.includes('--build'),
  isDev: !process.argv.includes('--build'),
  path: filePaths,
  gulp,
  plugins,
};

function watcher() {
  gulp.watch(filePaths.watch.static, copy);
  gulp.watch(filePaths.watch.html, html);
  gulp.watch(filePaths.watch.html, scss);
  gulp.watch(filePaths.watch.scss, scss);
  gulp.watch(filePaths.watch.js, js);
  gulp.watch(filePaths.watch.js, scss);
  gulp.watch(filePaths.watch.images, images);
  gulp.watch(filePaths.watch.php, scss);
}

I try this

tailwind.config.js

/** @type {import('tailwindcss').Config} */

export default {
  content: [
    './src/**/*.{html,scss,js}', 
    './*.{php}'
  ],
  theme: {

but it doesn’t worf for php files

Data provider laravel phpunit doesn’t work: Argument #2 ($code) must be of type int, string given

I’m trying to do testing on a Laravel application using Phpunit and data provider (I want to test for each field being wrong, so I thought it would be awesome to use a Data Provider)
However, I can’t manage to get it to work, it always gives me this error
Argument #2 ($code) must be of type int, string is given

Here is the code I used (redacted)

Test Function

   /**
     * @dataProvider invalidAddress
     */
   public function test_admin_cannot_create_client_with_invalid_address_data($invalidAddressData,$errors){
        $this->actingAs(AppModelsUser::factory()->create());

        Livewire::test(ClientResourcePagesCreateClient::class)
                ->fillForm($invalidAddressData)
                ->call('create')
                ->assertHasFormErrors($errors);
    }

The function that generates the data

    private function getFormDataForInvalidAddress(string $field, string | int $value, string $rule = ''): array
    {
        $record = $this->client->getAttributes();
        ......
        return [$record, $rules];
    }

Data Provider

    public function invalidAddress(): array
    {
        $this->setUp();
        return [
            'missing street' => self::getFormDataForInvalidAddress('street', '', 'required'),


            'missing postal code' => self::getFormDataForInvalidAddress('postalCode', '', 'required'),
            'too long postal code' => self::getFormDataForInvalidAddress('postalCode', '888888888'),


            'non-numeric postalCode' => self::getFormDataForInvalidAddress('postalCode', 'aaaaa'),
        ];
    }

Really, I can’t figure out what I’m doing wrong. It seems all okay to me, any advice on how I can debug this?

How to all email address showing from string [closed]

$text = “Whether you’re preparing for your [email protected] first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner.”;

$array_text = str_split($text);

if(in_array(“@”, $array_text)){

}
else{

}

// Show email Address color:

Laravel Deleting Event

i wanted to ask is it possible to update the book’s stock before deleting borrowDetail

the code provided below is where i’m trying using Observer but still doesn’t work

public function deleting(BorrowDetail $borrowDetail): void
    {
        $book = Book::where('id', $borrowDetail->book_id)->first();
        $book->stock += $borrowDetail->qty;
        $book->save();
    }

this is where i registered the Observer

<?php

namespace AppProviders;

use AppModelsBorrowDetail;
use AppObserversBorrowDetailObserver;
use IlluminateSupportServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     */
    public function register(): void
    {
        //
    }

    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        BorrowDetail::observe(BorrowDetailObserver::class);
    }
}

And I delete it on Laravel Filament’s Edit Page, there is a delete Button. It was on BorrowResource.

TCPDF Tamil Unicode Issue

My Code is

setFontSubsetting(true);

$fontname = TCPDF_FONTS::addTTFfont(‘../fonts/freeserif.ttf’, ‘TrueTypeUnicode’, ”, 96);
$pdf->setFont($font_family=’freeserif’,$font_variant=”,$font_size=10);

$pdf->AddPage();

$utf8text = ‘

தமிழ் தமிழ் குதிரை

‘;

$pdf->writeHTML($utf8text, true, 0, true, true);

$pdf->Output(‘example_008.pdf’, ‘I’);

?>

but tamil letter குதிரை not properly showing now.

enter image description here

TAMIL UNICODE CHARACTERS IN PDF CORRECTLY

Create a .gz file with relative path using PHP, and without commandLine?

I would like to gzip compress a file on my server using PHP, and without commandLine.

Have successfully written and tried a couple including this How do you create a .gz file using PHP?

But they all include the Full absolute paths, not the relative paths.

The function by both @Simon East AND @Gerben on this page How do you create a .gz file using PHP? all stores full absolute path to entire fileSystem e.g “/var/www/sites/example.com/path/to/my/file.gz” rather than just “my/file.gz”

You wouldn’t know till you attempt extracting it.

Does anyone have an example that would gzip compress file including just it’s relative path?

Have successfully written and tried a couple including this How do you create a .gz file using PHP?

But they all include the Full absolute paths, not the relative paths.

function gzCompressFile($source, $level = 9){ 
    $dest = $source . '.gz'; 
    $mode = 'wb' . $level; 
    $error = false; 
    if ($fp_out = gzopen($dest, $mode)) { 
        if ($fp_in = fopen($source,'rb')) { 
            while (!feof($fp_in)) 
                gzwrite($fp_out, fread($fp_in, 1024 * 512)); 
            fclose($fp_in); 
        } else {
            $error = true; 
        }
        gzclose($fp_out); 
    } else {
        $error = true; 
    }
    if ($error)
        return false; 
    else
        return $dest; 
}

optimizing select * on queries that is called multiple times

I have a table called order_list, in which it holds 700k entries.. continuously growing. In my show processlist in my sql i can see the following:

mysql> show processlist;
+-----+-------------+-----------+------+---------+------+-------------------+---------------------------------------------------------------------------------------------+
| Id  | User        | Host      | db   | Command | Time | State             | Info                                                                                        |
+-----+-------------+-----------+------+---------+------+-------------------+---------------------------------------------------------------------------------------------+
|   2 | alex | localhost | smm  | Query   |   13 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|   3 | alex | localhost | smm  | Query   |   13 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|   5 | alex | localhost | smm  | Query   |   13 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|   6 | alex | localhost | smm  | Query   |   13 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|   7 | alex | localhost | smm  | Query   |   13 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|   9 | alex | localhost | smm  | Query   |   13 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  10 | alex | localhost | smm  | Query   |   13 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  11 | alex | localhost | smm  | Query   |   13 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  12 | alex | localhost | smm  | Query   |   13 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  13 | alex | localhost | smm  | Query   |   13 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  14 | alex | localhost | smm  | Query   |   13 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  15 | alex | localhost | smm  | Query   |   13 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  17 | alex | localhost | smm  | Query   |   13 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  18 | alex | localhost | smm  | Query   |   13 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  19 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  20 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  21 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  22 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  23 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  24 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  26 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  27 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  29 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  30 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  31 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  32 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  33 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  35 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  36 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  38 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  39 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  41 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  42 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  43 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  45 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  46 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  47 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  48 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  49 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  50 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  51 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  52 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  53 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  54 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  55 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  56 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  57 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  58 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  59 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  60 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  61 | alex | localhost | smm  | Query   |   12 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  62 | alex | localhost | smm  | Query   |   11 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  64 | alex | localhost | smm  | Query   |   11 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  65 | alex | localhost | smm  | Query   |   11 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  67 | alex | localhost | smm  | Query   |   11 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  68 | alex | localhost | smm  | Query   |   11 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  69 | alex | localhost | smm  | Query   |   11 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  70 | alex | localhost | smm  | Query   |   11 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  72 | alex | localhost | smm  | Query   |   11 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  74 | alex | localhost | smm  | Query   |   11 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  75 | alex | localhost | smm  | Query   |   11 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  76 | alex | localhost | smm  | Query   |   11 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  78 | alex | localhost | smm  | Query   |   11 | Sending data      | SELECT *
FROM `order_list`                                                                  |
|  79 | alex | localhost | smm  | Query   |   11 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  80 | alex | localhost | smm  | Query   |   11 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  81 | alex | localhost | smm  | Query   |   11 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  82 | alex | localhost | smm  | Query   |   11 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  83 | alex | localhost | smm  | Query   |   11 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  84 | alex | localhost | smm  | Query   |   11 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  85 | alex | localhost | smm  | Query   |   11 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  86 | alex | localhost | smm  | Query   |   11 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  87 | alex | localhost | smm  | Query   |   11 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  88 | alex | localhost | smm  | Query   |   11 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  89 | alex | localhost | smm  | Query   |   11 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  90 | alex | localhost | smm  | Query   |   11 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  91 | alex | localhost | smm  | Query   |   11 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  94 | alex | localhost | smm  | Query   |   11 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  96 | alex | localhost | smm  | Query   |   11 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  97 | alex | localhost | smm  | Query   |   11 | Sending to client | SELECT *
FROM `order_list`                                                                  |
|  99 | alex | localhost | smm  | Query   |   11 | Sending to client | SELECT *
FROM `order_list`                                                                  |
| 100 | alex | localhost | smm  | Query   |   11 | Sending to client | SELECT *
FROM `order_list`                                                                  |
| 101 | alex | localhost | smm  | Query   |   11 | Sending to client | SELECT *
FROM `order_list`                                                                  |
| 102 | alex | localhost | smm  | Query   |   11 | Sending to client | SELECT *
FROM `order_list`                                                                  |
| 103 | alex | localhost | smm  | Query   |   10 | Sending to client | SELECT *
FROM `order_list`                                                                  |
| 105 | alex | localhost | smm  | Query   |   10 | Sending to client | SELECT *
FROM `order_list`                                                                  |
| 106 | alex | localhost | smm  | Query   |   10 | Sending to client | SELECT *
FROM `order_list`                                                                  |
| 107 | alex | localhost | smm  | Query   |   10 | Sending to client | SELECT *
FROM `order_list`                                                                  |
| 108 | alex | localhost | smm  | Query   |   10 | Sending to client | SELECT *
FROM `order_list`                                                                  |
| 109 | alex | localhost | smm  | Query   |   10 | Sending to client | SELECT *
FROM `order_list`                                                                  |
| 110 | alex | localhost | smm  | Query   |   10 | Sending to client | SELECT *
FROM `order_list`                                                                  |
| 111 | alex | localhost | smm  | Query   |   10 | Sending to client | SELECT *
FROM `order_list`                                                                  |
| 112 | alex | localhost | smm  | Query   |   10 | Sending to client | SELECT *
FROM `order_list`                                                                  |
| 113 | alex | localhost | smm  | Query   |   10 | Sending to client | SELECT *
FROM `order_list`                                                                  |
| 114 | alex | localhost | smm  | Query   |   10 | Sending to client | SELECT *
FROM `order_list`                                                                  |
| 115 | alex | localhost | smm  | Query   |   10 | Sending to client | SELECT *
FROM `order_list`                                                                  |
| 116 | alex | localhost | smm  | Query   |   10 | Sending to client | SELECT *
FROM `order_list`                                                                  |
| 117 | alex | localhost | smm  | Query   |   10 | Sending to client | SELECT *
FROM `order_list`                                                                  |
| 118 | alex | localhost | smm  | Query   |   10 | Sending to client | SELECT *
FROM `order_list`                                                                  |
| 120 | alex | localhost | smm  | Query   |   10 | Sending to client | SELECT *
FROM `order_list`                                                                  |
| 121 | alex | localhost | smm  | Query   |   10 | Sending to client | SELECT *
FROM `order_list`                                                                  |
| 122 | alex | localhost | smm  | Query   |   10 | Sending to client | SELECT *
FROM `order_list`                                                                  |
| 123 | alex | localhost | smm  | Query   |    9 | Sending to client | SELECT *
FROM `order_list`                                                                  |
| 124 | alex | localhost | smm  | Query   |    9 | Sending data      | SELECT `id`
FROM `order_list`
WHERE `user_id` = '32605'
AND DATE(created_at) = '2023-11-24' |
| 125 | alex | localhost | smm  | Query   |    9 | Sending to client | SELECT *
FROM `order_list`                                                                  |
| 126 | root        | localhost | smm  | Query   |    0 | starting          | show processlist                                                                            |
| 127 | alex | localhost | smm  | Query   |    9 | Sending to client | SELECT *
FROM `order_list`                                                                  |
| 128 | alex | localhost | smm  | Query   |    9 | Sending to client | SELECT *
FROM `order_list`                                                                  |
| 129 | alex | localhost | smm  | Query   |    8 | Sending to client | SELECT *
FROM `order_list`                                                                  |
| 130 | alex | localhost | smm  | Query   |    8 | Sending to client | SELECT *
FROM `order_list`                                                                  |
| 132 | alex | localhost | smm  | Query   |    6 | Sending to client | SELECT *
FROM `order_list`                                                                  |
| 133 | alex | localhost | smm  | Query   |    6 | Sending to client | SELECT *
FROM `order_list`                                                                  |
| 134 | alex | localhost | smm  | Query   |    5 | Sending to client | SELECT *
FROM `order_list`                                                                  |
| 135 | alex | localhost | smm  | Query   |    5 | Sending to client | SELECT *
FROM `order_list`                                                                  |
| 142 | alex | localhost | smm  | Query   |    3 | Sending to client | SELECT *
FROM `order_list`                                                                  |
| 143 | alex | localhost | smm  | Query   |    2 | Sending to client | SELECT *
FROM `order_list`                                                                  |
+-----+-------------+-----------+------+---------+------+-------------------+---------------------------------------------------------------------------------------------+

now I am not sure which part in my application or function is making these call.. im suspicious that i might got DDoS attack as my web usually doesn’t have these many traffic. I am kinda clueless on where to start in fixing this.. because of this my website can’t be opened as the query is taking 100% of the resources of the machine.. increasing RAM and CPU did not help at all.

any thoughts or idea on how to start and fix this ? i’ve added cloudfront to my website just recently, but that did not fix the issue. in the access log all i am seeing is just a bunch of access to my homepage.. in which the homepage did not have any code querying for SELECT * FROM order_list

Unable to Upload Files after Server Migration – Possible Permissions Issue

I’ve been encountering an issue for the last three days while working on a project that involves file and text uploads to my server. Every time a user uploads something, a new folder is created on the server in the format YearMonthDay_HourMinuteSecond.

Previously, on my old server running Ubuntu 22.04 with Apache, the code worked fine. However, after changing servers, I’m facing an issue where I can’t upload files, but the content gets uploaded. I suspect the problem might be related to folder and file permissions.

Here are the permissions for the directories and files:

Apache folder permission:
drwxr-xr-x 13 root root 4096 html/

English folder permission:
drwxr-xr-x 3 root root 4096 en/

Permissions for the upload page and upload script:
-rw-r–r– 1 root root 15498 upload.html
-rw-r–r– 1 root root 2935 upload.php

Upload directory permissions:
drwxrwxrwx 4 www-data www-data 4096 test_upload/

I’m using the latest Apache2 and PHP versions, and I’m running Ubuntu 22.04.

I believe the issue might be related to permissions on the server. Any help or suggestions on resolving this problem would be highly appreciated. Thank you in advance!

upload.php code :

<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $title = $_POST["title"];
    $story = $_POST["story"];
    $username = isset($_POST["username"]) ? $_POST["username"] : "Anonymous"; 

    // Get the current date and time in the desired format (YearMonthDay_HourMinuteSecond)
    $currentDateTime = date("Ymd_His");

    // Directory to store files and content
    $uploadDir = "/var/www/html/test_upload/" . $currentDateTime . "/";

    if (!file_exists($uploadDir)) {
        mkdir($uploadDir, 0777, true);
    }

    // Check if files were uploaded
    if (!empty($_FILES["file"]["name"][0])) {
        foreach ($_FILES["file"]["name"] as $key => $fileName) {
            $uploadFile = $uploadDir . basename($fileName);

            // Move uploaded file with proper file type validation
            $fileTmp = $_FILES["file"]["tmp_name"][$key];
            $fileType = mime_content_type($fileTmp);

            // Add more file type validations if needed
            if ($fileType === 'video/mp4' || $fileType === 'video/mpeg') {
                if (move_uploaded_file($fileTmp, $uploadFile)) {
                    // File uploaded successfully
                } else {
                    // File upload failed
                    echo "File upload failed. Debugging information:<br>";
                    echo "Upload file: $uploadFile<br>";
                    echo "Temporary file: $fileTmp<br>";
                    echo "File type: $fileType<br>";
                    echo "Check directory permissions and server configuration.";
                    exit();
                }
            } else {
                // Invalid file type
                echo "Invalid file type. Only MP4 and MPEG videos are allowed.";
                exit();
            }
        }
    }

    // Save the content and user information to a text file in the directory (without geolocation and user agent)
    $content = "Title: $titlenStory: $storynUsername: $username";
    file_put_contents($uploadDir . "content.txt", $content);

    // Redirect to success page
    header("Location: success.html");
    exit();
} else {
    // Redirect to error page
    header("Location: error.html");
    exit();
}
?>

any help with the problem pleas !

Python call from website is causing webpage to hang

I have spent a little time looking through the site, but ultimately wind up at the same place with code that stops functioning. I’m a coding novice and currently trying to learn HTML, PHP, python and SQL

I’m trying to trigger a python script from php code on a webserver. the python script and the webpage are located in the same folder on the server.

The website calls a script and is then supposed to open a new page to say the script ran.

The code I’m trying to call has a repeat function that runs every 10 seconds (this function is necessary) – this stops the webpage from loading.

This is the php. 

    if($datetime_diff < 2){
    // code as ran within datetime diff value so all good - don't show button
    echo "
    <p>SQL Time check shows python code is running</p>
    ";
    }else{
    // show link to run python code
    echo "
    <p><a href='python_call.php' class='btn btn-primary ml-3'>Run python code</a></p>
    ";
    }

this is the python call that is called in the href..

shell_exec('python pdl_test.py > error.txt 2>&1 &');
echo "
    <p><a href='admin_page.php' class='btn btn-primary ml-3'>Admin Page</a></p>
    ";

I was under the impression that the 2>&1 & should allow the php to continue without checking for a result.

the error.txt file displays complete

this is the script that the first python code is calling..

def repeat():
    print (datetime.now())
    try:
        subprocess.run(['python', 'sql_update.py'])
    except:
        print ('error')
    else:
        print ('called')
 
    print (datetime.now())
    print ("program complete")
 
    time.sleep(10)
    
while True:
    repeat()

and this is the SQL (this works OK)

cursorDestination.execute('''
            UPDATE eng_pdl_test
            SET scriptRan = getdate()
            WHERE id = 1
            ''')
cnxnDestination.commit()

 
I can see from the Task manager program that the command is being executed, and is retained.

Name     PID      Status     Command Line        
python.exe   12476   Running   python pdl_test.py  

If I close the first webpage and re-open it, the update shows as complete and, on page refresh the timer value increments every 10 seconds.

Also, if the pdl_test.py script is already running everything works correctly.

so ,in summary the code works correctly, it just doesn’t finish loading the page correctly.

Would someone please point me in a new/better/right direction please.

i’ve also tried Popen with no success.
subprocess.Popen(['python', 'sql_update.py'])

i’ve confirmed server calls are permitted using this code..
 

$output = null;
$return_var = null;
exec('echo "test"', $output, $return_var);
if ($return_var === 0) {
    echo 'command execution permitted.';
} else {
    echo 'command execution not permitted.';
}

if i call the sql_update.py script it works as expected. and I can return values if needed, but I can’t do this because I need the 10 second repeat.

exec('python sql_update.py', $output, $return_var);
echo "Output: " . implode("n", $output) . "n";
echo "Return value: " . $return_var . "n";