-2

I'd like to create an URL Shortener.

I have all files on my Webserver but now, when I'd like to short an url it says me:

Parse error: syntax error, unexpected end of file in /users/shrtml/www/public/submit.php on line 36

What is this? Here is my CODE:

<?php
require_once "../include/config.php";
require_once "../include/ShortUrl.php";
if ($_SERVER["REQUEST_METHOD"] != "POST" || empty($_POST["url"])) {
    header("Location: shorten.html");
    exit;
} 
try {
    $pdo = new PDO(DB_PDODRIVER . ":host=" . DB_HOST . ";dbname=" . DB_DATABASE,
        DB_USERNAME, DB_PASSWORD);
}
catch (\PDOException $e) {
    header("Location: error.html");
    exit;
}
$shortUrl = new ShortUrl($pdo);
try {
    $code = $shortUrl->urlToShortCode($_POST["url"]);
}
catch (\Exception $e) {
    header("Location: error.html");
    exit;
}
$url = SHORTURL_PREFIX . $code;
echo <<<ENDHTML
<html>
 <head>
  <title>URL Shortener</title>
 </head>
 <body>
  <p><strong>Short URL:</strong> <a href="$url">$url</a></p>
 </body>
</html>
ENDHTML; <<< This is line 34. End of file.  
Martin
  • 22,212
  • 11
  • 70
  • 132

1 Answers1

0

You look upset from GolezTrol answer, but he wants from you to be more specific about your problem and tries to push you to make some research yourself before posting question. Not needed to be upset.

Your problem is, that you have to put extra line after ENDHTML; line, because is is the last line of echo block, and PHP does not see proper end of file. Or put PHP end tag ?> on new line after ENDHTML;

Jan Rydrych
  • 2,188
  • 2
  • 13
  • 18
  • Now I can't use it. My Hoster now says 404 | The PHP Checker says no Issues found. Have you an Idea? Here is the Tutorial: http://www.sitepoint.com/building-your-own-url-shortener/ – logtainment Jan 24 '16 at 11:30
  • 404 is not found error - are you sure that you are typing correct URL (it may be lower/upper case issue)? – Jan Rydrych Jan 24 '16 at 11:37
  • Yes, now I have the original File from the GitHub Reposority. And if I add an ?> in line 35. My hoster says 404 not found. You can Test it yourself. shrt.ml – logtainment Jan 24 '16 at 12:14
  • The Link is http://shrt.ml/ @ – logtainment Jan 24 '16 at 13:14
  • You posted bad shrt.mll URL, please update it. BTW - error 404 doesn't mean that you have error in your script, but the url is wrong for the file you requested, s I guess thet you have problem with configuration or file placement... – Jan Rydrych Jan 24 '16 at 14:28