Page 1 of 1
Date Text Problem -- New to PHP
Posted: Fri Aug 18, 2006 9:15 am
by mvd7793
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?
Posted: Fri Aug 18, 2006 9:23 am
by JayBird
have a link on your page like this
Code: Select all
echo '<a href="somePage.php?date='.strtotime("8/19/06").'>click here for 8/19/06\'s random fact</a>';
Then on somePage.php
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';
NOTE: Untested
Posted: Fri Aug 18, 2006 9:24 am
by Luke
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";
}
?>
not tested
uhh... yea his is better.

Posted: Fri Aug 18, 2006 9:27 am
by feyd
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
Posted: Fri Aug 18, 2006 9:28 am
by mvd7793
Ok, I'm trying it. Please stay tuned for any other responses from me.
What do I make the PHP Page in?
Posted: Fri Aug 18, 2006 9:30 am
by mvd7793
Can I make the PHP page in Notepad?
Posted: Fri Aug 18, 2006 9:32 am
by JayBird
yes
But
check here for better (free) editors that will make your life easier
Ok
Posted: Fri Aug 18, 2006 9:47 am
by mvd7793
OK. Thanks
Couldn't Get It to Work
Posted: Fri Aug 18, 2006 10:02 am
by mvd7793
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?
Posted: Fri Aug 18, 2006 10:08 am
by JayBird
Ok
Posted: Sat Aug 19, 2006 10:01 am
by mvd7793
Ok. I will look at it and see if I can figure it out.
Re: Couldn't Get It to Work
Posted: Sat Aug 19, 2006 10:42 am
by RobertGonzalez
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?
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.
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...
Posted: Sat Aug 19, 2006 10:45 am
by mvd7793
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.
Posted: Sat Aug 19, 2006 11:51 pm
by RobertGonzalez
There are plenty of developers that will write this code for you... for a fee. Few around here will do it for you.