Link to home
Start Free TrialLog in
Avatar of Richard Korts
Richard KortsFlag for United States of America

asked on

php not working??

I have this code at the very end of a lengthy php program:

</form>
</div>
</div>
<? echo "nosumm = " . $_GET['nosumm'] . "<br>";
	if ($_GET['nosumm'] == "1") {
		header("Location: send_email_ls250.php?ddocs=" . $ddocs);
		exit;
	} else {
		header ("Location: summaryk.php?ddocs = " . $ddocs . "&nosumm=" . $_GET['nosumm'] . "&mv=Y");
		exit;
	}	
?>		
</body>
</html>

Open in new window


When it is run, it displays the page (see attached) with the echo at the bottom.

Why is the header to send_email_ls250.php?ddocs=" . $ddocs ignored?

FYI, I wasn't sure if $_GET['nosumm'] returns an integer 1 or a character "1", so I tried it both ways, same result.

The url is https://www.lakoshvac.com/summaryk.php?fr=proj&nosumm=1&ddocs=Y
wont_redirect_with_header.JPG
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

As stated in http://php.net/manual/en/function.header.php :
Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.
I can see from your code snippet that you've already sent output (the </form> tag etc count as output), so trying to send a header at that point won't work.

If you really do want to use the header function, you'll need to move the code so that it is run before output is sent.
Avatar of Richard Korts

ASKER

Thanks, that makes perfect sense. I did that.

It still fails & gives a blank page.

The url is: https://www.lakoshvac.com/summaryk.php?fr=proj&nosumm=1&ddocs=Y

Here is ALL the php code BEFORE the first output:
<?php
	error_reporting(E_ALL);
	ini_set('session.cache_limiter','public');
	session_cache_limiter(false);
	// sand_or_sep.php
	session_start();
	$ddocs = $_GET['ddocs'];
	$fr = $_GET['fr'];
	//echo "fr = " . $fr . "<br>";
	//echo "voltage = " . $_SESSION['voltage'] . "<br>";
	//echo "show prices = " . $_SESSION['show_prices'] . "<br>";
	//echo "access = " . $_SESSION['access'] . "<br>";
	//echo "pump repair = " . $_SESSION['pumprepair'] . "<br>";
	//echo "session['purge'] = " . $_SESSION['purge'] . "<br>";
	// check for net pricing
	function fmt_price($x) {
		if ($x == "0") {
			return "No Charge";
		}
		if (substr($x,0,5) == "facto") {
			$_SESSION['fac_quote'] = true;
			return "Factory Quote";
		}
		$r = "$" . number_format($x,2);
		return $r;
	}
	function conv_to_inches($x) {
		$xs = strval($x);
		if (substr($xs, -1) == "0") {
			$len = strlen($xs);
			$xs = substr($xs,0,$len-1);
		}
		$r = $xs . '"';
		return $r;
	}	
	$dir = getcwd();
	if (strpos($dir, "dev") !== false) {
		$subdir = "dev/";
	} else {
		$subdir = "https://htsumms:PjCcrK18!@www.lakoshvac.com/";
	}
	//echo "subdir = " . $subdir . "<br>";
	//echo "dir = " . $dir . "<br>";
	$_SESSION['fac_quote'] = false;
	$cwd = getcwd();	
	include "db_connect_nb.php";
	include "hb_prices.php";
	include "hb_prices_net.php";
	include "get_drawing.php";
	// check for net pricing
	$net_pricing = false;
	$allow_freight = false;
	if ($_SESSION['ruid'] != "") {
		$qryru = "SELECT * from registered_users where ix = " . $_SESSION['ruid'];
		$resru = mysqli_query($link, $qryru);
		$ru = mysqli_fetch_array($resru,MYSQLI_ASSOC);
		if ($ru['net_pricing'] == "Y") {
			$net_pricing = true;
		}
		if ($ru['country'] == "USA" || $ru['country'] == "United States") {
			$allow_freight = true;
		}	
	}
	// disallow freight, Oct 10, per Lakos - Remove when freight allowed
	$allow_freight = false;
	//echo "net_pricing = " . $net_pricing . "<br>";	
	$ems = $_GET['em'];
	$ps = $_GET['ps'];
	$model = $_SESSION['model'];
	$app = "Basin";
	if ($_SESSION['cltype'] != "B") {
		if ($_SESSION['cltype'] == "S") {
			if ($_SESSION['typ'] == "sssep") {
				$app = "Full";
			} else {			
				$app = "Side";
			}	
		} else {
			$app = "Full";
		}
	}		
	$qry = "SELECT * from products where Model = '" . $_SESSION['model'] . "' and App = '" . $app . "'";
	//echo "qry = " . $qry . "<br>"; 
	$res = mysqli_query($link, $qry);
	$p = mysqli_fetch_array($res,MYSQLI_ASSOC);
	$ptot = $p['base_price'];
	// image
	if (substr($model,0,1) == "e") {
		$Pgrp = substr($model,0,4);
		$pgrp = strtolower(substr($model,0,4));
	} else {
		$Pgrp = substr($model,0,3);
		$pgrp = strtolower(substr($model,0,3));
	}
	
	//echo "pgrp = " . $pgrp . "<br>";
	//echo "pgrp = " . $pgrp . "<br>";
	$image = $pgrp . "-product.jpg";
	// get model group desc.
	$qryd = "SELECT * from pgroup_descs where pgroup = '" . $pgrp . "'";
	$resd = mysqli_query($link, $qryd);
	$gd = mysqli_fetch_array($resd,MYSQLI_ASSOC);
	$_SESSION['gddesc'] = $gd['gdesc'];
	// Valve Kit
	$v_kit = "";
	if ($_SESSION['TCVValve'] == "Y") {
		$v_kit = "TCV";
		$vkdbn = "TCV_Valve";
	}
	if ($_SESSION['ECVValve'] == "Y") {
		$v_kit = "ECV";
		$vkdbn = "ECV_Valve";
	}	
	if ($_SESSION['eTCVValve'] == "Y") {
		$v_kit = "eTCV";
		$vkdbn = "eTCV_Valve";
	}
	$_SESSION['valve_kit'] = $v_kit;
	$voltage = $_SESSION['voltage'];
	$pos = strpos($voltage," ");
	$l = strlen($voltage);
	$cltype = $_SESSION['cltype'];
	if ($_SESSION['cltype'] != "F" && $_SESSION['typ'] != "sssep") {
		$dbvn = substr($voltage,0,$pos) . "_" . substr($voltage,$pos+1,5);
		$dbvn = str_replace(" ", "", $dbvn);
		//echo "dbvn = " . $dbvn . "<br>";
	}	
	switch($_SESSION['cltype']) {
		case "B":
			$cltype = "Basin Cleaning";
			break;
		case "S":
			$cltype = "Side Stream";
			break;
		case "F":	
			$cltype = "Full Stream";
			break;
	}
	//echo "session - hctrls " . $_SESSION['hlctrls'] . "<br>";
	include "pdf_summary_new2.php";
	include "pdf_summary_np.php";
	// build dislayable options from $_SESSION vars
	//echo "cwd = " . getcwd() . "<br>";	
	include "get_files.php";
	//echo "drawing = " . $drawing . "<br>";		
	// override drawing if group = etcx, etbx, tcx or tci & certain voltages
	$v14 = substr($_SESSION['voltage'],0,4);
	//echo "v14 = " . $v14 . "<br>";
	if ($v14 == "380V" || $v14 == "415V") {
		if ($pgrp == "etcx" || $pgrp == "etbx" ) {
			$drawing = "";
		}
	}
	if ($v14 != "460V") {
		if ($pgrp == "sts" || $pgrp == "cts") {
			$drawing = "";
		}
	}
	//echo "drawing = " . $drawing . "<br>";	
// download, print stuff
	//$drawing = get_drawing($model);
	
	// go elsewhere if LS250
	if ($_GET['nosumm'] == "1") {
		header("Location: send_email_ls250.php?ddocs=" . $ddocs);
		exit;
	}		
?>	

Open in new window


I'm at a total loss.

Thanks
That link is not giving me a blank page - it's giving me the following message:

FPDF error: Unable to create output file: https://home/lakoshva/summsp/summary.pdf
Hmmm. Now it is giving me a blank page, but if I check the source of that blank page, I see 3 empty lines, which may prevent the header() call from working (blank lines count as output!)

Something to think about that can often cause the blank lines - don't add the closing PHP tag at the end of your scripts! Just leave of the ?> from the end of all your scripts that you include - they're often the reason you get blank lines and this causes you hours of hunting around for bugs, particularly when you're trying to call the header() function.
I fixed the issue with the error you got earlier.

I removed the closing ?> tag from all 7 of the include files.

It now shows 3 blank lines at the top when I view source, so of course, that is PROBABLY the WHOLE problem.

I'll see if any of the includes themselves that includes.

Thanks, I think we are closer.

Richard
Chris,

I removed the closing tag in on other file included in one of the included files.

There are still two blank lines at the top on view source.

If there is a blank line in any of the included php files, can that cause this?

Just a plain blank line?

Thanks
Yes, blank lines before a <?php tag cause the problem too.
Any blank lines outside of the PHP script will be output as blank lines in the file (before and after)
I found the last two blank lines source & fixed.

Now the problem is totally different; it appears to be in an infinite loop.

Aaaaaaaaaaaarrrrrrrrrrrrrrrggggggggg!!!
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.