Current location: Hot Scripts Forums » General Community » Script Requests » PHP script that will load a php or html file depending on users date


PHP script that will load a php or html file depending on users date

Reply
  #1 (permalink)  
Old 10-05-06, 08:52 PM
Ruy Pedro Ruy Pedro is offline
New Member
 
Join Date: Oct 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Question PHP script that will load a php or html file depending on users date

Sorry but I'm new with PHP and I thank very much if anybody can help me and give me a free scrip for this problem:
I have a site and there's a page that should be diferent depending on the day of the month.
How can I make a script that loads the right page depending on the users computer date.?
I explain better: in the root of the site I have, for instance, 31 pages for the October month and the last page of September: 30September.php, 01oct.php, 02oct.php, 03oct.php, ... 10oct.php, 11oct.php... 29oct.php, 30oct.php, 31oct.php, 01nov.php.
In my contry, today is October, 1 but in another country still is only September 30.
later, in my country still is October 1 but in Japan, for instance is now October 2
How can I make to show to the user the page corresponding to the date in his country ?
I will thank you vary much.

Ruy Pedro
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 10-05-06, 11:15 PM
Keith's Avatar
Keith Keith is offline
Community Liaison
 
Join Date: Feb 2004
Posts: 1,232
Thanks: 1
Thanked 11 Times in 11 Posts
PHP Code:

<?php


// get local time info
$local localtimetime(), TRUE );
// make a timestamp based on local time
$localtime mktime
(
    
$local['tm_hour'],
    
$local['tm_min'],
    
$local['tm_sec'],
    
$local['tm_mon'] + 1,
    
$local['tm_mday'],
    
$local['tm_year'] + 1900
);
// set file name
$filename strtolowerdate'dM'$localtime ) ) . '.php';

echo 
$filename// 05oct.php

?>
__________________
The toxic ZCE

Last edited by Keith; 10-05-06 at 11:26 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 10-07-06, 04:37 AM
Ruy Pedro Ruy Pedro is offline
New Member
 
Join Date: Oct 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Hi Keith !

Thank you for your so quickly answer. I try the code you give me but there is 2 little problems:

1 - The date given is the server date and not the user's computer date (for instance the date in Japan, the date in France or the date in New York). Understand my problem ?

2 - The code you given only stamps a string in the page (for instance 07oct.php). Is missing the code that call and show a page/file with the name like 07oct.php

Can you help me a little more ?

Sorry for boring you. Perhaps all the problem is that I'm new at programing in php
Ruy Pedro
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 10-07-06, 04:52 AM
Ruy Pedro Ruy Pedro is offline
New Member
 
Join Date: Oct 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
The file load problem Is no more a problem. I put this code and it works fine:

if ((include $filename) == 'OK') {
include($filename);
echo 'OK';
}


The problem now is only the first problem : The user's date and not the server's date.

Thanks

Ruy Pedro
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 10-07-06, 10:00 AM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
To get the visitor's date, you need to use javascript and refresh/pass the date as $_GET parameters. I took the following from the example in the PHP manual and modified it to send the visitor's MM/DD. This works in IE6. I will leave it up to you to do the code to take the two values and form the file name -
PHP Code:

<?php

if (isset($_GET['umm']) AND isset($_GET['udd'])) {
  
// output the value gotten from the browser as a test
  
echo "Your MM: {$_GET['umm']} Your DD: {$_GET['udd']}<br />\n";
} else {
  
// form and pass the date variables

  
echo "<script language='javascript'>\n";
  echo 
"var d=new Date()\n";
  echo 
"var dd=d.getDate()\n";
  echo 
"var mm=d.getMonth()\n";
  echo 
"  location.href=\"${_SERVER['SCRIPT_NAME']}?${_SERVER['QUERY_STRING']}"
            
.  "&umm=\" + mm + \"&udd=\" + dd;\n";
  echo 
"</script>\n";
  exit();
}
?>
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 10-07-06, 11:33 AM
AlwaysHopeful AlwaysHopeful is offline
Newbie Coder
 
Join Date: Jul 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
It seems a shame to have to bother using Java. Being simplistic couldn't you just default to a particular date (based on GMT or whatever) and then just have a couple of buttons saying "up a day" or "down a day"?
__________________
We Introduce You attempts to find the best Secured Loans and blogs about finance at the secured loans blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 10-08-06, 08:34 PM
Ruy Pedro Ruy Pedro is offline
New Member
 
Join Date: Oct 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Eureka !....

Mab :

I Want to thank You very, very much. With the alteration I make to call the page instead of only stamp the day and the month on the browser, it works perfectly.
Down I shaw all the code I use now.
In the code you give I saw that first it sends a question to the user's browser and ask the date.
The answer given is transfered by string to the adress of the page in the browser and then the server gives de page of the day of the user's computer.
My only question is: what append if the user has the javascript disabled ?
Once again, than's
Your friend
Ruy Pedro

Code:
<?php 
if (isset($_GET['umm']) AND isset($_GET['udd'])) { 
  // output the value gotten from the browser as a test 
  //echo "Your MM: {$_GET['umm']} Your DD: {$_GET['udd']}<br />\n"; 
  // set file name
$mes = $_GET['umm'];  // I'm portguese. In my language mes = month
$dia = $_GET['udd'];  //  "     "        "   "    "    dia =  day
$filename = strtolower($dia . $mes) . '2006.php';  // In portugal we use the date in this format : dd/mm/yyyy
// echo $filename; // 05oct.php 
if ((include $filename) == 'OK') { 
	include($filename); 
	echo 'OK'; 
} 
  
} else { 
// form and pass the date 
 echo "<script language='javascript'>\n"; 
 echo "var d=new Date()\n"; 
 echo "var dd=d.getDate()\n"; 
 echo "var mm=(d.getMonth() +1 ) \n"; 
 echo "location.href=\"${_SERVER['SCRIPT_NAME']}?${_SERVER['QUERY_STRING']}" 
            .  "&umm=\" + mm + \"&udd=\" + dd;\n"; 
 echo "</script>\n"; 
 exit(); 
} 
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with my largest perl script. Grabbing data from a file. Sunnmann Perl 2 04-23-08 04:27 AM
including php file within html albobis PHP 4 06-12-06 11:15 PM
PHP script allowing to create, and write to an XML file... Xenon121 Script Requests 0 04-18-06 10:50 PM
Trying to recode my php script into c to run on linux... DaJackal C/C++ 1 02-03-06 09:22 PM
Script for picking the first HTML file out of a directory (with sorted HTML files) jelteveld Script Requests 0 08-16-03 02:30 PM


All times are GMT -5. The time now is 11:05 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.