简体   繁体   中英

Device differences in PHP code producing different results

I seem to be getting different results every time I run a PHP script.

On Windows and Chrome, the script runs as it should. On Android Chrome, it's almost as if the script is being ran twice before resulting in an error. As you can tell, the following script is being used to make sure a request can only be made once (no refreshes etc).

On Android, The script runs, it finds the row in the history table, the row gets removed from the history table as it should BUT it also unsets $uploadId resulting in the rest of the script not working. I fail to see how both sides of the if statement get run, unless somehow the Chrome browser on Android is running the page twice for performance or other reasons.

$historyQuery = "SELECT id FROM history WHERE userID = '".$_SESSION['userID']."'";
$historyQuery .= " AND historyCustom = '".$uploadId."' LIMIT 0, 1";
$checkHistory = mysqli_query($conn, $historyQuery);
if(mysqli_num_rows($checkHistory) == 0) {
    unset($uploadId);
} else {
    $historydetail = mysqli_fetch_array($checkHistory);
    mysqli_query($conn, "DELETE FROM history WHERE id = '".$historydetail['id']."'");
}

I've now tested under Firefox for Android and the script is running as it should, just like on Windows Chrome. Seems like it's an Android Chrome only issue.

Also, I've came accross the following question: https://stackoverflow.com/questions/29490740/does-chrome-for-android-automatically-compress-and-resize-images which seems to have a similar idea.

The uploadId is always the same before the unset function. It's after the unset that surprise... it gets unset but at the same time that it deletes the row in the history.

After some more research and testing, it seems to me (I may be corrected) that Chrome on Android can actually do pre-loading TWICE on a page/request before it displays the page.

The first I found due to my code reporting a different IP requesting the script. This caused the first failure of my code (not displayed above). So if you're relying on your script passing the referrer IP and expecting the same one, this will cause problems where the 'Data Saver' is turned on.

The second I've found due to testing on different devices. As far as I'm concerned there is NO other explanation as to why the code would return anything different in another browser. As treegarden mentioned, PHP is server side so the browser choice shouldn't influence it (even though it does in this example). This is causing me problems where I expect the script to only be ran once per request due to security. I think I'm going to have to add to time-based checking to the script also.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM