FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Need help with Java





SBrian
Good day to all,

I have a problem, I want that the visitors of my website on monday another page get, that on the rest of the week. Is there a script for it?
BlackSkad
I know it isn't Java, it's php. But this works very easy, and isn't hard to learn:
Code:
<?php
//days are represented by a number from 1 (monday) till 7 (sunday)
//more about the date-function and his parameters: http://www.php.net/manual/en/function.date.php
$dayNumber = date ('N');

//control if the number of the current day, is the number of monday (so is it 1?)
if ($dayNumber == 1)
{
   header ('location: http://www.yoursite.com/specialMondayPage.htm');
}
else
{
//use the header()-function again to go to another page,
//like: header ('location: http://www.yoursite.com/normalPage.htm');
//or get all your other code in here
}
?>


More about php: php.net or the tutorial-section Smile

Greatz,
BlackSkad
tony
I made the code a little simpler. You can make this the page you want people to see every day except Monday and save it as a .php file. Then put your monday page in the mondaypage.html file.

Code:

...All your nonMonday HTML here...

<?
   $x = date ('N');
   if ($x == 1)
      header ('location: http://www.yoursite.com/mondaypage.html');
?>
BlackSkad
If you would like to do it the way Tony said, your code should look like this:
(it's also better to use the long php tags (<?php ... ?>) to prevent confusion with XML)
Code:
<?php
   $x = date ('N');
   if ($x == 1)
      header ('location: http://www.yoursite.com/mondaypage.html');
?>
 ...All your nonMonday HTML here...


If not, you'll get an error like "FATAL ERROR: Cannot send header; Headers are already sent at line 1", because you output the normal html first. In the other way, everything should work fine Smile
If it doesn't you can use an outputbuffer to make it work. (ob-start sould help you with this.)
ignition
Just a pointer...but Java and JavaScript are 2 completely unrelated things. Don't put "Java" in your thread title when you're talking about JS.

You could no more write a script for what you want in Java than you could in c++.
dandelion
I would like to insert one line into BlackSkad's code to prevent non-Monday HTML output after sending the header.
Code:
<?php
   $x = date ('N');
   if ($x == 1) {
      header ('Location: http://www.yoursite.com/mondaypage.html');
      exit(0);
  }
?>
<!-- ...All your nonMonday HTML here... -->

Please note the 'N' format added in PHP 5.1.0. With PHP 4 and PHP 5.0 use the 'w' format.
Code:
<?php
  if (date('w') == 1) { /* ... */ }
?>

Well, PHP is great and strongly recommended, but in some cases using Javascript is reasonable, e.g. on PHP unsupported servers. You can use the following code.
Code:
<script type="text/javascript">
  today = new Date();
  if (today.getDay() == 1) {
    location.href = 'http://www.example.com/monday.html'
    window.stop()
  }
</script>
SBrian
Thank you very much for you help.
Related topics
Java Game
Problems with Java
JAva HELP
I can help design your website.
How to make an execution file (*.exe) for java program?
Does anypne help me about JAVA on UNIX?
Help with php and java script
Java Help
java help
[Java] Wanna help me figure out this error?
Help needed for making a server in java....
Java BlueJ - any help?
Help in Java ?
Which language should I learn during my semester break?
Java Servlet Help needed
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.