Jump to content


Photo

header("Location ... Problem in PHP 5


  • Please log in to reply
2 replies to this topic

#1 larswise

larswise
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 07 October 2006 - 10:11 AM

Hello,

I just upgraded my PHP to v5 and one of my scripts doesn't seem to work anymore (the script taking care of my orders). The script was written about two years ago and worked fine with php 4.2.3, It's an ugly script but it does (did) the job.

The problem is when i output my head.inc file (with html) before a header("Location: $var"); it simply stops and just displays an empty page with header.inc and footer.inc.

The code looked like this:

include 'head.inc';
if(strcmp($_GET['action'], "subm") == 0) {
if($_GET['step'] == "start" || $_GET['ccat'] == "select") {

when i reach the redirect code, the $_GET['action'] is still set to "subm"

I tried:

if(strcmp($_GET['action'], "subm") == 0) {
if($_GET['step'] == "start" || $_GET['ccat'] == "select") {
include 'head.inc';

But then, as the script is made, the page displays without any html header when neither step == start or ccat == select :)

Is there any good workaround to force a redirect even if HTML is outputted ?

Thanks in advance

Lars





#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 07 October 2006 - 11:09 AM

Use output buffering in that case

Add
ob_start();
after the opening php tag (<?php) and
ob_end_flush();
before the closing php tag (?>)

#3 larswise

larswise
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 07 October 2006 - 11:25 AM

wohAhoy! thank you!  :D

Lars




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users