解析错误:语法错误,第18行的/path/to/the/website/file.php中的意外“{”

时间:2017-03-18 22:48:30

标签: php

问题说意外{.....我不明白为什么这是hapenning我删除它,我仍然有问题。请回复正确的代码。

Kevin Andrews / Auth

<?php

$shortenedlink = mt_rand(10000,99999);
$longlink = $_POST['longlink'];
if(!isset($longlink) || trim($longlink) == '')
{
   echo "The link field is empty. Redirecting you in 3 seconds.";
   header ( "refresh:3;url=http://auth.kenygamer.com" );
   exit;

$shortenedlinkpath = "$shortenedlink.asp";
if (file_exists($shortenedlinkpath))
{
    echo "An error occurred creating the shortened link, because the assigned number already exists. However, you can retry. Copy the link and paste it again on the main page:<br><br>$longlink<br><br>Redirecting you in 15 seconds.";
    header( "refresh:15;url=http://auth.kenygamer.com" );
    exit;

}
else
{
    echo "";
}

$shortenedfilecontent = '<title>Outgoing link</title><meta http-equiv="refresh" content="5; url=$longlink">';
$fp = fopen("$shortenedlink.asp", "w"); 
fwrite($fp, $shortenedfilecontent).'&nbsp;'; 
fclose($fp);

echo ("The shortened URL has been successfully created. The shortened number #$shortenedlink has been assigned to your long URL $longlink. Therefore, it is accessible at https://auth.kenygamer.com/$shortenedlink at any time. Remember that you can always create new shortened URLs.<br><br>Long link: $longlink<br>Shortened link: $shortenedlink<br><br>Redirecting you in 20 seconds.");
header( "refresh:20;url=https://auth.kenygamer.com/$shortenedlink" );
?>

1 个答案:

答案 0 :(得分:1)

您忘了在exit;

之后添加}

这可以帮到你:

<?php

$shortenedlink = mt_rand(10000, 99999);
$longlink = $_POST['longlink'];
if (!isset($longlink) || trim($longlink) == '') {
    echo "The link field is empty. Redirecting you in 3 seconds.";
    header("refresh:3;url=http://auth.kenygamer.com");
    exit;
}

$shortenedlinkpath = "$shortenedlink.asp";
if (file_exists($shortenedlinkpath)) {
    echo "An error occurred creating the shortened link, because the assigned number already exists. However, you can retry. Copy the link and paste it again on the main page:<br><br>$longlink<br><br>Redirecting you in 15 seconds.";
    header("refresh:15;url=http://auth.kenygamer.com");
    exit;
} else {
    echo "";
}

$shortenedfilecontent = '<title>Outgoing link</title><meta http-equiv="refresh" content="5; url=$longlink">';
$fp = fopen("$shortenedlink.asp", "w");
fwrite($fp, $shortenedfilecontent) . '&nbsp;';
fclose($fp);

echo ("The shortened URL has been successfully created. The shortened number #$shortenedlink has been assigned to your long URL $longlink. Therefore, it is accessible at https://auth.kenygamer.com/$shortenedlink at any time. Remember that you can always create new shortened URLs.<br><br>Long link: $longlink<br>Shortened link: $shortenedlink<br><br>Redirecting you in 20 seconds.");
header("refresh:20;url=https://auth.kenygamer.com/$shortenedlink");
?>
相关问题