Jump to content

Enhance Guest Experience: Save User Data with Unique IDs


chat5html

71 views

 Share

This code allows you to save login data for guests.

Guests will receive a unique ID to use in their chat.

If you want user-related data such as name, age, and photo to always be present, use the following code.

Create a guest login page and use the code below:

 

<?php

function isValidInput($input) {
    return isset($input) && !empty($input);
}

function redirectToLoginPage() {
    header("Location: https://www.mysite.it/index.php?/videochat/page-login/");
    exit;
}

function redirectToVideoChatPage() {
    header("Location: https://www.mysite.it/index.php?/videochat/access-chat/");
    exit;
}

$member_id = \IPS\Member::loggedIn()->member_id;
if(empty($member_id)){ 
    // my id
    $_id_account = 1;

    // Recupera le variabili POST
    $name = $_POST['nickname'] ?? '';
    $anni_ = $_POST['age'] ?? '';
    $sesso = $_POST['gender'] ?? '';

    // Imposta i cookie
    if(empty($_COOKIE['number_cookie'])){
        setcookie('number_cookie', rand(100, 999), strtotime("+10 years"), "/");
    }

    if(isValidInput($name)){
        setcookie('name_mysite_ospite', $name, strtotime("+10 years"), "/");
    }

    if(isValidInput($sesso)){
        setcookie('gender_mysite_ospite', $sesso, strtotime("+10 years"), "/");
    }

    if(isValidInput($anni_)){
        setcookie('age_mysite_ospite', $anni_, strtotime("+10 years"), "/");
    }

    // Controlla se i cookie sono stati impostati
    if(empty($_COOKIE['name_mysite_ospite']) || empty($_COOKIE['gender_mysite_ospite']) || empty($_COOKIE['age_mysite_ospite']) || empty($_COOKIE['number_cookie']) ){
        redirectToLoginPage();
    }

    // Controlla se il nome è stato modificato
    if($_COOKIE['name_mysite_ospite'] !== $name && isValidInput($name)){
        redirectToVideoChatPage();
    }

    // Costruisci l'URL con i dati criptati
    $json = json_encode([
        'password' => 'my token',
        'id_account' => my id,
        'username' => $_COOKIE['name_mysite_ospite'].'_'.$_COOKIE['number_cookie'],
        'gender' => $_COOKIE['gender_mysite_ospite'],
        'role' => 'ospite',
        'birthyear' => $_COOKIE['age_mysite_ospite'],
        'profile_link' => "",
        'immage_user' => '',
        'room_id' => '198'
    ]);

    // Esegui il redirect alla pagina del videochat
    $encoded = file_get_contents("https://html5-videochat.com/applications/chat_webcam_personale/crypt.php/?code_crypt=".base64_encode($json));

    // Genera l'output HTML
    echo <<<HTML
    <!DOCTYPE html>
    <html>
    <head>
        <title>Video Chat</title>
        <style>
            /* Stili CSS */
        </style>
    </head>
    <body>
        <div id="container">
            <div id="header">
                <!-- Contenuto dell'intestazione, incluso l'iframe -->
                <a href="https://www.mysite.it/index.php?/login/" class="login-button">Login</a>
                <a href="https://www.mysite.it/index.php?/register/" class="register-button">Register</a>
            </div>
            <div id="content">
                <iframe id="iframeChat" width="100%" height="100%" src="https://www.html5-videochat.com/index.php?/chat/$encoded" allowfullscreen="" allow="geolocation; microphone; camera; allowfullscreen; autoplay;"></iframe>
            </div>
        </div>
    </body>
    </html>
    HTML;
}

 

 Share

0 Comments


Recommended Comments

There are no comments to display.

×
×
  • Create New...