Jump to content
bDyds

[PHP]Generare numere diferite la fiecare vizita

Recommended Posts

Posted

Salut, ma tot screm de 2 ore la un script si nu reusesc sa ii dau de cap.

Enuntul problemei: in php trebuie sa fac un script care citeste numarul de linii dintr-un fisier text si la fiecare vizita genereaza alt numar mai mic sau egal cu numarul de linii din fisier pana termina toate numerele. Ce am facut eu:

$n = countlines(file);
$expire=time()+12*60*60*24*30;
$r = rand(1, $n);
if (!isset($_COOKIE["ad"])) {
setcookie("ad", $r, $expire);
echo "S-A SETAT COOKIEUL";
}
else {
$old = $_COOKIE["ad"];
$oldish = explode("+", $old);
$nel = count($oldish);
while(in_array($r, $oldish)==1) {
if($nel == $n) echo "OVER";
else $r = rand(1, $n);
}
$new = $old . ' ' .$r;
setcookie("ad", $new, $expire);
echo "$r";
}

O problema ar fi ca intre numerele din cookie este + in loc de spatiu, desi nu inteleg de ce. Astept sa ma lamureasca un PHPMaster si sa ma si indrume cum sa fac scriptul, pentru ca probabil nu l-am gandit bine.

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.   Paste as plain text instead

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