Jump to content

Unexpected End Of File


6edie8

Recommended Posts

I have a chunk of code that I intend to use for comments on a website. I'm working on this in XAMPP so I don't have a website to show you the issue live. I've split the code into 3 parts. The 1st part is the beginning of the script and is in a separate file included on the page in question. The 2nd part is the part that will be on every page that simply needs a file name changed for each different page. The 3rd part is the end of the script and is in a separate file and included on the page in question. So, include "code1.txt" - middle part - include "code2.txt". The error I get says "unexpected end of file" on code1. I'd say I'm moderately experienced with PHP and have tried everything in my arsenal to fix this but alas, I cannot. I hope this is clear. Thank you!

 

Code1


<?php
$errname = $errcomm = "";
$name = $comment = "";
$date = date("F jS Y - g:i");
if (isset($_POST["submit"])) {
$name = $_POST["name"];
$website = $_POST["website"];
$comment = stripslashes(nl2br($_POST["comment"]));
if (!empty($_POST["website"])) { $name = "<a href=\"$website\" target=\"_blank\">$name</a>"; } else { $name = $name; }
if(!empty($_POST["spam"])) { die("<p><strong>Fuck you, bot!</strong></p>"); } else {}
if (empty($_POST["name"])) { $errname = " error"; } 
elseif (empty($_POST["comment"])) { $errcomm = " error"; } else {

 

Middle




<?php include "code1.txt"; ?>
$file = file("comments/001.txt"); 
$foo = fopen("comments/001.txt", "w+");
fwrite ($fopen, "<div class=\"comment\">\n<strong>$name ➜ $date</strong><br/>\n$comment\n</div>\n\n");
foreach ($file as $new) { fwrite($foo, "$new"); } 
fclose ($foo);
header ("Location:http://localhost/mine/rh/001.php");
<?php include "code2.txt"; ?>


 

Code2



}
}
?>


Edited by 6edie8
Link to comment
Share on other sites

You fundamentally misunderstand how script inclusion works. The included code isn't somehow copied into the main script. It's parsed like any other script, which means it must be syntactically valid. You cannot start a statement in one file and end it in another file.

 

Those inclusion gymnastics are bad anyway. If you want to reuse code, use a proper function.

 

Also get rid of ancient stuff like stripslashes(). The last time this made any sense at all was in the 90s when "Magic Quotes" still existed. That was ~20 years ago.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.