Jump to content

How to change position on each page load(?)


Recommended Posts

Hi all,
I'm using a file hosting script and when someone goes to the download page to download a file
there's a countdown timer.So when then counter goes to zero,the following code is used
to display a button and give access to the file:
[code]
<?php


if($downloadtimer == 0) {

echo "<input type=submit value=\"Download it\" onClick=\"".$scripturl. "download2.php?a=" . $filecrc . "&b=" . md5($foundfile[2].$_SERVER['REMOTE_ADDR'])."\">";
} else { ?>
If you're seeing this message, you need to enable JavaScript

<?php } ?> [/code]
I have already tried [code]style=\"position:relative;top:$top;left:$left;\" [/code] + [code]$top = rand(0,100);
$left = rand(0,100); [/code] but it's not working.

So is there any way to change the position of the "download button" using php?

thanks!

ps.I can post the whole script code if it's necessary.

Link to comment
https://forums.phpfreaks.com/topic/30411-how-to-change-position-on-each-page-load/
Share on other sites

You could also use the following:
[code]
<style>
.test{
position:absolute;
left:<?php echo rand(0,100); ?>px;
top:<?php echo rand(0,100); ?>px;
}
//put this with your earlier styles, and make sure that you haven't used the word test to define any classes
</style>

...

<?php echo "<div class=\"test\"><input type=submit value=\"Download it\" onClick=\"".$scripturl. "download2.php?a=" . $filecrc . "&b=" . md5($foundfile[2].$_SERVER['REMOTE_ADDR'])."\"></div>";
?>
[/code]
Just the way you had it in your PHP tag, plus the required <div>
Ok,I changed the code to this:
[code]
<?php
$top = rand(1,300);
$left = rand(5,100);

if($downloadtimer == 0) {

echo "<div style=position:absolute; top:$top; left:$left;><input type=submit value=\"Download It\" onClick=\"".$scripturl. "download2.php?a=" . $filecrc . "&b=" . md5($foundfile[2].$_SERVER['REMOTE_ADDR'])."\"></div>";
} else { ?>
If you're seeing this message, you need to enable JavaScript

<?php } ?>[/code]
I'm not getting any errors,but when the counter goes to zero the button stays on the same place.
Any ideas?
I did some tests
Summary:

After your help I changed the code to this:
[code]<?php
$top = rand(1,100);
$left = rand(1,100);

echo "<div style=position:absolute; top:$top; left:$left;>";
?>

<?php

if($downloadtimer == 0) {

echo "<input type=submit value=\"Download It\" onClick=\"".$scripturl. "download2.php?a=" . $filecrc . "&b=" . md5($foundfile[2].$_SERVER['REMOTE_ADDR'])."\">";
} else { ?>
If you're seeing this message, you need to enable JavaScript

<?php } ?>
</div>[/code]

And now instead of the counter I get this message: "If you're seeing this message, you need to enable JavaScript".

mgallforever: $downloadtimer  is defined in a config file.I have set it to 5 seconds.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.