need help regarding little php code error, any php expert here?

Status
Not open for further replies.

SpiderZq

Active Member
382
2009
10
0
PHP:
<div align="center">
Enter your long URL here:<br/>
<form action="adf.php" method="post">
<input type="text" value="http://" name="turl" id="turl">
<input type="submit" name="submit" value="MakeShort!">
</form>
</div>
<?php
if(isset($_POST['submit']))
{
function makeShort()
{
$turl=urlencode($_POST["turl"]);
$uid="ADF.LY UID";
$key="ADF.LY KEY";
$advert_type="int";
$url="http://api.adf.ly/api.php?key=".$key."&uid=".$uid."&advert_type=".$advert_type."&url=".$turl."";

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 1); 
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1); 
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($ch, CURLOPT_URL, $url);
$content = curl_exec($ch);
curl_close($ch);
return $content;
}
?>
<?php
echo"<div align='center'>Thank you for using this service</div><br/>";
$surl = makeShort();
echo"<div align='center'>Your short URL is:<br/>";
echo"<strong><a href='$surl'>$surl</a></strong>";
?>

when i try to use this on hosting, this error message comes up. how can i solve this issue?
"Parse error: syntax error, unexpected $end in /home/a657xxxx/public_html/index.php on line 35"
 
11 comments
PHP:
 <div align="center">
Enter your long URL here:<br/>
<form action="adf.php" method="post">
<input type="text" value="http://" name="turl" id="turl">
<input type="submit" name="submit" value="MakeShort!">
</form>
</div>
<?php
if(isset($_POST['submit']))
{
function makeShort()
{
$turl=urlencode($_POST["turl"]);
$uid="ADF.LY UID";
$key="ADF.LY KEY";
$advert_type="int";
$url="http://api.adf.ly/api.php?key=".$key."&uid=".$uid."&advert_type=".$advert_type."&url=".$turl."";

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 1); 
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1); 
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($ch, CURLOPT_URL, $url);
$content = curl_exec($ch);
curl_close($ch);
return $content;
}

echo"<div align='center'>Thank you for using this service</div><br/>";
$surl = makeShort();
echo"<div align='center'>Your short URL is:<br/>";
echo"<strong><a href='$surl'>$surl</a></strong>";
?>


Try That.
 
@itz.animal: error msg changed to
Parse error: syntax error, unexpected $end in /home/a6575072/public_html/index.php on line 34

:p
 
PHP:
<div align="center">
Enter your long URL here:<br/>
<form action="adf.php" method="post">
<input type="text" value="http://" name="turl" id="turl">
<input type="submit" name="submit" value="MakeShort!">
</form>
</div>
<?php
if(isset($_POST['submit']))
{
    function makeShort()
    {
        $turl = urlencode($_POST["turl"]);
        $uid  = "ADF.LY UID";
        $key  = "ADF.LY KEY";
        $advert_type = "int";
        $url = "http://api.adf.ly/api.php?key=".$key."&uid=".$uid."&advert_type=".$advert_type."&url=".$turl."";

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 1); 
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1); 
        curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
        curl_setopt($ch, CURLOPT_URL, $url);
        $content = curl_exec($ch);
        curl_close($ch);
        return $content;
    }

    echo "<div align='center'>Thank you for using this service</div><br/>";
    $surl = makeShort();
    echo "<div align='center'>Your short URL is:<br/>";
    echo "<strong><a href='$surl'>$surl</a></strong>";
}
?>

You really need to re-think that code, could be much better.
 
Edited my post, you shouldn't get the "undefined function" error now. But I still say you should reconsider your code structure, you can improve that code.
 
Status
Not open for further replies.
Back
Top