Weiterleitung nach Pdf Ausgabe....

treibstoff

Grünschnabel
Ich habe ein Abfrage Script mit Eingaben um anschliessend eine PDF-Datei als Download / Ausführen anzubieten.

Dazu wird nach dem Submit ein Cookie gesetzt und dann wieder redirected zur Seite wo das PDF als Download angeboten wird. (Außerdem werden dort die Eingaben mittels fput in eine namen.txt geschrieben.

Ist das Cookie gesetzt bzw. sind die Eingaben erfülllt kann der Download dann beginnen - und das ohne das das PDF sich automatisch öffnet.

Gerne hätte ich allerdings das ich gleich nach dem Submit alles erledige:
Also Eintrag in die Namen.txt, das readfile (PDF) und dann auch noch die Weiterleitung zur Herkunftsseite


Damit das PDF beim readfile () nicht als Code ausgegeben wird, musste ich dort vorher ob_end_clean() setzen.

Hat jemand ein Idee wie ich das hinbekomme?

PHP:
<?php
function callback($buffer){
    $buffer = str_replace("\n", "", $buffer);
    $buffer = str_replace("\t", "", $buffer);
    $buffer = str_replace(chr(13), "", $buffer);
    $buffer = ereg_replace("<!\-\- [\/\ a-zA-Z]* \-\->", "", $buffer);
    return $buffer;
}
ob_start("callback");?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<meta http-equiv="Content-Style-Type" content="text/css" />

</head>
<body >
	<!-- Main site container -->
      <div id="contentmitte">
      	<h2>Please provide the following company information</h2>
      	<div style="margin-left:1.2em; margin-top:1.2em; width:500px; text-align:center">
<?php 
function checkEmail($email) { 
if (!preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)*.([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/" , $email)) { 
return false; 
} 
return true; 
} 
function pruefung($string) {
$eregi = eregi_replace("([A-Z0-9ÄÖÜäöüß])+([a-zA-Z0-9ÄÖÜäöüß\. -]+)","",$string);
if(empty($eregi)){
return true;
}
return false;
}
if ($_COOKIE["laser"]== "logged"){header ('Content-type: application/pdf');header ('Content-Disposition: attachment; filename="welding_metals.pdf"');ob_end_clean();readfile ('http://www.xyz.de/welding_metals.pdf');exit; }else {
if($werbinich==''){  
$werBinIchValue ="value='Name*' onfocus=\"if (this.value == 'Name*') {this.value = '';}\" onblur=\"if (this.value == '') {this.value = 'Name*';}\"";  
} 
else{  
$werBinIchValue = "value='".$werbinich."' onfocus=\"if (this.value == 'Name*') {this.value = '';}\" onblur=\"if (this.value == '') {this.value = 'Name*';}\""; 
}  
if($name==''){  
$mailValue ="value='Email*' onfocus=\"if (this.value == 'Email*') {this.value = '';}\" onblur=\"if (this.value == '') {this.value = 'Email*';}\""; 
} 
else{  
$mailValue = "value='".$name."'onfocus=\"if (this.value == 'Email*') {this.value = '';}\" onblur=\"if (this.value == '') {this.value = 'Email*';}\"";  
}
if($Company==''){  
$CompanyValue ="value='Company' onfocus=\"if (this.value == 'Company') {this.value = '';}\" onblur=\"if (this.value == '') {this.value = 'Company';}\"";  
} 
else{  
$CompanyValue = "value='".$Company."' onfocus=\"if (this.value == 'Company') {this.value = '';}\" onblur=\"if (this.value == '') {this.value = 'Company';}\""; 
}
if($phone==''){  
$phoneValue ="value='phone' onfocus=\"if (this.value == 'phone') {this.value = '';}\" onblur=\"if (this.value == '') {this.value = 'phone';}\"";  
} 
else{  
$phoneValue = "value='".$phone."' onfocus=\"if (this.value == 'phone') {this.value = '';}\" onblur=\"if (this.value == '') {this.value = 'phone';}\""; 
}
if($aktion=='eingabe'){


ausgabe($name, $werbinich, $Company, $phone);
}
echo "<p>The fields marked <strong>*</strong> have to be filled in.</p>";
echo "<form name='formular' id='search_form' action='$SCRIPT_URI'>\n";
echo "<input type='text' class='search_input' name='werbinich' size='30' ". $werBinIchValue . " >\n"; 
echo "<br /><br />";
echo "<input type='text' class='search_input' name='name' size='30' ". $mailValue . "  >\n";
echo "<input type='hidden' name='aktion' value='eingabe' >\n";
echo "<br /><br />";
echo "<input type='text' class='search_input' name='Company' size='30' ". $CompanyValue . " >\n"; 
echo "<br /><br />";
echo "<input type='text' class='search_input' name='phone' size='30' ". $phoneValue . " >\n"; 
echo "<br /><br />";
echo "<input type='submit' value='submit'>\n";
echo "</form>\n";
echo "<small>You will be 
redirected to the download<br />and set free to download all data sheets and 
brochures</small>";
}



function ausgabe($name,$werbinich,$Company,$phone){
$fp = fopen("namen.txt", "a+");
$name1 = "<br/><br/>\n\n".$name;
$name2 = "<br/>\n".$werbinich;
$name3 = "<br/>\n".$Company;
$name4 = "<br/>\n".$phone;
$email = trim($name);
$string = trim($werbinich);    
if(!checkEmail($email)) {   
echo 'Invalid email address';
}
else {
   if(($string == "Name*") or ($string == "")) { 
    echo 'Invalid Name';} 
        else {if(!pruefung($string)) {echo 'Invalid Name';
}else {
	fputs($fp, $name1.$name2.$name3.$name4);fclose($fp);setcookie("laser",'logged', time()+3600);header ('Location:http://www.nach irgendwo.de');
 }}

}} ?>
<!-- Hier endet der Mitte Content -->
<p>&nbsp;</p><p><a href="http://www.adobe.de/products/acrobat/readstep.html" target="_blank" title="download Acrobat Reader to view the PDF Data Sheets"><img src="images/getacro.gif" width="88" height="31"></a></p><p>&nbsp;</p>

      </div></div>
        <!-- Footer begins -->
  </body>
</html> <?php ob_end_flush(); ?>

PS: Wen es wundert: Die <br /> Tags nach der function Ausgabe() für den Eintrag in der Namen.txt sind deshalb dort, weil die Namen.txt als html mit Utf8 beim Aufruf im Browser angezeigt wird und das mittels Eintrag in der htaccess durch
PHP:
<Files "namen.txt">
ForceType 'text/html; charset=UTF-8'
</Files>
 
Zurück