[PHP]Save Data without submitting again after Page reload

senheiser

Member
May 4, 2016
41
6
58
Hey,
is it possible to safe the data if you reload the page without creating a new output (teamspeak server creator - after reloading it creating a new server on a different port). ill want to change the data so if you reload the page you'll get the old data.

PHP Code:
Code:
<?php
    date_default_timezone_set('Europe/Berlin'); //Change Here!
    require_once("libraries/TeamSpeak3/TeamSpeak3.php");
    include 'data/config.php';


    $connect = "serverquery://".$USER_QUERY.":".$PASS_QUERY."@".$HOST_QUERY.":".$PORT_QUERY."";
    $ts3 = TeamSpeak3::factory($connect);

    if (isset($_POST["create"])) {

        $servername = $_POST['servername'];
        $slots = $_POST['slots'];
        $unixTime = time();
        $realTime = date('[Y-m-d]-[H:i]',$unixTime);

        if(!empty($_POST['port'])) {

            $port = $_POST['port'];
            try
            {
                $new_ts3 = $ts3->serverCreate(array(
                "virtualserver_name" => $servername,
                "virtualserver_maxclients" => $slots,
                "virtualserver_port" => $port,
                "virtualserver_name_phonetic" => $realTime,
                ));

                $token = $new_ts3['token'];

            }
            catch(Exception $e)
            {
                echo "Error (ID " . $e->getCode() . ") <b>" . $e->getMessage() . "</b>";
            }
            } else{

            try
            {
                $new_ts3 = $ts3->serverCreate(array(
                "virtualserver_name" => $servername,
                "virtualserver_maxclients" => $slots,
                "virtualserver_name_phonetic" => $realTime,
                ));

                $token = $new_ts3['token'];
                $portran = $new_ts3['virtualserver_port'];

            }
            catch(Exception $e)
            {
                echo "Error (ID " . $e->getCode() . ") <b>" . $e->getMessage() . "</b>";
            }

        }


    }
?>
I also ask me how to create a captcha into these script :)
have a great day!
 

maribro124

Restricted
Mar 6, 2016
38
7
43
Here comes my brother :) I added Captcha :)

Code:
<?php
    date_default_timezone_set('Europe/Istanbul'); //Change Here!
    require_once("libraries/TeamSpeak3/TeamSpeak3.php");
    include 'data/config.php';


    $connect = "serverquery://".$USER_QUERY.":".$PASS_QUERY."@".$HOST_QUERY.":".$PORT_QUERY."";
    $ts3 = TeamSpeak3::factory($connect);

    if (isset($_POST["create"])) {

    if (isset($_POST['g-recaptcha-response'])) {
    $captcha = $_POST['g-recaptcha-response'];
}
if (!$captcha) {
    echo '<center><h2>Please verify that you are not a robot..</h2>';
    exit;
}

        $servername = $_POST['servername'];
        $slots = $_POST['slots'];
        $unixTime = time();
        $realTime = date('[Y-m-d]-[H:i]',$unixTime);

        if(!empty($_POST['port'])) {

            $port = $_POST['port'];
            try
            {
                $new_ts3 = $ts3->serverCreate(array(
                "virtualserver_name" => $servername,
                "virtualserver_maxclients" => $slots,
                "virtualserver_port" => $port,
                "virtualserver_name_phonetic" => $realTime,
                ));

                $token = $new_ts3['token'];

            }
            catch(Exception $e)
            {
                echo "Error (ID " . $e->getCode() . ") <b>" . $e->getMessage() . "</b>";
            }
            } else{

            try
            {
                $new_ts3 = $ts3->serverCreate(array(
                "virtualserver_name" => $servername,
                "virtualserver_maxclients" => $slots,
                "virtualserver_name_phonetic" => $realTime,
                ));

                $token = $new_ts3['token'];
                $portran = $new_ts3['virtualserver_port'];

            }
            catch(Exception $e)
            {
                echo "Error (ID " . $e->getCode() . ") <b>" . $e->getMessage() . "</b>";
            }

        }


    }
?>
<script src='https://www.google.com/recaptcha/api.js'></script>
<?php  require_once('recaptchalib.php'); ?>

<div class="g-recaptcha" data-sitekey="SİTE KEY"></div>

Recaptcha Lib
https://www.solidfiles.com/v/Ww53R8xvPVLVB
Virus Total
https://www.virustotal.com/tr/url/a...336f3f9488c33a2ea0d9d1f4/analysis/1492125563/
 
Last edited:

senheiser

Member
May 4, 2016
41
6
58
Thank you bro, it worked! But i have a couple of questions. First of all how can I set up the script that a user cant reload the page without passing the captchar again? or how can i create a session or smth like that to safe the data from the form (now its shit because it creates a new teamspeak if i reload the page)
Pic:
fWYh6nM.png
 

maribro124

Restricted
Mar 6, 2016
38
7
43
You're welcome brother, :)
You can do it to get rid of the complex problem, for example my brother echo to header location .

Code:
header('Location: http://localhost/');
 
Last edited:
Top