Rodre Posted December 29, 2008 Share Posted December 29, 2008 Hi everyone! I´m new to this forum, and arrived here after hours of dealing with a problem. I so much hope u can help me. Here is the issue: I´m building a PHP photo manager. I have several categories of pics, and I want the user to be able to change the position of the pics on a gallery. I have one folder for each category containing the pics of that categoy. I´ve made a PHP that generates dinamically a table with all the pics in a certain directory. Each pic in the gallery have an arrow that moves the pic for the right for example. In an onclick event I call a php page that renames the pics acroding to the move and calls the gallery back. The gallery generates again, with the new names and pics and it works fine the the first time I click, may be the second or even the third but then it stop changing pics. But i´ve noticed that the problem is the browser bringing pics from cache, cause if I erase the cache and hit F5 I get the correct view. The question is, is there any effective way of avoiding cache ? I´ve tried some META tags, or headers. I´ve found everyone saying but it doesn´t work, or I´m not aplying it correctly. I´m new to programming its very probable i´m messing with something. But whatever it is.. I dont know.. Anyone can realize what should be done ? I´l be grateful to whoever helps me well ..here is the code The gallery: <? session_start(); if($_SESSION['validate']!= 1){ Header("location: login.php"); } if ($_SESSION['reload'] == true){ $_SESSION['reload'] = false; $test = "caca"; echo "<META HTTP-EQUIV='refresh' CONTENT='5'; URL='mportraits.php'>"; } echo $test; ?> <html> <head> <title>Administrar Fotos</title> <link rel="stylesheet" type="text/css" href="manage.css"> <script type="text/javascript"> var numero = 0; function adelante(numero){ document.location='adelante.php?num='+numero; } </script> </head> <body> <div class="divcontenedor"> <div class="divlinks"> <table class="tablalinks"> <tr> <td><a href="mcommercial.php">Commercial</a></td> <td class="separadorlinks"> </td> <td><a href="mlandscapes.php">Landscapes</a></td> <td class="separadorlinks"> </td> <td class="tdactivo">Portraits</td> <td class="separadorlinks"> </td> <td><a href="manalogic.php">Analogic</a></td> <td class="separadorlinks"> </td> <td><a href="mmore.php">More</a></td> </tr> </table> </div> <div class="divfotos"> <table class="tablafotos"> <? $dir = "fotos/tportraits"; $cant=0; if (is_dir($dir)) { if ($gd = opendir($dir)) { while (($archivo = readdir($gd)) !== false) { $cant++; } closedir($gd); } } $cant = $cant -2; $fotonum = 100; $lim = $cant/7; $lim2 = 100+$cant; for($i=0;$i<$lim;$i++){ echo "<tr>"; for($j=0;$j<6;$j++){ if($fotonum<$lim2){ echo "<td class='tdfotos'><img src='fotos/tportraits/t".$fotonum.".jpg'><br>"; echo $fotonum; echo "<span class='spanmover' onclick='adelante(".$fotonum.")'> ></span>"; echo "</td>"; $fotonum++; }else{ break; } } echo "</tr>"; } ?> </table> </div> </div> </body> </html> The renaming page: <? session_start(); $_SESSION['reload'] = true; $num = $_GET['num']; $ad = $_GET['num'] +1; rename("fotos/tportraits/t".$num.".jpg","fotos/tportraits/trans.jpg"); rename("fotos/tportraits/t".$ad.".jpg","fotos/tportraits/t".$num.".jpg"); rename("fotos/tportraits/trans.jpg","fotos/tportraits/t".$ad.".jpg"); header("location: mportraits.php"); ?> Only left functionality is made casue I´m stuck here... Thanks. Rodre Quote Link to comment https://forums.phpfreaks.com/topic/138700-can-i-avoid-cache-my-php-app-fails-for-that/ Share on other sites More sharing options...
opalelement Posted December 29, 2008 Share Posted December 29, 2008 Try puttin this at the top of all pages: <? Header('Cache-Control: no-cache'); Header('Pragma: no-cache'); ?> http://lab.artlung.com/anti-cache/ Quote Link to comment https://forums.phpfreaks.com/topic/138700-can-i-avoid-cache-my-php-app-fails-for-that/#findComment-725169 Share on other sites More sharing options...
Rodre Posted December 29, 2008 Author Share Posted December 29, 2008 Tried but it doesn´t work. I wrote it on every pages, deleted all data from browser options. And it bheaves the same way. Works one or two times, then stops. If i delete cache from browser and hit refresh, I get the correct. This is making me sad... thanks for the interest. can u think of anything else ? Quote Link to comment https://forums.phpfreaks.com/topic/138700-can-i-avoid-cache-my-php-app-fails-for-that/#findComment-725171 Share on other sites More sharing options...
Rodre Posted December 29, 2008 Author Share Posted December 29, 2008 Any other suggestion ? Thanks Rodre Quote Link to comment https://forums.phpfreaks.com/topic/138700-can-i-avoid-cache-my-php-app-fails-for-that/#findComment-725450 Share on other sites More sharing options...
Maq Posted December 29, 2008 Share Posted December 29, 2008 Found this code in Google, it may be of help: if (!defined("CACHE")) define("CACHE", FALSE); if (!defined("GLOBAL_CACHE")) define("GLOBAL_CACHE", TRUE); if (!defined("TTL")) define("TTL", 15); if (!defined("PAGE_CACHE")) define("PAGE_CACHE", TRUE); Quote Link to comment https://forums.phpfreaks.com/topic/138700-can-i-avoid-cache-my-php-app-fails-for-that/#findComment-725479 Share on other sites More sharing options...
Rodre Posted December 29, 2008 Author Share Posted December 29, 2008 It doens´t work. Thanks for the interest anyway. Whats the problem here? cause the aplication works, the names are changed. OR how should I do to get this same ffect by something that actually works ? Cause I´m starting to think that this way is not going to be possible at all. Rodre Quote Link to comment https://forums.phpfreaks.com/topic/138700-can-i-avoid-cache-my-php-app-fails-for-that/#findComment-725504 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.