Redirecting URL's using PHP
Moderator: General Moderators
-
eduardosbs
- Forum Newbie
- Posts: 4
- Joined: Fri May 16, 2008 7:45 am
Redirecting URL's using PHP
Hello all,
I need some help whit this subject:
I need to redrect URLs as the server time, I was trying some thing like this:
<?php
$hour = (int)date("H");
if ($hour >= 9 && $hour < 10) {
echo "<meta http-equiv="Refresh" content="5; url=http://www.google.com">";
} elseif ($hour >= 10 && $hour < 12){
echo "<meta http-equiv="Refresh" content="5; url=http://www.google.com">";
} elseif ($hour >= 12 && $hour < 13){
echo "<meta http-equiv="Refresh" content="5; url=http://www.google.com">";
(the code continues until 24h)
But is not working... could some one help me ??
I need some help whit this subject:
I need to redrect URLs as the server time, I was trying some thing like this:
<?php
$hour = (int)date("H");
if ($hour >= 9 && $hour < 10) {
echo "<meta http-equiv="Refresh" content="5; url=http://www.google.com">";
} elseif ($hour >= 10 && $hour < 12){
echo "<meta http-equiv="Refresh" content="5; url=http://www.google.com">";
} elseif ($hour >= 12 && $hour < 13){
echo "<meta http-equiv="Refresh" content="5; url=http://www.google.com">";
(the code continues until 24h)
But is not working... could some one help me ??
Re: Redirecting URL's using PHP
You need to fix your quotes. This...
... will break PHP. PHP will think the string ends at equiv=. Either backslash the quotes in the string, or use single quotes rather than double quotes.
Code: Select all
echo "<meta http-equiv="Refresh" content="5; url=http://www.google.com">";
Re: Redirecting URL's using PHP
Your code below is confusing.
First off, is the same as
Same with that is the same as
Not to mention your meta refreshes are all the same. The refresh is for 5 seconds and all the URLs go to http://www.google.com.
What are you trying to achieve here?
Code: Select all
if ($hour >= 9 && $hour < 10) {
echo "<meta http-equiv="Refresh" content="5; url=http://www.google.com">";
} elseif ($hour >= 10 && $hour < 12){
echo "<meta http-equiv="Refresh" content="5; url=http://www.google.com">";
} elseif ($hour >= 12 && $hour < 13){
echo "<meta http-equiv="Refresh" content="5; url=http://www.google.com">";
Code: Select all
if ($hour >= 9 && $hour < 10)Code: Select all
if ($hour == 9)Same with
Code: Select all
elseif ($hour >= 12 && $hour < 13)Code: Select all
if ($hour == 12)What are you trying to achieve here?
Last edited by dbemowsk on Sat May 17, 2008 10:55 pm, edited 1 time in total.
-
suresh_2220
- Forum Newbie
- Posts: 23
- Joined: Mon May 12, 2008 3:13 pm
Re: Redirecting URL's using PHP
You can use PHP header() fn inorder to redirect URL. for Eg :
Code: Select all
<?php
header("Location: http://suresh-mobileweb.blogspot.com");
?>
-
eduardosbs
- Forum Newbie
- Posts: 4
- Joined: Fri May 16, 2008 7:45 am
Re: Redirecting URL's using PHP
Ok all,
for my last issue Iám ok ! now I am trying to do some thing like this...
<?php
$hour = date('H');
$min = date('i');
echo $hour;
echo $min;
/* 9:00 horas as 9:30 */
if ($hour >= 9 && $min < 30) {
echo "<meta http-equiv=\"Refresh\" content=\"5; url=http://www.URL1.com\">";
/* 9:30 horas as 10:00 */
} elseif ($hour >= 9 && $min > 30) {
echo "<meta http-equiv=\"Refresh\" content=\"5; url=http://www.URL2.com\">";
/* 10:00 horas as 10:30 */
} elseif ($hour >= 10 && $min < 30){
echo "<meta http-equiv=\"Refresh\" content=\"5; url=http://www.URL3.com\">";
/* 10:30 horas as 11:00 */
} elseif ($hour >= 10 && $min > 30){
echo "<meta http-equiv=\"Refresh\" content=\"5; url=http://www.URL4.com\">";
/* 11:00 horas as 11:30 */
} elseif ($hour >= 11 && $min < 30){
echo "<meta http-equiv=\"Refresh\" content=\"5; url=http://www.URL5.com\">";
/* 11:30 horas as 12:00 */
} elseif ($hour >= 11 && $min > 30){
echo "<meta http-equiv=\"Refresh\" content=\"5; url=http://www.URL6.com\">";
}
/* the code continues..... */
I need to redirect to a diferent url after 30 minutes... but the code above is not working... some one could help me ?
for my last issue Iám ok ! now I am trying to do some thing like this...
<?php
$hour = date('H');
$min = date('i');
echo $hour;
echo $min;
/* 9:00 horas as 9:30 */
if ($hour >= 9 && $min < 30) {
echo "<meta http-equiv=\"Refresh\" content=\"5; url=http://www.URL1.com\">";
/* 9:30 horas as 10:00 */
} elseif ($hour >= 9 && $min > 30) {
echo "<meta http-equiv=\"Refresh\" content=\"5; url=http://www.URL2.com\">";
/* 10:00 horas as 10:30 */
} elseif ($hour >= 10 && $min < 30){
echo "<meta http-equiv=\"Refresh\" content=\"5; url=http://www.URL3.com\">";
/* 10:30 horas as 11:00 */
} elseif ($hour >= 10 && $min > 30){
echo "<meta http-equiv=\"Refresh\" content=\"5; url=http://www.URL4.com\">";
/* 11:00 horas as 11:30 */
} elseif ($hour >= 11 && $min < 30){
echo "<meta http-equiv=\"Refresh\" content=\"5; url=http://www.URL5.com\">";
/* 11:30 horas as 12:00 */
} elseif ($hour >= 11 && $min > 30){
echo "<meta http-equiv=\"Refresh\" content=\"5; url=http://www.URL6.com\">";
}
/* the code continues..... */
I need to redirect to a diferent url after 30 minutes... but the code above is not working... some one could help me ?
Re: Redirecting URL's using PHP
I googled "meta refresh content".
The first several links had your answer.
That number in content= is the number of seconds until the refresh.
The first several links had your answer.
That number in content= is the number of seconds until the refresh.
-
eduardosbs
- Forum Newbie
- Posts: 4
- Joined: Fri May 16, 2008 7:45 am
Re: Redirecting URL's using PHP
puke7 wrote:I googled "meta refresh content".
The first several links had your answer.
That number in content= is the number of seconds until the refresh.
tks for your reply but, thats noto the point ! i know that content is the number of seconds until refresh...
I have a webpage and i need a code that do some thing like this:
when you type http://www.mywebpage.com you will be redirected after 5 seconds to a diferent webpage , so i need a code that do this wich 30 minutes to a diferent url like i typed above !
Re: Redirecting URL's using PHP
I really wish people wouldn't put things like "the code above is not working". It's useless. Unless you tell us what's happening, or not happening, and what you expect it to do, there's nothing anyone can really do.
Taking a guess though.. only the first 2 URLs work, right?
Think about your conditions. You have:
What happens if $hour is 100 and $min is 20? It matches the first condition. If $hour is 100 and $min is 40 it matches the second condition. None of the other conditions will ever be matched because the first two catch every possibility.
Personally I'd use a switch anyway..
Taking a guess though.. only the first 2 URLs work, right?
Think about your conditions. You have:
Code: Select all
if ($hour >= 9 && $min < 30) {
} elseif ($hour >= 9 && $min > 30) {
etcPersonally I'd use a switch anyway..
Code: Select all
<?php
$hour = date('H');
$min = date('i');
switch ($hour) {
case 9: $url = ($min < 30) ? "www.url1.com" : "www.url2.com"; break;
case 10: $url = ($min < 30) ? "www.url3.com" : "www.url4.com"; break;
case 11: $url = ($min < 30) ? "www.url5.com" : "www.url6.com"; break;
default: $url = "www.thisdomainifsomethinggoeswrong.com"; break;
}
echo "<meta http-equiv=\"Refresh\" content=\"5; url=http://".$url."\">";
-
eduardosbs
- Forum Newbie
- Posts: 4
- Joined: Fri May 16, 2008 7:45 am
Re: Redirecting URL's using PHP
onion2k wrote:I really wish people wouldn't put things like "the code above is not working". It's useless. Unless you tell us what's happening, or not happening, and what you expect it to do, there's nothing anyone can really do.
Taking a guess though.. only the first 2 URLs work, right?
Think about your conditions. You have:What happens if $hour is 100 and $min is 20? It matches the first condition. If $hour is 100 and $min is 40 it matches the second condition. None of the other conditions will ever be matched because the first two catch every possibility.Code: Select all
if ($hour >= 9 && $min < 30) { } elseif ($hour >= 9 && $min > 30) { etc
Personally I'd use a switch anyway..Code: Select all
<?php $hour = date('H'); $min = date('i'); switch ($hour) { case 9: $url = ($min < 30) ? "www.url1.com" : "www.url2.com"; break; case 10: $url = ($min < 30) ? "www.url3.com" : "www.url4.com"; break; case 11: $url = ($min < 30) ? "www.url5.com" : "www.url6.com"; break; default: $url = "www.thisdomainifsomethinggoeswrong.com"; break; } echo "<meta http-equiv=\"Refresh\" content=\"5; url=http://".$url."\">";
Hi ,
I really apreciate your reply... but could you explain a little bit the code? sorry but i am a begginer... i got the idea but not at all....
this code is very very important to me if you explain the idea for me i will be apreciate a lot !!!!
regards
Re: Redirecting URL's using PHP
Switch statements: http://uk3.php.net/switch
Ternary if operator: http://uk3.php.net/ternary (scroll down a little way)
echo function: http://uk3.php.net/manual/en/function.echo.php
Ternary if operator: http://uk3.php.net/ternary (scroll down a little way)
echo function: http://uk3.php.net/manual/en/function.echo.php