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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.