links

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Vietboy
Forum Commoner
Posts: 41
Joined: Mon Dec 01, 2003 10:59 pm

links

Post by Vietboy »

I'm trying to write a script that it will show redirect to different links depends on the seasons of the year.

Could any one fix the script? It doesn't work for me when I test it out.

Code: Select all

<?php

$link[1] = "1.html",
//spring
$link[2] = "2.html";
//summer
$link[3] = "3.html";
//fall
$link[4] = "4.html";
//winter

$rmq = date("n"); 
 if ($rmq >= 3 && $rmq <= 5) { 
 //show spring
  echo "<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">";
  echo "<meta http-equiv="refresh" content="2;URL=$link[1]">";

 }
 
if ($rmq >= 6 && $rmq <= 9) { 
//show summer
  echo "<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">";
  echo "<meta http-equiv="refresh" content="2;URL=$link[2]">";

 }
 
 if ($rmq >= 10 && $rmq <= 11) { 
 //show fall
   echo "<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">";
  echo "<meta http-equiv="refresh" content="2;URL=$link[3]">";

 }
 
 if ($rmq >= 1 && $rmq <= 2) { 
 //show winter
   echo "<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">";
  echo "<meta http-equiv="refresh" content="2;URL=$link[4]">";

 }
 
 if ($rmq = 12) { 
 //show winter
   echo "<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">";
  echo "<meta http-equiv="refresh" content="2;URL=$link[4]">";

 }
 

?>
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

From what I guess, you have to use ElseIf() rather than If() everytime. Any why not use header("Location: 1.html")?

-Nay
Paddy
Forum Contributor
Posts: 244
Joined: Wed Jun 11, 2003 8:16 pm
Location: Hobart, Tas, Aussie
Contact:

Post by Paddy »

This

if ($rmq = 12) {

needs to be this

if ($rmq == 12) {

What is the error, or wrong output, you are getting?
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post by redmonkey »

Hi,

Your first link has a , at the end of the line, this should be a ;

Also you need to escape the " character in your echo calls, so..

Code: Select all

echo "<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">";
should be...

Code: Select all

echo "<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">";
That being said, I would probably use the header function for this redirect. In this case....

Code: Select all

header("Location: ./$link[0]");
Personally I would use a switch type approach to this problem. So the whole code would be something like this....

Code: Select all

<?php

$rmq = date("n");

switch ($rmq) {
	
	case 3:
	case 4:
	case 5:
	$page = '1.html';
	break;
	
	case 6:
	case 7:
	case 8:
	case 9:
	$page = '2.html';
	break;
	
	case 10:
	case 11:
	$page = '3.html';
	break;
	
	case 1:
	case 2:
	case 12:
	$page = '4.html';
	break;
}

header("Location: ./$page");
exit;

?>
For some odd reason my PHP closing tag is not showing up? very odd.
Vietboy
Forum Commoner
Posts: 41
Joined: Mon Dec 01, 2003 10:59 pm

Post by Vietboy »

Code: Select all

<?php 

$rmq = date("n"); 

switch ($rmq) { 
    
   case 3: 
   case 4: 
   case 5: 
   $page = 'spring.php'; 
   break; 
    
   case 6: 
   case 7: 
   case 8: 
   case 9: 
   $page = 'summer.php'; 
   break; 
    
   case 10: 
   case 11: 
   $page = 'fall.php'; 
   break; 
    
   case 1: 
   case 2: 
   case 12: 
   $page = 'winter.php'; 
   break; 
} 

header("Location: ./$page"); 
exit; 
?>

<html>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<frameset rows="80,*" cols="*" frameborder="NO" border="0" framespacing="0">
  <frame src=".$/page" name="top" scrolling="NO" noresize>
  <frameset cols="100,*" frameborder="NO" border="0" framespacing="0">
    <frame src="left.php" name="left" scrolling="NO" noresize>
    <frame src="main.php" name="main">
  </frameset>
</frameset>
<noframes><body>
</body></noframes>
</html>
?>

How would I put that into the frame src? Like this ? <frame src=".$/page"> ?
?>
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post by redmonkey »

Code: Select all

<?php

$rmq = date("n");

switch ($rmq) {
   
   case 3:
   case 4:
   case 5:
   $page = 'spring.php';
   break;
   
   case 6:
   case 7:
   case 8:
   case 9:
   $page = 'summer.php';
   break;
   
   case 10:
   case 11:
   $page = 'fall.php';
   break;
   
   case 1:
   case 2:
   case 12:
   $page = 'winter.php';
   break;
}

?>

<html>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<frameset rows="80,*" cols="*" frameborder="NO" border="0" framespacing="0">
  <frame src="<?php echo $page ?>" name="top" scrolling="NO" noresize>
  <frameset cols="100,*" frameborder="NO" border="0" framespacing="0">
    <frame src="left.php" name="left" scrolling="NO" noresize>
    <frame src="main.php" name="main">
  </frameset>
</frameset>
<noframes><body>
</body></noframes>
</html>
Post Reply