0

I am working on a program that creates a lease. The user enters data such as tenant name, address, etc into a form. This form is located on a page named leaseCreation.php. When the form is submitted, the form action is another page named leaseProcessing.php. This page stores the form values in a MySQL database and creates a Word document based on the values. (lease).

Everything was working as intended, but I wanted to use a redirect on leaseProcessing.php to avoid the user refreshing the page and submitting the form data a second time. So, I created another page named leaseProcessed.php and added the following redirect at the bottom of leaseProcessing.php where $outputFilename is the name of the word document.

header("Location: leaseProcessed.php?outputfile=".$outputFilename); 

Here is the code from leaseProcessed.php

<?php
session_start();

if(!isset($_SESSION['auth']) || $_SESSION['auth'] != "1"){   
header( 'Location: login.php' ) ;
}

if(!isset($_GET)){
    header( 'Location: leaseCreation.php' ) ;
}else{
    $outputFileName = $_GET['outputfile'];
}
?>

<html>
<head>
<title>Lease Processed</title>
<link rel="stylesheet" type="text/css" href="style\style.css">
</head>
<body>

<?php echo('<a href="'.$outputFileName.'">Download your lease here.</a>');
header("Location: ".$outputFileName);
?>

</body>
</html>

PROBLEM: When the user submits the form on leaseCreation.php, the url never changes. It remains leaseCreation.php and I continue to see the form on leaseCreation.php even though the code on leaseProcessing.php is executing (Mysql database is updated and word file is created), and the Word file is opening. I am unsure why the browser url has not updated to leaseProcessed.php? Clearly code from that page is being executed.

Thanks in advance for any insight!

-Brent

Suman Singh
  • 1,379
  • 12
  • 20
Brent
  • 171
  • 1
  • 2
  • 10
  • 4
    You shouldn't change headers after outputting HTML. – Phiter Dec 19 '16 at 01:32
  • why you have the other redirect at the bottom – meda Dec 19 '16 at 01:34
  • I previously had the redirect inside the if/else at the top of the page and it responded the same way. I was hoping by placing it at the bottom of the page the html would execute. That didn't happen for some reason. – Brent Dec 19 '16 at 01:35
  • 1
    seems you're creating an endless loop *and* outputting before header at the same time. Error reporting's your friend here. Should also add exit after each header – Funk Forty Niner Dec 19 '16 at 01:37
  • 1
    If you had error reporting turned on you would have figured this out quickly – John Conde Dec 19 '16 at 01:39
  • @Fred-ii- Where is the endless loop? I have a form that submits to a page that processes the data. At the end of that page, I have a redirect to a third page that only serves the purpose of preventing the user from refreshing the form data. – Brent Dec 19 '16 at 01:40
  • soon as you click on that hyperlink – Funk Forty Niner Dec 19 '16 at 01:41
  • @JohnConde - I'm very new and still a student. I am using Netbeans. It gives me an error if the syntax is incorrect. Is there another error reporting I should have turned on? – Brent Dec 19 '16 at 01:41
  • http://php.net/manual/en/function.error-reporting.php that will tell you what's going on or not. set it to catch and display and you'll see. – Funk Forty Niner Dec 19 '16 at 01:43
  • @Fred-ii- The hyperlink links to the word file. I have removed the hyperlink and still have the same problem. I am not trying to be disagreeable, really trying to understand how to fix the problem and more importantly how to diagnose similar problems in the future. – Brent Dec 19 '16 at 01:43
  • @Fred-ii- Thank you for that link. I am sure it will be very helpful. Thanks again. – Brent Dec 19 '16 at 01:44
  • @Brent When you have an answer that resolves your question please accept it. e.g. http://stackoverflow.com/questions/40988220/php-editing-a-file-in-zip-archive-and-saving-as-another-archive-name-before-cl that answer should be accepted. It seems none of your questions have accepted answers. See http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – chris85 Dec 19 '16 at 01:49
  • @chris85 - Thank you for pointing that out. I thought by up voting, I was accepting the answer. Thanks for clearing that up. – Brent Dec 19 '16 at 01:54
  • @Fred-ii- I have no errors reported. Also, mine is not an issue of using the redirect after output as suggested above. I moved my redirect inside the if/else at the top of the page and have the same issue. Interestingly enough, my issue seems to be directly related to redirecting to the word file. When I replace the redirect to any other .php or .html file located on my server, everything works as expected. Does it make sense this could be an issue only when redirecting to a .docx file? – Brent Dec 19 '16 at 01:57

0 Answers0