Phinx migartion Exception

Im using the package “robmorgan/phinx”: “^0.15”
I run to an issue with Phinx migration, when I run command phinx migrate with the config file, This error occurs.

 vendorbinphinx migrate -c "Device/conf.php"

This is detail error:

TypeError: PhinxDbAdapterPdoAdapter::createPdoConnection(): Argument #2 ($username) must be of type ?string, bool given, called in C:ApplicationswampwwwyodamigrationsrcvendorrobmorganphinxsrcPhinxDbAdapterMysqlAdapter.php on line 158 and defined in C:ApplicationswampwwwyodamigrationsrcvendorrobmorganphinxsrcPhinxDbAdapterPdoAdapter.php:85
Stack trace:
#0 C:ApplicationswampwwwyodamigrationsrcvendorrobmorganphinxsrcPhinxDbAdapterMysqlAdapter.php(158): PhinxDbAdapterPdoAdapter->createPdoConnection('mysql:host=;dbn...', false, false, Array)
#1 C:ApplicationswampwwwyodamigrationsrcvendorrobmorganphinxsrcPhinxDbAdapterPdoAdapter.php(169): PhinxDbAdapterMysqlAdapter->connect()
#2 C:ApplicationswampwwwyodamigrationsrcvendorrobmorganphinxsrcPhinxDbAdapterPdoAdapter.php(256): PhinxDbAdapterPdoAdapter->getConnection()
#3 C:ApplicationswampwwwyodamigrationsrcvendorrobmorganphinxsrcPhinxDbAdapterPdoAdapter.php(277): PhinxDbAdapterPdoAdapter->query('SELECT * FROM `...')
#4 C:ApplicationswampwwwyodamigrationsrcvendorrobmorganphinxsrcPhinxDbAdapterPdoAdapter.php(413): PhinxDbAdapterPdoAdapter->fetchAll('SELECT * FROM `...')
#5 C:ApplicationswampwwwyodamigrationsrcvendorrobmorganphinxsrcPhinxDbAdapterPdoAdapter.php(385): PhinxDbAdapterPdoAdapter->getVersionLog()
#6 C:ApplicationswampwwwyodamigrationsrcvendorrobmorganphinxsrcPhinxDbAdapterAdapterWrapper.php(206): PhinxDbAdapterPdoAdapter->getVersions()
#7 C:ApplicationswampwwwyodamigrationsrcvendorrobmorganphinxsrcPhinxMigrationManagerEnvironment.php(254): PhinxDbAdapterAdapterWrapper->getVersions()
#8 C:ApplicationswampwwwyodamigrationsrcvendorrobmorganphinxsrcPhinxMigrationManager.php(316): PhinxMigrationManagerEnvironment->getVersions()
#9 C:ApplicationswampwwwyodamigrationsrcvendorrobmorganphinxsrcPhinxConsoleCommandMigrate.php(124): PhinxMigrationManager->migrate('dev', NULL, false)
#10 C:ApplicationswampwwwyodamigrationsrcvendorsymfonyconsoleCommandCommand.php(326): PhinxConsoleCommandMigrate->execute(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#11 C:ApplicationswampwwwyodamigrationsrcvendorsymfonyconsoleApplication.php(1063): SymfonyComponentConsoleCommandCommand->run(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#12 C:ApplicationswampwwwyodamigrationsrcvendorsymfonyconsoleApplication.php(320): SymfonyComponentConsoleApplication->doRunCommand(Object(PhinxConsoleCommandMigrate), Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#13 C:ApplicationswampwwwyodamigrationsrcvendorrobmorganphinxsrcPhinxConsolePhinxApplication.php(69): SymfonyComponentConsoleApplication->doRun(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#14 C:ApplicationswampwwwyodamigrationsrcvendorsymfonyconsoleApplication.php(174): PhinxConsolePhinxApplication->doRun(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput)) #15 C:Applicationswampwwwyodamigrationsrcvendorrobmorganphinxbinphinx(28): SymfonyComponentConsoleApplication->run()
#16 C:Applicationswampwwwyodamigrationsrcvendorbinphinx(120): include('C:\Applications...')
#17 {main}

My conf file content :

$conf = [
    "paths" => [
        "migrations" => __DIR__,
    ],
    "environments" => [
        "default_migration_table" => "phinxlog",
        "default_environment" => "dev",
        "dev" => [
            "adapter" => "mysql",
            "host" => getenv('DB_HOST', '127.0.0.1'),
            "name" => getenv("DB_DATABASE_CATALOG_DEVICE"),
            "user" => getenv('DB_USERNAME', 'forge'),
            "pass" => getenv('DB_PASSWORD', ''),
            "charset" => "utf8",
            "collation" => "utf8_general_ci",
        ],
    ],
];

Validate RSA key against password without PHPSeclib

I try to validate if a passphrase works with a private key in PHP.

Right now the solution is simply to use phpseclib and do this:

$rsa = new phpseclibCryptRSA();
$rsa->setPassword($passphrase);
$res = $rsa->loadKey($privateKeyString);

and check if $res is false. This works fine but I want to get rid of phpseclib and use native PHP functionality. How can I achieve that? I tried openssl_pkey_get_private() which did not work.

I only expect RSA keys (like “—–BEGIN RSA PRIVATE KEY—–“)…

Managing a CalDAV link in a flat-CMS

Here’s the project: I want people to be able to manage events with a flat CMS (no db management, only txt files). The CMS is Kirby and it suits me very well because it can be upload to any web server without specific config (npm, SQL db…), works with PHP, HTML and CSS and runs on Apache (nginx is possible): I’m not a high-qualified dev.. The big advantage of this is to be able to upload the CMS on light and common server.

Since generating .ics files for each single events is “simple” (I found how .ics files have to be coded), how managing a link with CalDAV (or something else) is possible? I did a quick research and I found some cool stuff like Radicale or Baïkal but I don’t want another programm that needs to have its own url, own architecture… I want to understand the process behind it to integrate it to the CMS.

Why?

People who will use the CMS and events won’t go to a different page, learn how the programm works and publish the events. I want to keep it simple: you add events like you add a new page or update information… with the CMS.

The link will provide only events. No tasks management. It will be a read-only calendar link. Why not generating only .ics files with multiple events? Because I want the events to be updated automatically, not only once.

Thanks for your help!

Found some programs like Radicale or Baïkal but dosen’t suits me because you need an extra installation.

Where to store secrets (ie passwords, private key) on website [closed]

I plan to implement an encrypted messaging system on a website (I realize this isn’t the best place to do this). The website has php as a backend with a SQLite database.

This requires that messages are encrypted with a public key and decrypted with a private one. The public one (for each person) will be stored on the database (it will be sent to the client when they want to send a message). Messages on the server are stored and encrypted by this essential pair.

My question is, how should I store the private key? Each person will need one, and it needs to remain secret. Otherwise, other people could see their messages.

I think it is encrypted with the user’s password on the database. It is then sent to the client, who enters the password, and it is decrypted and stored as a javascript variable. It is then used to solve each message sent to the client.

Is this secure enough? Would it be better to store the private key differently on the client side, such as cookie/local storage, or not at all? Should more be done server-side?

Edit:
Alternativly I could do more server side. When messages are requested, the password will be sent from the client (manual input) to the server via POST. It will then be used to decrypt the private key that is stored in the database (encryted) and decrypt the messages. The messages will be then sent back to the client in plain text as part of a html page.

Should normal php variables ($varname) be used for this? Is it safe to store the password itself as a variable or session variable or should they be sent every time.

PHP Mysqli query only runs when I’m not redirecting the page afterwards

Im sitting on a basic login system and for me as a complete beginner I’m happy with it. Right now I try to set the user as online in the database. And this pretty much works. The problem is that when I redirect the user to the profile page the query doesn’t seem to work anymore. As soon as I comment the JavaScript redirection the data changes again. When I take the redirection back inside the data doesn’t change anymore. I’m wondering if I should put sth like a delay between the query and redirection but then how long should I do this to be sure that it worked? I don’t want a loop that runs the whole time and asks if the data changed. The redirection works, so the code runs through. Just the data doesn’t get updated.

require("mysql.php");
            $query = "SELECT * FROM userdata WHERE username = '".$username."' AND password = '".$password."'";
            $result = mysqli_query($mysqli, $query);
            if(mysqli_num_rows($result)>0) { //if > 0 that means that an account has been found
                $_SESSION['username'] = $username;
                $_SESSION['loggedin'] = 1;
                $query = "UPDATE userdata SET loggedin='Online' WHERE username='".$username."'";
                $result = mysqli_query($mysqli, $query);
                if($result) {
                    echo "<script type='text/JavaScript'>
                        var name = '$username';
                        window.location.assign('/profile.php?name='+name);
                    </script>"; //redirect to the profile page after login
                }
                else {
                    echo musqli_error($mysqli);   
                }
            }  

I tried several things to check if the code even runs completely, I replaced the redirection with a simple alert, this made the data to update but of course then I don’t get redirected anymore. But the alert was shown what means that it’s working. The redirection itself works as well. Just the combination of the data update and redirection seems wrong.

How do I connect a website as the administrator to an Android Studio application using Firebase database?

So I have this website for the admin and an app for the user, What I would like to do for example I would write an announcement from the admin then it would reflect to the application. For what I have read online they would just use the firebase directly to create, update, delete. datas for the app, is it not possible?

if you have any article and any videos on how to make it please do help me, as I am having a hard time searching for it at the web thanks!

also I am using android studio, kotlin for the application

php load image from url in the card [closed]

I have a card in php.
It should show the iamge from the link but it does not show.

<?php foreach($media['links'] as $link): ?>
    <div class="col-md-4">
        <div class="card mb-4">
            <img src="<?php $link['url']; ?>" class="card-img-top" style="height: 350px;">
            <div class="card-body">
                <a href="dl.php?url=<?php echo base64_encode($link['url']); ?>" class="btn btn-get" download="">
                    <i class="fa fa-download"></i> Download
                </a>
            </div>
        </div>
    </div>
    <?php endforeach; ?>

In above code, if I try to var_dump the $link['url'], I get

string(293) "https://scontent.cdninstagram.com/v/t51.2885-15/266857610_601178334547526_5472702649899260888_n.jpg?stp=dst-jpg_e35&_nc_ht=scontent.cdninstagram.com&_nc_cat=102&_nc_ohc=1W5jDUFHgdoAX-huO6a&edm=APs17CUBAAAA&ccb=7-5&oh=00_AfAmBev0MJZnoZXi5R_VPkPz31z-ZAZmHc2ec7SqlvPUJg&oe=65686AA8&_nc_sid=10d13b"

so if I take the link after the string from above and then paste it into the browser, I can see the image, but it is not showing in the card using the initial code.

Can I use array_splice to delete element multidimensional array without error in PHP?

I got this code:

function deleteClient(){
    global $database;
    $input = 2;
    if (array_key_exists($input, $database)){
        $database.array_splice($database, $input, 1);
        echo "Client with id $input deleted succesfully";
    } else {
        echo "Client with this id doesn't exist";
    }
}

Variable $database is my two-dimensional array. Although array_splice deletes array with given index, it shows an error “Warning: Array to string conversion”. Everything else works properly.

I tried doing it with unset:

function deleteClient(){
    global $database;
    $input = 2;
    if (array_key_exists($input, $database)){
        unset($database[$input]);
        echo "Client with id $input deleted succesfully";
    } else {
        echo "Client with this id doesn't exist";
    }
}

It doesn’t return an error, but makes gaps in array which breaks another function.

How to Determine Minimum and Maximum Degree Of Chart Javascript

I have an wheel of fortune from chart and javascript code. I copy [https://www.codewithrandom.com/2023/11/24/spin-wheel-app-using-javascript/](this site) and everything is working fine.

What I want to do is reduce or increase the prize, in that example the prize are 12 items, here is the code

/* --------------- Minimum And Maximum Angle For A value  --------------------- */
const spinValues = [
  { minDegree: 61, maxDegree: 90, value: 100 },
  { minDegree: 31, maxDegree: 60, value: 200 },
  { minDegree: 0, maxDegree: 30, value: 300 },
  { minDegree: 331, maxDegree: 360, value: 400 },
  { minDegree: 301, maxDegree: 330, value: 500 },
  { minDegree: 271, maxDegree: 300, value: 600 },
  { minDegree: 241, maxDegree: 270, value: 700 },
  { minDegree: 211, maxDegree: 240, value: 800 },
  { minDegree: 181, maxDegree: 210, value: 900 },
  { minDegree: 151, maxDegree: 180, value: 1000 },
  { minDegree: 121, maxDegree: 150, value: 1100 },
  { minDegree: 91, maxDegree: 120, value: 1200 },
];
/* --------------- Size Of Each Piece  --------------------- */
const size = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10];
/* --------------- Background Colors  --------------------- */
var spinColors = [
  "#E74C3C",
  "#7D3C98",
  "#2E86C1",
  "#138D75",
  "#F1C40F",
  "#D35400",
  "#138D75",
  "#F1C40F",
  "#b163da",
  "#E74C3C",
  "#7D3C98",
  "#138D75",
];

labels: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

I try to reduce the items become 10 items, with this code (I modified my self) and also find my own formula with minDegree and MaxDegree for spinValues

/* --------------- Minimum And Maximum Angle For A value  --------------------- */
const spinValues = [
  { minDegree: 73, maxDegree: 108, value: 100 },
  { minDegree: 37, maxDegree: 72, value: 200 },
  { minDegree: 0, maxDegree: 36, value: 300 },
  { minDegree: 325, maxDegree: 360, value: 400 },
  { minDegree: 289, maxDegree: 324, value: 500 },
  { minDegree: 253, maxDegree: 288, value: 600 },
  { minDegree: 217, maxDegree: 252, value: 700 },
  { minDegree: 181, maxDegree: 216, value: 800 },
  { minDegree: 145, maxDegree: 180, value: 900 },
  { minDegree: 109, maxDegree: 144, value: 1000 },
];
/* --------------- Size Of Each Piece  --------------------- */
const size = [12, 12, 12, 12, 12, 12, 12, 12, 12, 12];
/* --------------- Background Colors  --------------------- */
var spinColors = [
  "#E74C3C",
  "#7D3C98",
  "#2E86C1",
  "#138D75",
  "#F1C40F",
  "#D35400",
  "#138D75",
  "#F1C40F",
  "#b163da",
  "#E74C3C",
];

labels: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

But it goes wrong somehow, See the picture I attach
The arrow show to labels 6 but the prize value is 700
The arrow show to labels 2 but the prize value is 300

Its work when its in default 12 items, when arrow show to label 6, the prize value would be 600.

I think there’s some mistake in determine Minimum And Maximum Angle For A value in script.
The formula I use to get 10 Items
360/10
formula in excel

What I ask, how to determine the minimum and maximum angle (degree) for the items show?
I want to use foreach function in PHP to show the item with minimum and maximum angle (minDegree and MaxDegree for spinValues) so that I can increase or reduce the total of items easily.
thanks

php inserting billions by bypassing limit even while I use intval

I have a web game that players can train troops according to the gold they have , but someone is bypassing that and able to create billions of troops

I want to confirm if this function is vulnerable before I apply any fixes

please check code and tell me if there is any change he may bypass intval()

I read like people do input stuff like 100000e-100 or 9e18 and that would do the trick , I tried it did not work for me

I need help detecting how is he getting this amount of troops

function :

    public function handleWarrior()
    {
        $itemId = $this->buildings[$this->buildingIndex]['item_id'];
        $this->troopsUpgrade = array();
        $_arr = explode(',', $this->data['troops_training']);
        foreach ($_arr as $troopStr) {
            list($troopId, $researches_done, $defense_level, $attack_level) = explode(' ', $troopStr);
            if (($researches_done == 1 && 0 < $this->gameMetadata['troops'][$troopId]['gold_needed'])) {
                $this->troopsUpgrade[$troopId] = $troopId;
            }
        }
        $this->warriorMessage = '';
        if (((is_post('tf') && !$this->isGameTransientStopped()) && !$this->isGameOver())) {
            $cropConsume = 0;
            $totalGoldsNeeded = 0;
            $trop = array();
            foreach ($_POST['tf'] as $troopId => $num) {
                $num = intval($num);
                if (($num <= 0 || !isset($this->troopsUpgrade[$troopId]))) {
                    continue;
                }
                $troopMetadata = $this->gameMetadata['troops'][$troopId];
                $needres = $troopMetadata['training_resources'][1] + $troopMetadata['training_resources'][2] + $troopMetadata['training_resources'][3] + $troopMetadata['training_resources'][4];
                $totalGoldsNeeded += $num;
                $trop[$troopId] = floor(($troopMetadata['gold_needed'] / ($needres / 100)) * $num);
                $cropConsume += $troopMetadata['crop_consumption'] * $trop[$troopId];
                $totalGoldsNeeded = ceil($totalGoldsNeeded);
            }
            if ($totalGoldsNeeded <= 0) {
                return null;
            }
            $canProcess = ($totalGoldsNeeded <= $this->data['gold_num'] and $totalGoldsNeeded <= $this->data['gold_buy']);
            $this->warriorMessage = ($canProcess ? 1 : 2);
            if ($canProcess) {
                $troopsString = '';
                foreach ($this->troops as $tid => $num) {
                    if ($tid == 99) {
                        continue;
                    }
                    $neededNum = ((isset($this->troopsUpgrade[$tid]) && isset($trop[$tid])) ? intval($trop[$tid]) : 0);
                    if ($troopsString != '') {
                        $troopsString .= ',';
                    }
                    $troopsString .= $tid . ' ' . $neededNum;
                }

                $this->load_model('Plus', 'm');
                $this->m->DeletPlayerGold($this->player->playerId, $totalGoldsNeeded,16);


                $this->data['gold_num'] -= $totalGoldsNeeded;
                $procParams = $troopsString . '|0||||||1';
                $buildingMetadata = $this->gameMetadata['items'][$this->buildProperties['building']['item_id']];
                $bLevel = $this->buildings[$this->buildingIndex]['level'];
                $needed_time = $buildingMetadata['levels'][$bLevel - 1]['value'] * 3600;

                $this->load_library('QueueTask', 'newTask', array(
                    'taskType' => QS_WAR_REINFORCE,
                    'playerId' => 0,
                    'executionTime' => $needed_time
                ));
                $this->newTask->villageId = 0;
                $this->newTask->toPlayerId = $this->player->playerId;
                $this->newTask->toVillageId = $this->data['selected_village_id'];
                $this->newTask->procParams = $procParams;
                $this->newTask->tag = array(
                    'troops' => NULL,
                    'hasHero' => FALSE,
                    'resources' => NULL,
                    'troopsCropConsume' => $cropConsume
                );
                $this->queueModel->addTask($this->newTask);
            }
        }
    }

What technology should be used to develop scalable web applications? [closed]

I have a functional prototype of a web application, but this is only a proof of concept (MVP) with a potential to grow.

I’d like to get your opinion about what technology I should use to develop a fully functional and rock-solid product.

Front-end: access via web browser (mostly on smartphones or tablets, I don’t consider smartwatches at all). A city map with crucial locations to select and get info (plus geolocation). Users (/guests) can register themself to create individual profiles with possibility to edit them later.

Backend: DB stores locations (coords, types, notes) and users data (login, pass, preferences, etc.) and custom attachments (images, posted by users). Server can send emails (or SMS – using an external API and sms gate) to verify users or deliver different notifications.

BTW – I’m still thinking about push notifications, but they aren’t perfect from a webapp (yet?), so this can stay at the bottom of the product backlog 😉

Scalability: it will start with a couple of hundred users, but can grow to 1k-5k in a few months up to 50k-200k later and even more after several years.

I built the MVP using my (old school?) knowledge gained 15 years ago (+some recent R&D) and it works but it is not perfect and doesn’t scale as I wish.
At the moment it is based on HTML + JavaScript (front-end), node.js (uploading images), AppScript (backend & database), plus some PHP (to control fronted access).

I assume this can be improved (a lot) and probably completely rewritten – even from the scratch, using the current design and user experience.

Alright, any thoughts / ideas on what technology should be used here?

Copying html-tags from one table to another (yii2, mysql)

I need to copy description of the product from one table to another, everything works fine until the <img src="url" width="50%" height="50%" /> tag appears in the description. I have a script that copying descriptions of product one by one, with this script in cycle:

$rowParse = Parsing::find()->where(['art_post' => $value])->one();
$desc = $rowParse->description;
Yii::$app->db->createCommand("UPDATE `products` SET `description`=:desc WHERE `id_post`=:id && `art_post`=:art")
->bindValues([':desc'=>$desc, ':id'=>$id_post, ':art'=>$art_post])->execute();

If I do copying description of single product it works as needed – tag inserts with his attributes, but if i do, for example, 100 products in cycle, attributes width and height just disappears and it inserts just like <img src="url" />

Insertion of all other html-tags like span, strong, td, tr, p works normal.

I’m new to programming world, so I need help of big guys 😀
Thank you in advance