Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Help with php


ghost's Avatar
0 0

Ok I would like to make a url with php. Lets say…

http://mydomain.com/servlet/Index.php?nid=2

How would I make it to where the "nid=#" be a new number everytime the user refreshed the page.

I was thinking something like

<?php for ($i=0;$i<=10;++$i) { echo '<a href="http://mydomain.com/servlet/Index.php?nid='. $i . '">Click Here to refresh</a>'; } ?>

But its not working apparently. Im a noob. Sorry.


ynori7's Avatar
Future Emperor of Earth
0 0

Froger wrote: <?php for ($i=0;$i<=10;++$i) { echo '<a href="http://mydomain.com/servlet/Index.php?nid='. $i . '">Click Here to refresh</a>'; } ?> That'll just print out 10 hyperlinks.

You could just say:

echo &quot;&lt;a href=&#39;http://mydomain.com/servlet/Index.php?nid=$i&#39;&gt;Click Here to refresh&lt;/a&gt;&quot;;```
But of course the user will have to click your link to make the number change, if they hit refresh it wont do it. Why exactly do you want the value in the url to change?

ghost's Avatar
0 0

I see you've got the whole concept of how php works and is utilized wrong. It's not one transnet program that ends and waits for a user reaction everytime an echo statement is used. It's one script that is executed in its entirety, in this case on the server and can then execute again if called for again, etc. What you'd need is a session for the person where you can keep a counter variable that gets incremented every time the person asks for that page. For more info: http://www.tizag.com/phpT/phpsessions.php However, I'd really recommend you to get a more firm grasp on php first.


ghost's Avatar
0 0

ynori7 wrote:

markup$i=rand(0, 10);

This is actually what I did. The reason why is because I couldnt prevent my mobile browser from caching images no matter what I did. So I had to make sure that when Refreshing the url would change. Now my browser isnt caching images files so the page can now be reloaded successfully. Thanks yall.


ynori7's Avatar
Future Emperor of Earth
0 0

Froger wrote: Thanks yall. …Not entirely sure I understand, but glad I could help.


ghost's Avatar
0 0

ynori7 wrote: [quote]Froger wrote: Thanks yall. …Not entirely sure I understand, but glad I could help.[/quote]

Say you're working on a design but you're web browser keeps caching the CSS file, a simple solution on this is:

echo "<link src=\"/styles/theme.css?rand=".rand(0,1000)."\" />";

The CSS file doesn't parse the GET variable, although the web browser will think that this is a new file that hasn't been cached yet. Ergo, it will fetch that file instead of the cached one.