php:获取cookie值并加1

时间:2013-09-07 19:57:01

标签: php cookies

<?php
 $cwd = getcwd();
 $dir = 'onlytest';
 // get file names from logos directory
 $files = scandir($dir);
 // count total files in directory
 $totalFiles = count($files) - 1;
 // loop through file names and output the images
 $desc = $files;
 echo 'Hello '.($_COOKIE['number']!='' ? $_COOKIE['number'] : '2'); // number of cookie!
 for ($i = (10 * $_COOKIE['number']) - 18; $i <= 10 * $_COOKIE['number']; $i++) 
 {
    $text = substr($desc[$i],0,20).'...';
    $filepath = $dir . "/" . $files[$i];
    echo '<img src="' . $filepath . '" target="_blank" width="25%" height="33%"           />';    
    echo "<a href='$filepath' target='_blank'>$text</a>";
 }
 echo "</br>";
?>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
  function doSomething() 
  {
     $.get("opentext.php");
     return false;
  }
</script>

<a href="#" onclick="doSomething();">'next 20 pictures'</a>

我的另一个文件opentext.php是这样的!

<?php
$number = ($_COOKIE['number'] + 1);
setcookie('number',$number,time() + (86400 * 1)); // 86400 = 1 day cookie
?>

我正在尝试获取cookie的值并添加+ 1,因为你可以看到我想在文件夹中拍摄20张第一张照片然后我想在点击下面的链接时使用javascript onclick函数更改cookie,它将我重定向到php文件,该文件为cookie添加+ 1并提供接下来的20张图片,我已经这样做了几个小时,我似乎无法让自己找到解决方案。

0 个答案:

没有答案