[ Поиск ] - [ Пользователи ] - [ Календарь ]
Полная Версия: вторичное посещение веб страницы
php beginer
Здравствуйте. Мне надо знать первый раз пользователь зашёл на страницу или нет . Делаю так:

if ($secondRoll == TRUE)
{
print "<h2>Second roll</h2>\n";
$secondRoll = FALSE;
evaluate();
}
else
{
print "<h2>First roll</h2>\n";
$secondRoll = TRUE;
}

//Но при обновлении F5 secondRoll всегда TRUE.
//Или ещё например:


$i=$i+1;
print "$i";

//Всегда выдаёт 1.

Почему? Может что то настроить надо в интерпретпторе.



Спустя 18 минут, 51 секунда (9.11.2009 - 22:01) Grazor написал(а):
php beginer
biggrin.gif настраивать ничего не надо) всё отлично работает)
просто сценарий каждый раз выполняется снова, то есть изначально значение всех переменных 0 (или FALSE)

Спустя 7 минут, 11 секунд (9.11.2009 - 22:09) Guest написал(а):
А как же отследить вторичные обновления

Спустя 2 минуты, 34 секунды (9.11.2009 - 22:11) Guest написал(а):
я сделал конечно через чтение/запись файлов, но ведь можно как то проще?

Спустя 5 минут, 50 секунд (9.11.2009 - 22:17) Guest написал(а):
а вот он исходный пример pokerDice из книги Энди Хариса:

<html>
<
head>
<
title>poker dice</title>
<
style type = "text/css">
body {
background: green;
color: tan;
}

</style>
</
head>

<
body>
<
center>
<
h1>Poker Dice</h1>

<
form>

<?
//check to see if this is first time here
if (empty($cash)){
$cash = 100;
} // end if

rollDice();

if ($secondRoll == TRUE){
print "<h2>Second roll</h2>\n";
$secondRoll = FALSE;
evaluate();
} else {
print "<h2>First roll</h2>\n";
$secondRoll = TRUE;
} // end if

printStuff();


function rollDice(){
global $die, $secondRoll, $keepIt;

print "<table border = 1><td><tr>";

for ($i = 0; $i < 5; $i++){
if ($keepIt[$i] == ""){
$die[$i] = rand(1, 6);
} else {
$die[$i] = $keepIt[$i];
} // end if
$theFile = "die" . $die[$i] . ".jpg";

//print out dice images
print <<<HERE
<td>
<img src = "
$theFile"
height = 50
width = 50><br>


HERE;
//print out a checkbox on first roll only
if ($secondRoll == FALSE){
print <<<HERE
<input type = "checkbox"
name = "keepIt[
$i]"
value =
$die[$i]>
</td>


HERE;

} // end if
} // end for loop

//print out submit button and end of table

print <<<HERE
</tr></td>
<tr>
<td colspan = "5">
<center>
<input type = "submit"
value = "roll again">
</center>
</td>
</tr>
</table>


HERE;

} // end rollDice

function evaluate(){
global $die, $cash;
//set up payoff
$payoff = 0;

//subtract some money for this roll
$cash -= 2;

//count the dice
for ($theVal = 1; $theVal <= 6; $theVal++){
for ($dieNum = 0; $dieNum < 5; $dieNum++){
if ($die[$dieNum] == $theVal){
$numVals[$theVal]++;
} // end if
} // end dieNum for loop
} // end theVal for loop

//print out results
// for ($i = 1; $i <= 6; $i++){
// print "$i: $numVals[$i]<br>\n";
// } // end for loop

//count how many pairs, threes, fours, fives

$numPairs = 0;
$numThrees = 0;
$numFours = 0;
$numFives = 0;

for ($i = 1; $i <= 6; $i++){
switch ($numVals[$i]){
case 2:
$numPairs++;
break;
case 3:
$numThrees++;
break;
case 4:
$numFours++;
break;
case 5:
$numFives++;
break;
} // end switch
} // end for loop

//check for two pairs

if ($numPairs == 2){
print "You have two pairs!<br>\n";
$payoff = 1;
} // end if

//check for three of a kind and full house

if ($numThrees == 1){
if ($numPairs == 1){
//three of a kind and a pair is a full house
print "You have a full house!<br>\n";
$payoff = 5;
} else {
print "You have three of a kind!<br>\n";
$payoff = 2;
} // end 'pair' if
} // end 'three' if

//check for four of a kind

if ($numFours == 1){
print "You have four of a kind!<br>\n";
$payoff = 5;
} // end if

//check for five of a kind

if ($numFives == 1){
print "You got five of a kind!<br>\n";
$payoff = 10;
} // end if

//check for straights

if (($numVals[1] == 1)
&& (
$numVals[2] == 1)
&& (
$numVals[3] == 1)
&& (
$numVals[4] == 1)
&& (
$numVals[5] == 1)){
print "You have a straight!<br>\n";
$payoff = 10;
} // end if

if (($numVals[2] == 1)
&& (
$numVals[3] == 1)
&& (
$numVals[4] == 1)
&& (
$numVals[5] == 1)
&& (
$numVals[6] == 1)){
print "You have a straight!<br>\n";
$payoff = 10;

} // end if
print "You bet 2<br>\n";
print "Payoff is $payoff<br>\n";
$cash += $payoff;

} // end evaluate

function printStuff(){
global $cash, $secondRoll;

print "Cash: $cash\n";

//store variables in hidden fields
print <<<HERE
<input type = "hidden"
name = "secondRoll"
value = "
$secondRoll">

<input type = "hidden"
name = "cash"
value = "
$cash">

HERE;
} // end printStuff

?>

</form>
</
center>
</
html>

Так вот этот $secondRoll он всегда FALSE, а не должен?

Спустя 5 минут, 11 секунд (9.11.2009 - 22:22) Grazor написал(а):

Спустя 3 дня, 15 часов, 41 минута, 47 секунд (13.11.2009 - 14:04) Guest написал(а):
спасибо
Быстрый ответ:

 Графические смайлики |  Показывать подпись
Здесь расположена полная версия этой страницы.
Invision Power Board © 2001-2024 Invision Power Services, Inc.