Jump to content

setcookie


bob2006

Recommended Posts

i have never been able to get this to work but i am at it agian

in this code the php is not making the cookie can any one tell me why

 

 

 

<?php
function getRandomString($length = 5) {
    $validCharacters = "abcdefghijklmnopqrstuxyvwzABCDEFGHIJKLMNOPQRSTUXYVWZ+-*#&@!?1234567890";
    $validCharNumber = strlen($validCharacters);

    $result = "";

    for ($i = 0; $i < $length; $i++) {
        $index = mt_rand(0, $validCharNumber - 1);
        $result .= $validCharacters[$index];
    }

    return $result;
}
setcookie("code", "getRandomString()", 3600000);
echo getRandomString();
?>

Link to comment
https://forums.phpfreaks.com/topic/218641-setcookie/
Share on other sites

i know this has no relation to this post but how can i do this

function getRandomString($length = 75) {
    $validCharacters = "abcdefghijklmnopqrstuxyvwzABCDEFGHIJKLMNOPQRSTUXYVWZ+-*#&@!?1234567890";
    $validCharNumber = strlen($validCharacters);

    $result = "";

    for ($i = 0; $i < $length; $i++) {
        $index = mt_rand(0, $validCharNumber - 1);
        $result .= $validCharacters[$index];
    }

    return $result;
}
$string= 'getRandomString';
$expire=time()+60*60*24;
setcookie("code", getRandomString(), $expire);
mysql_query("UPDATE admin SET cookie_code='$string' WHERE login='$username'")or die(mysql_error());

 

Link to comment
https://forums.phpfreaks.com/topic/218641-setcookie/#findComment-1134134
Share on other sites

I am trying to update a variable in the databases called cookie_code with the function getRandomString

 

mysql_query("UPDATE admin SET cookie_code='21121' WHERE login='$username'")or die(mysql_error());

but all it is putting in the databases is getRandomString() And not the string i know it is doing this because the Function is not a virable so i try make it a Variable

$string= 'getRandomString';

and that did not help at all

Link to comment
https://forums.phpfreaks.com/topic/218641-setcookie/#findComment-1134138
Share on other sites

Completed Code

function getRandomString($length = 75) {
    $validCharacters = "abcdefghijklmnopqrstuxyvwzABCDEFGHIJKLMNOPQRSTUXYVWZ+-*#&@!?1234567890";
    $validCharNumber = strlen($validCharacters);

    $result = "";

    for ($i = 0; $i < $length; $i++) {
        $index = mt_rand(0, $validCharNumber - 1);
        $result .= $validCharacters[$index];
    }

    return $result;
}
$string= getRandomString();
$expire=time()+60*60*24;
setcookie("code", getRandomString(), $expire);
mysql_query("UPDATE admin SET cookie_code='$string' WHERE login='$username'")or die(mysql_error());

Link to comment
https://forums.phpfreaks.com/topic/218641-setcookie/#findComment-1134148
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.