Fehler in PHP Datei

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Fehler in PHP Datei

    Hallo,

    ich bin gerade dran mir einen URL Shortener zu erstellen. Dazu habe ich die Dateien von GitHub genommen. Hier das Tutorial: PHP Master | Building Your Own URL Shortener

    Nun ist es so, dass in einer Datei ein Fehler ist. Nur ich finde nicht heraus wo. Hoffentlich könnt ihr mir helfen.

    Hier ist die Fehlermeldung, wenn ich die Seite öffne oder eine URL Kürzen möchte:
    Parse error: syntax error, unexpected end of file in /users/shrtml/www/public/submit.php on line 34

    Hier ist meine PHP Datei:

    PHP Quellcode:
    PHP 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_USERNAMEDB_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;

  • #2
    Der Parser erwartet offenbar nach ENDHTML; einen Zeilenumbruch, dann gehts.

    Die PHP-Doku dazu:
    It's also important to realize that the first character before the closing identifier must be a newline as defined by the local operating system. This is \n on UNIX systems, including Mac OS X. The closing delimiter must also be followed by a newline.
    http://php.net/manual/en/language.ty...syntax.heredoc

    Es ist übrigens generell empfehlenswert Code-Dateien mit einem Zeilenumbruch abzuschließen.
    Last edited by h3ll; 24-01-2016, 11:31.

    Comment


    • #3
      Originally posted by h3ll View Post
      Der Parser erwartet offenbar nach ENDHTML; einen Zeilenumbruch, dann gehts.

      Die PHP-Doku dazu:PHP: Strings - Manual

      Es ist übrigens generell empfehlenswert Code-Dateien mit einem Zeilenumbruch abzuschließen.
      Wie mache ich das? Wenn ich in eine neue Zeile geh, und dort ?> Kommt auf dem Webserver nurnoch 404

      Comment


      • #4
        Originally posted by log View Post
        Wie mache ich das? Wenn ich in eine neue Zeile geh, und dort ?> Kommt auf dem Webserver nurnoch 404
        Das ist dann aber ein anderes Problem. Dann solltest du dir mal die HTTP-Requests und HTTP-Responses im Browser anschauen. Wahrscheinlich zeigt da eine Weiterleitung ins Nirgendwo.

        Comment


        • #5
          Originally posted by h3ll View Post
          Das ist dann aber ein anderes Problem. Dann solltest du dir mal die HTTP-Requests und HTTP-Responses im Browser anschauen. Wahrscheinlich zeigt da eine Weiterleitung ins Nirgendwo.
          Sooo.
          Ich habe mir nochmal die Datei aus GitHub genommen. Jetzt kommt wieder der Fehler.

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


          Könntest du mir denn sagen, wo ich was einfügen soll?

          Comment


          • #6
            Originally posted by h3ll View Post
            Das ist dann aber ein anderes Problem. Dann solltest du dir mal die HTTP-Requests und HTTP-Responses im Browser anschauen. Wahrscheinlich zeigt da eine Weiterleitung ins Nirgendwo.
            Das wäre nett!

            Comment


            • #7
              Ich hab dir doch schon gesagt, nach ENDHTML; gehört ein Zeilenumbruch. Wenn sonst noch Fehler im Script vorkommen, wende dich an den Hersteller.

              Außerdem Crosspost:

              http://phpforum.de/forum/showthread.php?t=282748
              Last edited by h3ll; 24-01-2016, 19:23.

              Comment

              Working...
              X