Using "nl2br" PHP command, but still sometimes a space (where shouldn't be) at end of output to browser...

Hi experts, this is related to a question I had and was answered last month or so:

http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/Q_28687222.html

All seemed well after I was given that solution... my PHP script's output back to the browser was nice and clean, with no CR/LF's in the output. That was when I was doing development/testing of my PHP script locally on my VPS using EasyPHP. Now that I have a live domain pointing to my work, a test using my local computer shows that there is a trailing space at the very end of the output to the browser. Please try it live here:

www.optimaloption.net

For 'Name", just put TESTNAME. For "User Data", put this:

27539CE60BC6A6C0B5E10324F73BBF5BDD2A791E0E0A4D9502DA620035483B80

Then click on "Generate". Copy and paste the long code that is displayed, from the starting "=" sign right to the end of the file. Then paste that into Notepad and then CTRL-A highlight all of that. if you were using Firefox, you'll see that there's an extra space at the very very end of that long code. Doesn't seem like much, but that will be enough to throw my users off. if you try all this with Google Chrome hoever, you'll see that there's no trailing space at the very end (which is what I want).
   In my PHP script I'm using the "nl2br" to output this code from a generated file, to the browser. is there any way in PHP to check if there is this final trailing space at the end of my output and if so, delete it... before doing the output to the browser?

Thanks!
    Shawn
shawn857Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

shawn857Author Commented:
Quick update to this: it appears going "live" and running this script from a live domain did not in fact, have anything to do with the trailing space being added to the end of the output... my mistake sorry. All my local testing on my VPS with EasyPHP was with Google Chrome, giving me the illusion that everything was working fine. I just installed Firefox on my VPS and tried a local test using that, and it has that trailing space at the end.
   So it seems that only Google Chrome gives me the browser output I want, while Firefox and IE don't behave. Can I account for this somehow in my PHP script and combat it?

Thanks
   Shawn
0
Ray PaseurCommented:
Have you tried using trim() ?
http://php.net/manual/en/function.trim.php
0
shawn857Author Commented:
Well, here's the thing Ray - my PHP script first writes it's output to a disk file, then my PHP script reads the disk file and outputs that to the browser. My PHP code is:

  if (file_exists($fname))
  {
    echo nl2br(file_get_contents($fname));  
  }

The contents of the disk file are clean - in other words, no trailing space at the end of it. So it has to be one of, or a combination of the nl2br command, the "file_get_contents" command, and the browser type, that is producing this extraneous space at the end (when using Firefox or IE).
   How can I fit the "trim" command into all this? (I am very much a newbie at PHP).

Thanks
    Shawn
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Dave BaldwinFixer of ProblemsCommented:
If there is a \r\n at the end of the file, 'nl2br' will add a <br> to it.  If you use 'trim' first, it will eliminate an \r\n at the end which will make it appear like another line is there.

if (file_exists($fname))
  {
    echo nl2br(trim(file_get_contents($fname)));  
  }

Open in new window

0
shawn857Author Commented:
Thank you Dave, I added the TRIM in there but I'm afraid it didn't help. You can try it live again now and see. The extra space (...after copying/pasting the code into Notepad) still occurs with Firefox/IE, but for some reason, everything's fine with Chrome. Gotta be a browser thing eh?

Thanks
    Shawn
0
Dave BaldwinFixer of ProblemsCommented:
No, I don't think so.  I copied the text shown in the image below from Firefox and there was not an extra space showing in Notepad, PSPad, or Notepad++.
extrak key display
0
shawn857Author Commented:
Dave, you gotta copy the whole text - equals signs included. The trailing space lies right after the final equals sign on the last line.

Thanks
    Shawn
0
Dave BaldwinFixer of ProblemsCommented:
Still don't see it.  You can see in the first image that the cursor is right at the last '=' sign.
reg keyscreen shot
0
Dave BaldwinFixer of ProblemsCommented:
Now I'm not getting a response from http://www.optimaloption.net/ in any browser.
0
shawn857Author Commented:
Dave, did you paste the code into Notepad and then ctrl-A to hilite everything? That's where you'll see it.
0
Dave BaldwinFixer of ProblemsCommented:
No, I don't see it that way or any other way so far.
extrak in notepad
0
Dave BaldwinFixer of ProblemsCommented:
So I had a thought.  I have been highlighting exactly to the end of your text and not seeing an extra space.  I decided to highlight from the first '=' sign to the bottom of the page.  Then I get an extra space in IE8 and Firefox.  

That says it has nothing to do with your code.  And that your code where this is used is going to have cope with that extra space because there is nothing you can do to prevent your users from including that extra space.
0
Ray PaseurCommented:
If you're new to PHP and want some good learning resources, this article can help.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html

If you want to know what is present in a data element, this function is your friend:
http://php.net/manual/en/function.var-dump.php

If var_dump() does not show extraneous white space, it's not part of the string.
0
Julian HansenCommented:
This might have nothing to do with the file.

Consider the following
<?php
echo "something"
?>
<== Space here

Open in new window


In some cases that extra space at the end of the file will come through to your output.
Two options
1. Check there is no white space after your closing ?>
2. Remove the ?> altogether - if there is nothing but script in the file the closing ?> is not needed and no additional spaces will be sent to the browser. In other words the above becomes
<?php
echo "something"

Open in new window

0
shawn857Author Commented:
Thanks guys.

Dave - yes, I guess I should have said to copy "past" the end of the code all the way down to the end of the page. OK, so you saw the same thing I did then for Firefox and IE. That final space at then end of the code could cause havoc when a user includes that in the code to try and activate my software... I'm pretty sure it will bugger things up.

Julian - I checked my PHP script and there WAS an extra space at the end of this line:

echo nl2br(trim(file_get_contents($fname)));

So I fixed it and got all excited and figured that was the problem... but I'm afraid it made no difference.

I think I'm going to have to go the route of popping up a window to tell the user to open/save a file containing the activation code.... instead of trying to output it to the browser. Julian, in a previous question of mine regarding this a few weeks ago:

http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/Q_28687222.html

... you had suggested some PHP code to do just this. Namely:

<?php
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename('test.txt'));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize('test.txt'));
readfile('test.txt');
?>

Open in new window


However, that also echoes all the HTML code of my PHP script in the "test.txt" file... as well as my desired activation code.

Googling around this topic, I found another example that used this seemingly simpler PHP code:

$string = 'a string';
header('Content-type: text/plain');
header('Content-Disposition: attachment; filename="file.txt"');
echo $string;

Open in new window


However that gave the same result - it includes all my PHP script's HTML code in the file as well. if I could get this way working right, this would be the best and most robust solution for me. Any ideas guys?

Thanks!
   Shawn
0
Dave BaldwinFixer of ProblemsCommented:
I think you should accommodate the extra space at the end in your software and make it work with or without it.
0
shawn857Author Commented:
Well Dave, it's not really something I can fix - the user is going to copy and paste the big long activation code and plop it inside a 3rd party security module I employ in my software. If the big code has an extra space that it's not expecting at the end of it... then the software does not activate for the user.... and I wind up having to put fires out left and right. That defeats the whole purpose of my little "self-serve" PHP script which allows my users to generate and get their activation code without my intervention.
   If I can use Julian's "header" method successfully to pop-up an OPEN/SAVE window to the user, I think this will be the most robust way. Now I just need to get that method working right so it doesn't also include all my script's HTML code in the output file.

Thanks
    Shawn
0
Julian HansenCommented:
After looking at the output from your script
====== REGISTRATION KEY ======<br />
gcxMpKrDYH02S19fab/N7FvJcA1B2i<br />
9Se5UKVKatpr+LdfnvjA9QbP3KnO7M<br />
p7Q3A/PDxzjBAA9bD4N1N0BwYf7W9W<br />
WIHKaqOs0D9uMXDxLdY9XVmCuIvnJv<br />
qbleBs6kU/ytvkMVv+Cet3wAkLveFQ<br />
1oSxX6VGh1qI4Mav/uzEEHOmaRwlFd<br />
TtXZLZjw4dXoLogngkZJOWwkiWZVK8<br />
nxSf+wU9vh8Boj8i7dxSesMwf345/Z<br />
VjlWG+a0AGy5wtdj4BxCORn3djw9St<br />
XekrQHFdQJfPez+LId91k2Bs+mcxRi<br />
UGQsjXjpo/VXDvuQTicqN/T0PixTpL<br />
HH4FKRd72w23KXhZADJ7/f<br />
====== DO NOT ALTER KEY ======
</center></body>

Open in new window

The problem appears to be that the </center> is on its own line. I saved the generated page to a file and changed the second last line to
====== DO NOT ALTER KEY ======</center></body>

Open in new window

And cut and paste - problem seems to have gone away.

The solution would then appear to be how to get the line starting with </center> onto the same line as the closing DO NOT ALTER KEY.

Having said that - is there a reason you are not simply outputing this in <pre></pre> tags and ignoring the <br/> thing altogether?
0
shawn857Author Commented:
Thanks for the reply Julian, well for one thing, I don't know what <pre> tags do! Also I don't have control of the line-by-line creation of the big activation code - this is done by a 3rd part EXE file that I call from within my script. Basically in my script, I build a parameter string and then call the EXE file:

  shell_exec($runcmd);
  
  if (file_exists($fname)) 
  {
    echo nl2br(trim(file_get_contents($fname)));
    unlink($fname);
  }
  else
  {
    echo "Invalid USER DATA code!";
  }
}
?>

</center></body>
</html>

Open in new window


The EXE code-generating program then creates the filename $fname which I simply want to output to the browser. That's where the "extra space" problem crops up with Firefox and IE. So you think that </center> tag at the end of my script might be the culprit? What if I just got rid of it altogether?

Alternatively, can we try your suggestion of prompting the user to open/save the file? I just need to figure out how to NOT have the HTML code included in that file.

Thanks
   Shawn
0
shawn857Author Commented:
Julian, just tried getting rid of the </center> tag at the end of my script altogether and it made no difference for Firefox/IE - the space is still at the end of my activation code.

Shawn
0
Julian HansenCommented:
It is not the <center> tag itself - it is whatever comes after the final ====

Whatever follows needs to be immediately after it. So if you  removed <center> then <body> comes after it. FF is seeing that CR as a white space char - which is coming through in the cut and paste.
What do the last 5 lines of your output script look like?

Have you tried removing the <br> and enclosing the entire string in <pre> tags?
0
shawn857Author Commented:
Here is my FULL script Julian:

<?php
require_once "config.php";
?>

<html>
<head>
<title>Generate extrak DEMO activation code</title><link rel="stylesheet" href="style.css">
</head>
<body><center>
<img src="extraklogo.png" border="0" ><br>
<table class="form" cellspacing="1" cellpadding="1">
<tr><td class="title" colspan="2"><center><font face="arial"><b>Generate extrak DEMO activation code</b></center></td></tr>
<form method="POST" action="">
<tr><td class="title"><span class="small">Name</span></td><td class="title"><input type="text" name="n" size="70" class="text"></td></tr>
<tr><td class="title"><span class="small">User Data</span></td><td class="title"><input type="text" name="u" size="70" class="text"></td></tr>
<tr><td class="background" colspan="2" align="center"><input type="submit" value="Generate"></td></tr></font>
</form>
</table>
<br>


<?php
if ($_POST) 
{
  $n = $_POST['n'];
  $u = $_POST['u'];
  
  if (strlen($n) < 8) 
  {
    echo 'NAME field must be at least 8 characters long!';
    return;
  }
  
  if (empty($u)) 
  {
    echo 'USER DATA field must not be empty!';
    return;
  }

  $progname = "CodeLockKeygenCMD.exe ";
  $programcode = $p;
  $userdata = $u;
  $nameofuser = $n;
  $nameofuserstripped = preg_replace('/\s+/', '', $nameofuser);
  $fname = "regcode" . $nameofuserstripped . ".txt";
  $sixtydays = "1";
  $runcmd = $progname . '"' . $programcode . '|' . $userdata . '|' . $nameofuser . '|' . $fname . '|' . $sixtydays . '"'; 

  shell_exec($runcmd);
  
  if (file_exists($fname)) 
  {
    echo nl2br(trim(file_get_contents($fname)));
    unlink($fname);
  }
  else
  {
    echo "Invalid USER DATA code!";
  }
}
?>
</body>
</html>

Open in new window


I create a filename $fname, based on what the user types in to the "Name" field in my input form. I then feed this $fname to the code-generating EXE and it creates a file by that name containing the activation code. Then i just try to echo that file to the browser. I needed to use the "echo nl2br" statement to output it, as otherwise it was putting only a LineFeed after each line in the output file and not a proper CR/LF. I believe it was Dave Baldwin who helped me with that. Anyway, the contents of the created activation code file are clean, I can attest to that. Here's the contents of a created activation code file on disk as created by this script:

Name: myname 44
Registration Code:
(copy & paste the whole block)

====== REGISTRATION KEY ======
73srA6UOlHZqDB6wOZPYuNwqOG2YlP
mwvSvMWSROHxIA3Lee9pm3J5IB3lN9
WIMsZibyRmQS3wAIMtlXKyiEmeesuG
DI7xiII+JGRYUwE5cQNeqZfzW7wAhg
65WxHCbRhC9UvX4t7Lk4PbUoiycBKa
Ud06WbC0HDRKUSeatmy3TyfrcMPix8
gGmWsGqnwthFzlnAOAQ9VXeLLDUpdM
4/c+m4hMuK1VcYxZs07U/MfZzwspuk
TI4wOpfQKSq8WoRldOK48M+v/B8sxk
FX0H/2U8tlvs90KylepoGs92PEf5je
pEXgJO6du5cMAgzFKrpGPC+WMbZjlL
HTgoDAg0uO6ZxsiisP3aeP
====== DO NOT ALTER KEY ======

Open in new window



... no extraneous stuff at the end of each line, nor at the end of the file. Clean as a whistle. It's echoing this file to Firefox/IE that is the problem.
   So now it's the HTML <body> tag in my script that could be the problem?

Thanks
   Shawn
0
Julian HansenCommented:
To answer your earlier comment <pre> tags are HTML tags that tell the browser to output the text exactly as it is formatted in the HTML file - it removes the need to use the nl2br function call - you can take the output from your shell script and dump it between the <pre></pre> tags and it should work.

Two potential solutions

Option #1 - change the script so that the <center> tag is on the same line as the closing ?> - see below.
  shell_exec($runcmd);
  
  if (file_exists($fname)) 
  {
    echo nl2br(trim(file_get_contents($fname)));
    unlink($fname);
  }
  else
  {
    echo "Invalid USER DATA code!";
  }
}?></center></body></html>

Open in new window


The second option is to use the <pre> tags - but try this first.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
shawn857Author Commented:
OK, I'll try them both... can you explain how to do the "output from your shell script and dump it between the <pre></pre> tags" ?

Thanks
   Shawn
0
Julian HansenCommented:
Solution using <pre> tags
<pre>
<?php
if ($_POST) 
{
  $n = $_POST['n'];
  $u = $_POST['u'];
  
  if (strlen($n) < 8) 
  {
    echo 'NAME field must be at least 8 characters long!';
    return;
  }
  
  if (empty($u)) 
  {
    echo 'USER DATA field must not be empty!';
    return;
  }

  $progname = "CodeLockKeygenCMD.exe ";
  $programcode = $p;
  $userdata = $u;
  $nameofuser = $n;
  $nameofuserstripped = preg_replace('/\s+/', '', $nameofuser);
  $fname = "regcode" . $nameofuserstripped . ".txt";
  $sixtydays = "1";
  $runcmd = $progname . '"' . $programcode . '|' . $userdata . '|' . $nameofuser . '|' . $fname . '|' . $sixtydays . '"'; 

  shell_exec($runcmd);
  
  if (file_exists($fname)) 
  {
    readfile($fname);
    unlink($fname);
  }
  else
  {
    echo "Invalid USER DATA code!";
  }
}
?></pre>

Open in new window

0
shawn857Author Commented:
Julian, the solution to put ?></center></body></html> all on the same last line worked!!! No more extra space in Firefox/IE.... fantastic!!! Thank you very much!

Julian, as a backup plan should some of my users find this method awkward to copy the activation code... do you have an idea why your alternative suggestion of:

<?php
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename('test.txt'));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize('test.txt'));
readfile('test.txt');
?>

Open in new window



... didn't work right? Do you see now maybe why that my script's HTML code was included in the output file?

Thanks!
    Shawn
0
Julian HansenCommented:
... didn't work right?
Can you be more specific on how it failed?

I suspect it has to do with the fact that the data is saved to the file with CR and not CR\LF and because the file is being sent as a application/octet-stream this is what is causing the problem.

You might get a better result with this code

<?php
header('Content-Type: text/plain'); /* CHANGED TO text/plain */
header('Content-Disposition: attachment; filename='.basename('test.txt'));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize('test.txt'));
readfile('test.txt');
?>

Open in new window


But without knowing the specifics of the failure - not sure if this will make a difference.
0
shawn857Author Commented:
Well, when I say it failed, I mean it produced a file like this:


<html>
<head>
<title>Generate extrak DEMO activation code</title><link rel="stylesheet" href="style.css">
</head>
<body><center>
<p>
<img src="extraklogo.png" border="0" ><br>
<table class="form" cellspacing="1" cellpadding="1">
<tr><td class="title" colspan="2"><center><font face="arial"><b>Generate extrak DEMO activation code</b></font></center></td></tr>
<form method="POST" action="">
<tr><td class="title"><span class="small">Name</span></td><td class="title"><input type="text" name="n" size="70" class="text"></td></tr>
<tr><td class="title"><span class="small">User Data</span></td><td class="title"><input type="text" name="u" size="70" class="text"></td></tr>
<tr><td class="background" colspan="2" align="center"><input type="submit" value="Generate"></td></tr>
</form>
</table>
<br>

Name: myname 12
Registration Code:
(copy & paste the whole block)

====== REGISTRATION KEY ======
73srA6UOlHbZR5PavxOd3WCqpYwn5G
LTfTppJAWoQ1iouWBoGt58SLYc51EA
AnIj2MvlZcqc4mVh0HmBiMTmHcTZxj
hrDJosOcyL1YbIQZpehY/H1bosJru0
Wl0dQ7rTZ00NMoSEr6soFyWqinwUhH
bObFQ0QFsYAgffaQ+Rw4UVj8g4xoVx
eedgKqvQxeHknSOURXwecvKH/1+wyj
2HQqO7P88XCKdz0mBEoOwrkb08oRSV
kiDoET3aPehMTdGqjXB6+veyYXMBEB
kvorbaFIavScXawSRJ5QK9PwVYMFZ4
/pUZQEGBNAnZQsPIHM/aSIBGsIJmpE
jJgRK8X0kcjdu12VxeiHS2
====== DO NOT ALTER KEY ======

</center></body>
</html>

Open in new window



... the output file includes not only the activation code, but for some reason, all the HTML code of my script.

Thanks
    Shawn
0
shawn857Author Commented:
Julian, I implemented your last code suggestion and you can try it yourself here:

http://optimaloption.net/index-popupfile3.php

Name: username123
User Data: ED3E78BDB99C15A36DB6746B9966B6ECCFF62E8202EEB9956DC83B7F15C4AF00

... you'll see what I mean when you open the output file.

Here's the full code for that PHP script:

<?php
require_once "config.php";
?>

<html>
<head>
<title>Generate extrak DEMO activation code</title><link rel="stylesheet" href="style.css">
</head>
<body><center>
<p>
<img src="extraklogo.png" border="0" ><br>
<table class="form" cellspacing="1" cellpadding="1">
<tr><td class="title" colspan="2"><center><font face="arial"><b>Generate extrak DEMO activation code</b></font></center></td></tr>
<form method="POST" action="">
<tr><td class="title"><span class="small">Name</span></td><td class="title"><input type="text" name="n" size="70" class="text"></td></tr>
<tr><td class="title"><span class="small">User Data</span></td><td class="title"><input type="text" name="u" size="70" class="text"></td></tr>
<tr><td class="background" colspan="2" align="center"><input type="submit" value="Generate"></td></tr>
</form>
</table>
<br>


<?php
if ($_POST) 
{
  $n = $_POST['n'];
  $u = $_POST['u'];
  
  if (strlen($n) < 8) 
  {
    echo 'NAME field must be at least 8 characters long!';
    return;
  }
  
  if (empty($u)) 
  {
    echo 'USER DATA field must not be empty!';
    return;
  }

  $progname = "CodeLockKeygenCMD.exe ";
  $programcode = $p;
  $userdata = $u;
  $nameofuser = $n;
  $nameofuserstripped = preg_replace('/\s+/', '', $nameofuser);
  $fname = "regcode" . $nameofuserstripped . ".txt";
  $sixtydays = "1";
  $runcmd = $progname . '"' . $programcode . '|' . $userdata . '|' . $nameofuser . '|' . $fname . '|' . $sixtydays . '"'; 

  shell_exec($runcmd);
  
  if (file_exists($fname)) 
  {
   header('Content-Type: text/plain');
   header('Content-Disposition: attachment; filename='.basename($fname));
   header('Expires: 0');
   header('Cache-Control: must-revalidate');
   header('Pragma: public');
   header('Content-Length: ' . filesize($fname));
   readfile($fname);
  }
  else 
  {
    echo "Invalid USER DATA code!";
  }

}
?>

</center></body>
</html>

Open in new window



Thanks!
    Shawn
0
Julian HansenCommented:
Link posted does not load.

Well, when I say it failed, I mean it produced a file like this:
Is that script part of your landing page? It shouldn't be. Your landing page should post to that script as a completely separate script - in other words - the following should be in its own file
sendfile.php
<?php
if ($_POST) 
{
  $n = $_POST['n'];
  $u = $_POST['u'];
  
  if (strlen($n) < 8) 
  {
    echo 'NAME field must be at least 8 characters long!';
    return;
  }
  
  if (empty($u)) 
  {
    echo 'USER DATA field must not be empty!';
    return;
  }

  $progname = "CodeLockKeygenCMD.exe ";
  $programcode = $p;
  $userdata = $u;
  $nameofuser = $n;
  $nameofuserstripped = preg_replace('/\s+/', '', $nameofuser);
  $fname = "regcode" . $nameofuserstripped . ".txt";
  $sixtydays = "1";
  $runcmd = $progname . '"' . $programcode . '|' . $userdata . '|' . $nameofuser . '|' . $fname . '|' . $sixtydays . '"'; 

  shell_exec($runcmd);
  
  if (file_exists($fname)) 
  {
   header('Content-Type: text/plain');
   header('Content-Disposition: attachment; filename='.basename($fname));
   header('Expires: 0');
   header('Cache-Control: must-revalidate');
   header('Pragma: public');
   header('Content-Length: ' . filesize($fname));
   readfile($fname);
  }
  else 
  {
    echo "Invalid USER DATA code!";
  }

}
// Note the absence of the closing ?>

Open in new window

Your landing page then looks like this
<html>
<head>
<title>Generate extrak DEMO activation code</title><link rel="stylesheet" href="style.css">
</head>
<body><center>
<p>
<img src="extraklogo.png" border="0" ><br>
<table class="form" cellspacing="1" cellpadding="1">
<tr><td class="title" colspan="2"><center><font face="arial"><b>Generate extrak DEMO activation code</b></font></center></td></tr>
<form method="POST" action="sendfile.php">
<tr><td class="title"><span class="small">Name</span></td><td class="title"><input type="text" name="n" size="70" class="text"></td></tr>
<tr><td class="title"><span class="small">User Data</span></td><td class="title"><input type="text" name="u" size="70" class="text"></td></tr>
<tr><td class="background" colspan="2" align="center"><input type="submit" value="Generate"></td></tr>
</form>
</table>
</center></body>
</html>

Open in new window

When you are sending output to be saved as a file then that is the only output you can send. With the above script - your landing page will stay in place and all that will (should) happen is a file save dialog should appear.
0
shawn857Author Commented:
Oh okay, I wasn't aware of that at all Julian - I thought you could have HTML and PHP both together in one script and it would be okay. I will give that a try tomorrow as I'm just heading to bed now... almost 4 am here.

That link to the script should work now if you want to try it for fun:

http://optimaloption.net/index-popupfile3.php

It seems that I needed to restart Apache in EasyPHP on the VPS. I've been having to do that almost once a day... the unreliability of that might start becoming another issue in itself...

Thanks
   Shawn
0
Julian HansenCommented:
The link works - but not necessary - if the script is mixing the download code with the form rendering code then it is not going to do what you want - you have to separate them.
0
shawn857Author Commented:
Hi Julian, I separated the HTML from the PHP as per your suggestion and it works perfectly, thanks so much - that will be my "Plan B" in case users don't like copying/pasting straight from the browser.
   Julian, in the sendfile.php, I added this line that my script needs:

require_once "config.php";

I put it right after the opening "<?php" tag.... I'm assuming this is the proper place for it, yes? I tried it and everything seems to work right...

Thanks!
   Shawn
0
Julian HansenCommented:
I'm assuming this is the proper place for it, yes?
That is correct.
0
shawn857Author Commented:
Fantastic, thank you Julian. And thanks to Dave and Ray for their contributions.

Cheers
   Shawn
0
Julian HansenCommented:
You are welcome.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.