I figured a code snippet would be required. Rather than post all 232 lines of code, I'll try and give the relevant information below:
An example URL would be http://javelin.altervista.org/article.php?id=43, where 'id' refers to the line number of a file.
This works for links and manual entry, as the contents of the file are correctly retrieved and displayed when not submitting the form. The form action uses $_SERVER['REQUEST_URI'] so that the same php page (and URL) are used for processing. This is the point where things stop working.
	Code:
	<?php
require("incl/session.php");
require("incl/functions.php");
if (is_numeric(_INPUT('id'))) { // Validate id
   $line = _INPUT('id');
} else {
   $line = 0;
}
$count=1;
$total = countLines("articles");
$articles = fopen("articles", "r");
if ($articles) { // Check if variable exists before continuing
   if ($line > 0 && $line <= $total) { // Ensure $line is valid
[Display file contents, validate form data, do whatever else here]
   } else { // If $line is invalid, display '404 Not Found' error
      header("HTTP/1.1 404 Not Found");
      include("err/404.php");
      exit;
   }
}
fclose($articles);
 The session.php file contains the following:
	Code:
	   session_start();
   $_SESSION['URL'] = $_SERVER['REQUEST_URI'];
 functions.php contains various functions used, of which the following is relevant:
	Code:
	function _INPUT($field) {
   if ($_SERVER['REQUEST_METHOD'] == 'GET') {
      return strip_tags($_GET[$field]);
   }
   if ($_SERVER['REQUEST_METHOD'] == 'POST') {
      return strip_tags($_POST[$field]);
   }
}
 As you can see, I display a 404 error page if 'id' is invalid. It is the 404 error I am receiving each time I submit the form on this page, despite the URL being correct and including the query string.