使用php重定向1个短url到2个url

问题描述:

我想用php重定向一个短url到2个url。第一个URL立即重定向,第二个URL在一小时后重定向。当第二个网址在一小时后重定向时,第一个网址停止重定向。一小时后url只重新定向。使用php重定向1个短url到2个url

是否有可能使用PHP?

如果你需要更多的细节问我。谢谢。

更多详细信息:
我做了一个排序url工具/脚本。我想在一个排序网址上一次添加两个网址。如:我想在一次google.com and youtube.com短结果一个网址进行排序这两网址example.com/gdh733

当我访问短网址sxample.com/gdh733其立即重定向我第一个URL,1小时后第一个URL不是重定向,只有第二个URL youtube.com开始转向。

希望让你明白。如果不明白问我。

再次更新:
数据库:
Database Imagehttp://devlup.com/wp-content/uploads/2010/08/database-structure-php-shortener.png

htaccess的:

RewriteEngine on 
RewriteRule ^([\w\d]{4})$ decoder.php?decode=$1 [L] 

的index.php

<div class="header"> Php URL shortener<hr /></div> 
<div class="content"> 
<form id="form1" name="form1" method="post" action="shorten.php"> 

    <p><strong> Url:</strong> 
    <input type="text" name="url" id="url" size="45" /> 
    </p> 
    <p> 
    <input type="submit" name="Submit" id="Submit" value="Shorten" /> 
    </p> 
    <p>&nbsp;</p> 
</form> 

shorte n.php

<div class="header"> Php URL shortener<hr /></div> 
<div class="content"> 

<?php 

$con = mysql_connect("localhost","masudtoo_short2","masud226688"); 
if (!$con) 
    { 
    die('Could not connect: ' . mysql_error()); 
    } 
mysql_select_db("masudtoo_short", $con); //Replace with your MySQL DB Name 
$urlinput=mysql_real_escape_string($_POST['url']); 
$id=rand(10000,99999); 
$shorturl=base_convert($id,20,36); 
$sql = "insert into save values('$id','$urlinput','$shorturl')"; 
mysql_query($sql,$con); 
echo "Shortened url is <a href=\"http://short.masudtools.xyz/". $shorturl ."\">http://short.masudtools.xyz/". $shorturl ."</a>"; 
mysql_close($con); 
?> 

</div> 

decoder.php

<?php 

$con = mysql_connect("localhost","masudtoo_short2","masud226688"); 
if (!$con) 
    { 
    die('Could not connect: ' . mysql_error()); 
    } 
mysql_select_db("masudtoo_short", $con); //Replace with your MySQL DB Name 


$de= mysql_real_escape_string($_GET["decode"]); 



$sql = 'select * from save where shortened="$de"'; 

$result=mysql_query("select * from save where shortened='$de'"); 

while($row = mysql_fetch_array($result)) 
{ 
$res=$row['url']; 
header("location:".$res); 
} 

?> 

这里我设置2网址和会话PHP代码?

+1

是的,我们需要更多的细节,也不清楚你在问什么。 –

+0

是的,这是可能的,如果你需要更多的细节问我_先生,你没有下订单。**所有的细节和你已经尝试应该已经发布的问题。** –

+0

我更新了我的文章@ julien-lachal和saad-suri –

当然是的,它是可能的,使用SessionsJavaScript

在这个例子中,我重定向每5秒。 1小时使用:

<?php 
    session_start() ; 

    //If session not set, redirect immediatly. First time only 
    if (!isset($_SESSION["isRedirected"]) || $_SESSION["isRedirected"] != 1) { 
     $_SESSION["isRedirected"] = "1" ; 
     header("Location: index2.php") ; 
    } 

?> 
<html> 
    <head> 

    </head> 
    <body> 
     <h2>Index 1</h2> 

     <script src='https://code.jquery.com/jquery-2.1.4.min.js'></script> 
     <script> 
      //After 5000 milliseconds = 5 seconds, redirect. 
      //for 1 hour use: 1000 * 60 * 60 
      //    1 sec * 60 sec/min * 60 min/hour 
      setTimeout(
       function() { 
        window.location.href = "index2.php" 
       }, 5000 
      ); 
     </script> 
    </body> 
</html> 

创建 “index2.php” 与下面的代码:1000 * 60 * 60,在代码

创建 “的index.php” 与下面的代码说明:

<?php 
    session_start() ; 
?> 
<html> 
    <head> 

    </head> 
    <body> 
     <h2>Index 1</h2> 


     <script src='https://code.jquery.com/jquery-2.1.4.min.js'></script> 
     <script> 
      //After 5000 milliseconds = 5 seconds, redirect. 
      //for 1 hour use: 1000 * 60 * 60 
      //    1 sec * 60 sec/min * 60 min/hour 
      setTimeout(
       function() { 
        window.location.href = "index.php" 
       }, 5000 
      ); 
     </script> 
    </body> 
</html> 

更新代码,丢弃上面的代码:

<?php 
    session_start() ; 

    $redirectsArr = array(//Pages to visit, by order 
     "http://google.com", 
     "http://youtube.com" 
    ) ; 

    //If session not set, redirect immediatly. First time only 
    if (!isset($_SESSION["redirectedNdx"])) { 
     $_SESSION["redirectedNdx"] = 0 ; 
     header("Location: " . $redirectsArr[$_SESSION["redirectedNdx"]]) ; 
    } 
    else { //Set the index of the page to visit in the above array 
     if ($_SESSION["redirectedNdx"] == 0) { 
      $_SESSION["redirectedNdx"] = 1 ; 
     } 
     else { 
      $_SESSION["redirectedNdx"] = 0 ; 
     } 
    } 
?> 
<html> 
    <head> 

    </head> 
    <body> 
     <h2>Soon... redirecting to: <?php echo $redirectsArr[$_SESSION["redirectedNdx"]] ?></h2> 

     <script src='https://code.jquery.com/jquery-2.1.4.min.js'></script> 
     <script> 
      //After 5000 milliseconds = 5 seconds, redirect. 
      //for 1 hour use: 1000 * 60 * 60 
      //    1 sec * 60 sec/min * 60 min/hour 
      setTimeout(
       function() { 
        window.location.href = "<?php echo $redirectsArr[$_SESSION["redirectedNdx"]] ?>" 
       }, 5000 
      ); 
     </script> 
    </body> 
</html> 
+0

我更新了我的文章。请再次检查。 –

+0

检查更新的代码! –

+0

你的代码是好的,但我需要更多的提示。我更新了它。核实。 –