-1

If a user enters the website a interval (js) is running and calling PHP file every second (for updating text and images).

But if someone uploads an image, he/she gets redirected to the url with .php. I've entered a "header" at the bottom, to redirect the user back to page after uploading.

On desktop everything is working perfect. On Android the PHP code isn't working if the user returns.

gallery.php:

<?php
header( "Access-Control-Allow-Origin: *" );
$count = 0;
$oldcount = 0;
if ( $handle = opendir( "../../archive/images/" ) ){
while ( ( $file = readdir( $handle ) ) !== false ){
if ( !in_array( $file, array( ".", ".." ) ) && !is_dir( "../../archive/images/" . $file ) ) 
$count++;
    }
}
if ( $count == $oldcount ){
exit;
}
else{
$oldcount = $count;
$count = 0;
$files = glob( "../../archive/images/" . "*.*" );
foreach( $files as $image ){
if ( $image ){
echo '<img src="' . $image . '" /></img>';
    }
}
}
?>

Tested it on multiple Androids. Every time the same. Seems like it has a problem to call this code after uploading something.

    setInterval(
function(){
$( "#gallery" ).load( "system/communicate/gallery.php" );
$( "#chat" ).load( "system/communicate/output.php" );
}, 1000 );

Any ideas why? Is this a known bug?

If you want to try, please do. Here is my url: www.m7-studios.de user/email: test, pw: test

halfer
  • 18,701
  • 13
  • 79
  • 158
  • 1
    Add code to question please. – Shawn Jan 28 '15 at 22:30
  • not nearly enough info to provide a resonable answer. What phone, what android version? what browser? Can you provide more detail in the flow through your program? What do you mean by "On android the php code isn't working if the user returns." – lukevp Jan 28 '15 at 22:31
  • Sounds like something similar to this http://stackoverflow.com/questions/2692814/httprequest-without-caching. As Shawn said, post more code people will be able to help you better =) Clearer details of what you're trying to do would help too. – Kennifer Jan 28 '15 at 22:35
  • So here you go. this is the "buggy" code. :D BTW maybe you find some mistakes. –  Jan 28 '15 at 22:38
  • Is this an android application, or a browser on an android device? – Kennifer Jan 28 '15 at 22:48
  • It's on desktop- and androidbrowser –  Jan 28 '15 at 22:49

1 Answers1

0

The android browser is probably caching your 1 second requests.

Option 1 On your gallery.php and output.php send some headers to tell it not to cache

<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='expires' content='0'>
<meta http-equiv='pragma' content='no-cache'>

Option 2 Add a random number to the string so the android browser thinks it is a new file

   setInterval(
function(){
    var myrandom=Math.random();
    $( "#gallery" ).load( "system/communicate/gallery.php?random="+myrandom );
    $( "#chat" ).load( "system/communicate/output.php?random="+myrandom );
}, 1000 );
greg_diesel
  • 2,770
  • 1
  • 13
  • 23
  • thank you! you solved this problem in a tricky way. I used option 2. –  Jan 29 '15 at 00:11