Form validation not working correctly …

Hello
What is wrong in the form validation. It always give me -> not OK -> red color
I hope someone can help me with this.
Thanks in advance. Best regard.

<html>          
<head>
<style>
.error {
    font-family: Tahoma;
    font-size: 8pt;
    color: #FFFFFF;
    padding: 2px 172px 2px 172px;
    background-color: #FF0000;
    display:none;
    text-align: center;
}

.correct {
    font-family: Tahoma;
    font-size: 8pt;
    color: #FFFFFF;
    padding: 2px 203px 2px 203px;
    background-color: #0c9f5b;
    display:none;
    text-align: center;
}

.error_captcha {
    font-family: Tahoma;
    font-size: 8pt;
    color: #FFFFFF;
    padding: 2px 133px 2px 133px;
    background-color: #FF0000;
    display:none;
    text-align: center;
}

.correct_captcha {
    font-family: Tahoma;
    font-size: 8pt;
    color: #FFFFFF;
    padding: 2px 203px 2px 203px;
    background-color: #0c9f5b;
    display:none;
    text-align: center;
}

</style>
<!-- Captcha -->
    <script type="text/javascript">
        <!-- Begin
            var a = Math.ceil(Math.random() * 10 + 2);
            var b = Math.ceil(Math.random() * 10 + 2);       
            var c = a + b
            function DrawBotBoot()
            {
                document.write("<span id='captcha' style='font-size:12px;'>"+a + " + " + b +" = <span>");
                document.write("<input type='text' name='captcha' id='captcha' maxlength='2' size='2' />");
            }    
        // End -->
    </script>

<!-- Form validation -->
<script type="text/javascript">
function formulierValidation()
{
    var d = document.getElementById("captcha").value;

    //captcha
    if((d !== c) || (d = ""))
        {
            hideAllErrors();
            var obj = document.getElementById("captchaCorrect");
                obj.removeAttribute('style');
            document.getElementById("captchaError").style.display = "inline";
            document.getElementById("ErrorCaptcha").style.color = "red";
            document.getElementById('captcha').focus();
            return false;
        } else {
            hideAllErrors();
            var obj = document.getElementById("captchaError");
                obj.removeAttribute('style');
            document.getElementById("captchaCorrect").style.display = "inline";
            document.getElementById("ErrorCaptcha").style.color = "green";
        }       


    // Clear Errorsfields
    function hideAllErrors() 
    {
        document.getElementById("captchaError").style.display = "none"
    }
}
// -->
</script>

        </head>
        <body>


        <form name="formulier" method="post" action="<?=$self?>" onclick="formulierValidation();">

        <span id="ErrorCaptcha"><b>code</b><span>
        <script type="text/javascript">DrawBotBoot()</script> <span id="ErrorCaptcha"></span>
        <span class="error_captcha" id="captchaError">ccde invullen.</span><span class="correct_captcha" id="captchaCorrect">Ok.</span>
        <input type="button" value="submit" class="button" />
        </form>

PHP Flat file sorting on third column …

Hello helpers,

I'm having a problem with sorting (3rd column) a flat file.

flat file looks like this:
20210103|~|3 jan 2021|~|Harold|~|m|
20210121|~|21 jan 2021|~|Elly|~|f|
20210213|~|13 feb 2021|~|Silvy|~|f|
20210330|~|30 mrt 2021|~| George|~|m|

Now I want to save it in a new flat file sorted on the 3rd column
Result:
20210121|~|21 jan 2021|~|Elly|~|f|
20210330|~|30 mrt 2021|~|George|~|m|
20210103|~|3 jan 2021|~|Harold|~|m|
20210213|~|13 feb 2021|~|Silvy|~|f|

I already have a code for making new flat file but I'm stuck on sorting 3rd column, The sorting does not work.
Can somebody help me by adding the code for sorting correctly please?

Code I already have:

<?php
$data = trim(file_get_contents('../myfile.dat'));
$data = explode("\n", $data);
$array_order = array();
$fileLocation = getenv("DOCUMENT_ROOT") . "/mynewfile.txt";
$file = fopen($fileLocation, "w");
for ($i = 0; $i < count($data); $i++) {
($i > 0) ? $array_order[$i] = $data[$i] : fwrite($file, $data[0]);
}
sort($array_order);
$data = implode("\n", $array_order);
fwrite($file, $data);
fclose($file);
echo 'file created - location::' . $fileLocation;
?>

Thanks in advance
Kind regards.

PHP takes empty captcha session …

Is it possible in PHP?
I have a website with form + captcha on domain A -> there the captcha worked well.
It generates 1 session with the captcha code.
explanation -> https://postimg.cc/Wdzcw8vB
-> no problem so far

Now the server on which the domain A is hosted disabled sendmail - PHP mail() function so no PHP mail() function and no phpmailer with smtp on google works.
This way I can't send forms anymore.
Since it's impossible (for personal reason!) to move the website from domain A on server A to domain B on server B , I decided to use 2 domains on different servers.
I keep domain A on server A for the website and domain B on server B to send the forms -> works good except the captcha.
explanation -> https://postimg.cc/hhsRHvKb
My problem is when I call the form with captcha in iframe on domain B it generates 2 sessions in the /temp folder of server B: one with the captcha code and one empty! Now It always choose the empty session so the captcha is always wrong.

What I don't understand is ...
I open the domain A on server A with an iframe with contents which is on domain B on server B -> no session has been sent at all. Just opening a page from another server B in an iframe on server A.
Now from that page (normal page) which is on domain B on server B, I call a new page with form in the iframe with the captcha -> session_start(); -> so session is sent from domain B on server B
look again for explanation here -> https://postimg.cc/hhsRHvKb
So I call the session on domain B on server B -> why does it create 2 sessions instead of 1
What PHP code do I have to add so it takes the right session with the captcha code?
I hope someone can help me with my problem (if it's possible of course)
Thanks in advance
Best regards.