Help with script - Redirect Timeout

Hey guys, I am trying to create a redirect timeout using values from DB.

The javascript is something I have used before, think I actualy got it from here somewhere, now I am trying to replace the domain name and timeout values with those obtained from the database. This is what I have so far, the two database variables are in place and have tried a few options here, including:
<?php echo json_encode("$domain"); ?> and <?=$domain?> Both of which display the $domain/$timeout variables instead of the actual domain name or timeout value retrieved from DB. Hoping somebody can help with this as my javascript sucks :slight_smile: Thanks in advance!

Script:

// Check for record
$check_sql = “SELECT sett_domain, sett_timeout”
. " FROM plat_settings"
. " WHERE sett_ID = ‘1’";
sc_lookup(rs, $check_sql);

if (isset({rs[0][0]})) // Row found
{
$domain = {rs[0][0]};
$timeout= {rs[0][1]};
}
else // No row found
{
$domain = $_SERVER[‘SERVER_NAME’];
$timeout = ‘1800000’; //Default 30min
}

[idle]= '&lt;script type="text/javascript"&gt;

var inactivityTime = function () {
    var t;
    window.onload = resetTimer;
    document.onmousemove = resetTimer;
    document.onkeypress = resetTimer;


    function logout() {
        alert("Your session has ended, please login again.")
        location.href = "$domain"; // EDIT THIS LINE
    }

    function resetTimer() {
        clearTimeout(t);
        t = setTimeout(logout, $timeout) // EDIT THIS LINE
        // 1000 = 1 second
       // 60000= 1 minute
       // 3600000= 1 hour
    }
};

inactivityTime();

&lt;/script&gt;';

Hallo Jamie, try this to get the variables into JS
var x = ‘<?php echo $domain; ?>’;
then your location should become
location.href = “x”;
this way it works for me !

Hey Gerd, thx but how ever I add it I get errors…

placing it after the [idle]= '<script type=“text/javascript”> I get this:
Parse error: syntax error, unexpected ‘?’ in C:\Program Files (x86)\NetMake\v81\wwwroot\scriptcase\app\Security_Platform\menu\index.php on line 736

have tried some variations of with other errors…

Should be faily easy


// Check for record
$check_sql = "SELECT sett_domain, sett_timeout"
. " FROM plat_settings"
. " WHERE sett_ID = '1'";
sc_lookup(rs, $check_sql);

if (isset({rs[0][0]})) // Row found
{
$domain = {rs[0][0]};
$timeout= {rs[0][1]};
}
else // No row found
{
$domain = $_SERVER['SERVER_NAME'];
$timeout = '1800000'; //Default 30min
}

[idle]= '

<script type="text/javascript">

var inactivityTime = function () {
var t;
window.onload = resetTimer;
document.onmousemove = resetTimer;
document.onkeypress = resetTimer;


function logout() {
alert("Your session has ended, please login again.")
location.href = "' . $domain . '"; // EDIT THIS LINE
}

function resetTimer() {
clearTimeout(t);
t = setTimeout(logout,' .  $timeout . ') // EDIT THIS LINE
// 1000 = 1 second
// 60000= 1 minute
// 3600000= 1 hour
}
};

inactivityTime();

</script>';

lol simple when you know how, actualy didnt know if I could do that and of course not something I tried, thanks very much working so nicely now :slight_smile: