ayunami2000
ayunami2000

Reputation: 459

mt_rand and rand not changing on page reload

I am having an odd issue with PHP. Here's my code:

<?php $rand = mt_rand(0,99);?>
<!doctype html5>
<html>
<head>
<title>MCAP</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div style="width:<?php echo $rand;?>%;background:blue no-repeat left center;background-size:100% 100%;height:100%;"><?php echo $rand;?>%</div>
</body>
</html>

The issue I'm facing is that the page will not update the number when I refresh it.

The site: http://play.elementfx.com

It will show a random number when I initially load the page, and when I refresh it once, but refreshing the page any more makes no difference. I am using an iPhone SE on Safari on iOS 11.0.2, in case that matters.

EDIT: It seems like a cache issue, but I'm not sure.

Upvotes: 0

Views: 337

Answers (2)

Progman
Progman

Reputation: 19545

You have a server side cache for your PHP script response:

HTTP/1.1 200 OK
Date: Sun, 08 Oct 2017 20:17:58 GMT
Content-Type: text/html
Vary: Accept-Encoding
X-Varnish: 291144118 290391078
Age: 7
X-Cache: HIT
X-Cache-Hits: 5
Accept-Ranges: bytes
Connection: keep-alive

Disable the cache in your server configuration or ask the administrator to do so.

Upvotes: 2

M0ns1f
M0ns1f

Reputation: 2725

safari cache you page try this

Go to Safari > Empty Cache, or hit Opt+Cmd+E. To refresh, click the refresh button on the addressbar or press Cmd+R.

Another tip. If you want to restore Safari, like completely clear all the caches, or parts of it, go to Safari > Reset Safari. I use it usually when I need to clear a lot of memory from Safari, for it will clear the webpage screenshots, the cookies, the favicons, etc.


Edit: On the latest version of Empty Cache isn't on the Safari menu any more. It's now on the Develop menu. To show the Develop menu it, go to Safari > Preferences..., click the Advanced tab, and check Show Develop menu in menu bar. The keyboard shortcut remains unchanged, though.

Safari > Reset Safari isn't an option any more. To clear history you can use History > Clear History... and to clear cookies/local storage data, go to Safari > Preferences..., click the Privacy tab, and either click Remove All Website Data... or Details... to view and remove it for individual sites.

Upvotes: 0

Related Questions