• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1240
  • Last Modified:

Passing parameters using header location format

I tried passing in a parameter using the header format but don't know how, can you fix this code please:

header('Location: Customer_Mare_Progress_Status.php')

?CustomerNo.=<?print $CustomerNo?>

0
willwatters
Asked:
willwatters
  • 2
1 Solution
 
VGRCommented:
header("Location: Customer_Mare_Progress_Status.php?CustomerNo=$CustomerNo");

just a problem of single vs double quotes...
0
 
jausionsCommented:
Hi,

Be aware that some web browsers expect a full URL and not just the last page. So you may need to do:

header('Location: http://myserver/Customer_Mare_Progress_Status.php?CustomerNo=' . $CustomerNo);

Of course replace "myserver" by the actual value. You could also do:

<?php

// Get server name and default port
$sHost = ($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
$iPort = $_SERVER['SERVER_PORT'];

// Get more detailed info
if (strpos($sHost, ':') !== false) {
  list($sHost, $iPort) = explode(':', $sHost);
}

// Build URL depending on protocol
if (isset($_SERVER['HTTPS']) && strtoupper($_SERVER['HTTPS']) == 'ON') {
  // HTTP-S
  $sURL = 'https://' . $sHost . (($iPort == 443) ? '' : ':' . $iPort);
} else {
  // HTTPS
  $sURL = 'http://' . $sHost . (($iPort == 80) ? '' : ':' . $iPort);
}

// Should check for headers_sent() too
header('Location: ' . $sURL . dirname($_SERVER['PHP_SELF']) . '/Customer_Mare_Progress_Status.php?CustomerNo=' . $CustomerNo);

?>
0
 
VGRCommented:
well, did I "fix the code" or not ?
was my answer "thorough" enough or not ?
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now