我已经使用链接http://devlup.com/programming/php/create-url-shortener-php/853/创建了 url shortner ,为此我使用的是 EasyPhp5.3.6.0,但我没有找到所需的输出,这意味着在单击缩短的 url 后它不会重定向到原始页面。可能我认为问题出在数据库端这是我在数据库端执行的步骤,请让我知道有什么问题
首先,我转到配置-> PhpMyAdmin 链接,然后我在这里创建了名为“leaf”的数据库,我没有选择名为“Collation”的下拉列表,我将表名设为“团队”,字段数为“3”,然后我修改了如图所示的字段以下
**Field id url shortened**
Type INT VARCHAR VARCHAR
Lenght/Values 255 10000 10000
Default None None None
然后我将“id”设为主键
这些是 php 代码的一部分,其中数据库处理在 sortner.php 中进行
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("leaf", $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 team values('$id','$urlinput','$shorturl')";
mysql_query($sql,$con);
echo "Shortened url is <a href=\"http://projects.devlup.com/url/". $shorturl ."\">http://devlup.com/". $shorturl ."</a>";
mysql_close($con);
?>
在decoder.php中
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("leaf", $con); //Replace with your MySQL DB Name
$de= mysql_real_escape_string($_GET["decode"]);
$sql = 'select * from team where shortened="$de"';
$result=mysql_query("select * from team where shortened='$de'");
while($row = mysql_fetch_array($result))
{
$res=$row['url'];
header("location:$res");
}
请让我知道这里有什么问题,我的所有文件都在根文件夹(www)下,这意味着 C:\Program Files\EasyPHP-5.3.6.0\www\test