Jump to content

Recommended Posts

Question 1. How can i make it so one of my pages cant be accessed dueing certon times? i.e the page will open at 8am and will close at 8pm once it is closed it will echo something like "We are closed we open at 8am and close at 8pm" can this be done?

Question 2. How can i make a random number like 0.003? the fact for this is i am making a gym for my game so i want a random number from 0.001 to 0.020. i tried this way but didn't work how i wanted it to.

[code]<?PHP
$rand_strength = rand(0,0) . rand(0,0) . rand(1,20);

echo "You have gained $rand_strength strength";
$db->query("UPDATE users SET uStrength=uStrength+'$rand_strength' WHERE uID='" . $user['uID'] . "'");
?>[/code]

This is the results i got "You have gained 0018 strength"

Thanks for your time
Link to comment
https://forums.phpfreaks.com/topic/25356-ok-2-questions-solved/
Share on other sites

[code]
<?php
$hour = date('H');
if ($hour < 8){
echo "We are closed we open at 8am and close at 8pm";
}
elseif ($hour > 20){
echo "We are closed we open at 8am and close at 8pm";
}
else {
// normal page
}
?>[/code]

Watch out as '$hour' is the hour in server time of course, you might need to change that to match your time zone.

I'm not too sure about your second question, but something like this probably works:

[code]
<?PHP
$rand_strength = rand(0,0).".". rand(0,0).".". rand(1,20);

echo "You have gained $rand_strength strength";
$db->query("UPDATE users SET uStrength=uStrength+'$rand_strength' WHERE uID='" . $user['uID'] . "'");
?>
[/code]

Good luck :)
Link to comment
https://forums.phpfreaks.com/topic/25356-ok-2-questions-solved/#findComment-115611
Share on other sites

if you want to show a page only if it is between 8 am and 8 pm, then do this

[code]
<?php
$hr = date("G");
if($hr < 20 && $hr > 7){
//show the page
} else {
echo('Sorry, page closed');
}
?>
[/code]

p.s. doublecheck the numbers in my if statement, they should be accurate but I'm not exactly certain.

also if you need to modify your timezone, say you're on PST and your server is EST, do this:

[code]
<?php
$hr = date("G");
$offset = $hr - 3;
?>
[/code]

also, freeloader, when you put a date function in a variable, using " instead of ' is more error-proof

and the H format in date uses leading zeros, keep that in mind.
Link to comment
https://forums.phpfreaks.com/topic/25356-ok-2-questions-solved/#findComment-115612
Share on other sites

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.