Date Text Problem -- New to PHP
Moderator: General Moderators
Date Text Problem -- New to PHP
I don't know PHP, but I was told that I could come and do what I am trying to do in PHP. I need to make text show on a set date, such as Friday, August 18, 2006. The text then needs to stay there normal. For example,
The visitor clicks a link that says, click here for 8/19/06's random fact. Then, if the date is before then, it shows "You can't see that! It's not time for it yet". If it is that date or after, then the text shown is "The monkey's Latin name rhymes with cat".
Can someone give me a script that does that?
The visitor clicks a link that says, click here for 8/19/06's random fact. Then, if the date is before then, it shows "You can't see that! It's not time for it yet". If it is that date or after, then the text shown is "The monkey's Latin name rhymes with cat".
Can someone give me a script that does that?
have a link on your page like this
Then on somePage.php
NOTE: Untested
Code: Select all
echo '<a href="somePage.php?date='.strtotime("8/19/06").'>click here for 8/19/06\'s random fact</a>';Code: Select all
$date = $_GET['date'];
if($date < time())
echo "You can't see that! It's not time for it yet";
else
echo 'The monkey\'s Latin name rhymes with cat';Code: Select all
<?php
$text = "The monkey's Latin name rhymes with cat";
$month = 8;
$day = 17;
$year = 2006;
$date = mktime(0, 0, 0, $month, $day, $year);
$day_after_date = $date + (60 * 60 * 24);
$now = time();
if( $now >= $date){
if($now <= $day_after_date){
echo $text;
}
else{
echo "You are too late!";
}
}
else{
echo "It is not time for you to see this yet";
}
?>uhh... yea his is better.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
mvd7793 wrote:Can someone give me a script that does that?
, give you a script? No. Help you make it yourself? Yes. Learning is an goal we must do ourselves, not be dragged to.I would use date() in two places: the in-page displayed date and the date passed via URL when requesting the "random fact."
I would choose to use the format of YYYYMMDD or some combination thereof. As long as it doesn't have symbols, it'll work with this method. Now, on the fact request page, I would look at the date passed. Is it all numbers? ctype_digit(). Is it the right length? strlen().
After this bit of checking it's time to break out substr() and extract out the year, month and day. It's probably a good idea to use checkdate() to make sure they are valid. Now give them to mktime(), then date() to format them for lookup: YYYY-MM-DD. We do this because the date given can actually be off in a few ways whereas mktime() will correct it. Now it's just a matter of looking this new date up somewhere after verifying that the date is not in the future by using time() and comparing the return value from mktime().
I'm Trying it
Ok, I'm trying it. Please stay tuned for any other responses from me.
What do I make the PHP Page in?
Can I make the PHP page in Notepad?
Couldn't Get It to Work
I couldn't get it to work. Do I have to put the php code in an HTML page, or a PHP page? Do I have to put any special tage around the PHP code?
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Re: Couldn't Get It to Work
This leads me to believe that you have limited PHP development experience. There is nothing wrong with that, but I would realy recommend you read the introduction to PHP portion of the PHP Manual. Then click the links in the table of contents and read through them.mvd7793 wrote:I couldn't get it to work. Do I have to put the php code in an HTML page, or a PHP page? Do I have to put any special tage around the PHP code?
After that, read the Basic tutorial section of the PHP Manual. Click the links in the table of contents and read throught those articles. Practise what you learn there, then try some stuff, then come back here and post with any problems you may be having.
I am new...
I am new to php. I have never done it. I really don't have time to learn it. Can someone please give me a code, fully ready for an html or php page? You could also take one of the ones above and put some simple brackets around it. I really don't have a clue how to do that.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA

