Jump to content

redirect code gives blank page


Lassie

Recommended Posts

I have a simple piece of code designed to register a bookmark in an arrray during a customer site visit.

The page should update the arrray and redirect but I get only a blank page.

I dont get error messages and this basic code works in a similar application.

 

Can anyone see my error please.

 


<?php
ob_start();
require_once('db_fns.php');
require_once ('./includes/config.inc.php');
@ $product_id = $_GET['product_id'];
if($product_id)
{
    //new property selected
    	if(!isset($_SESSION['browse']))
    {
      	$_SESSION['browse'] = array();
    }
    //update browse list
    $_SESSION['browse'][]="$product_id";
    }	
    		// Start defining the URL.Return to browsing
		$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
		// Check for a trailing slash.
		if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) 
		{
			$url = substr ($url, 0, -1); // Chop off the slash.
		}
		// Add the page.
		$url .= '/index.php';

		ob_end_clean(); // Delete the buffer.
		header("Location: $url");
		exit(); // Quit the script.

?>
    		

Link to comment
Share on other sites

I am reluctant to change tack at this point as the code does work in another application.

I have an error script which is included in the page, but no output from it.

This is the code for the errors

 


<?php #  - config.inc.php

// This script determines how errors are handled and deines variables
//$user_type=$_SESSION['user_type'];

// Flag variable for site status:
$live = TRUE;

// Error log email address:
$email = 'xxxxxxxx@btinternet.com';

// Create the error handler.
function my_error_handler ($e_number, $e_message, $e_file, $e_line) {

global $live, $email;

// Build the error message.
$message = "An error occurred in script '$e_file' on line $e_line: \n<br />$e_message\n<br />";

// Add the date and time.
$message .= "Date/Time: " . date('n-j-Y H:i:s') . "\n<br />";

// Append $e_vars to the $message.
//	$message .= print_r($e_vars, 1);

if ($live) { // Don't show the specific error.

//	error_log ($message, 1, $email); // Send email.

	// Only print an error message if the error isn't a notice.
	if ($e_number != E_NOTICE) {
		echo '<div id="Error">A system error occurred. We apologize for the inconvenience.</div><br />';
	}

} else { // Development (print the error).
	echo '<div id="Error">' . $message . '</div><br />';
}

} // End of my_error_handler() definition.

// Use my error handler.
set_error_handler ('my_error_handler');
?>

Link to comment
Share on other sites

If you want to troubleshoot, you have to change something.  You don't have to leave it, but you do want to figure out the problem right?

 

It only takes a second to put // in front of header("Location: $url"); and then add a single line under it to use HTML or Java instead.  At least it will tell you if that's the problem or not.

 

I am reluctant to change tack at this point as the code does work in another application.

Link to comment
Share on other sites

Try this to see what is happening throughout the page:

 

<?php
ob_start();
require_once('db_fns.php');
require_once ('./includes/config.inc.php');
echo "Requires completed<br />\n";


@ $product_id = $_GET['product_id'];
echo "Product ID = '$product_id'<br />\n";

if($product_id)
{
   echo "Product ID is true\n";
   //new property selected
   if(!isset($_SESSION['browse']))
   {
     	unset($_SESSION['browse']);
       echo "Session['browse'] was set and is now unset<br />\n";
   }

   //update browse list
   $_SESSION['browse'][]="$product_id";
   echo "Session['browse'] has been repopulated: <pre>".print_r($_SESSION['browse'])."</pre>\n";
}	

// Start defining the URL.Return to browsing
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
echo "$url has been defined: $url<br />\n";

// Check for a trailing slash.
if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) 
{
   $url = substr ($url, 0, -1); // Chop off the slash.
   echo "$url has been re-defined: $url<br />\n";
}

// Add the page.
$url .= '/index.php';
echo "$url has been re-defined: $url<br />\n";

ob_end_clean(); // Delete the buffer.
//header("Location: $url");
exit(); // Quit the script.

?>

Link to comment
Share on other sites

Ok. I tried that code and i only recieved the raw code from ' Start definning Url' as follows:-

 

\n";

}

 

// Start defining the URL.Return to browsing

$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);

echo "$url has been defined: $url<br />\n";

 

// Check for a trailing slash.

if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') )

{

    $url = substr ($url, 0, -1); // Chop off the slash.

    echo "$url has been re-defined: $url<br />\n";

}

 

// Add the page.

$url .= '/index.php';

echo "$url has been re-defined: $url<br />\n";

 

Clearly a problem somewhere . I can't see why this should occur.Is it worth trying this without the buffer set?

Link to comment
Share on other sites

Hi,

I am still having this problem.

I have established that the link goes to the correct page by using a simple program to display html and php.

The problem occurs whether the test page is htm or php.

The result is the html is displayed but not the php.

Short of reinstalling the development environmet (uniserver3.5) I am stumped.

Does anybody have any suggestions that might reveal the issue. The php is not being passed in new pages yet the existing web pages parse no problem.

If it helps I can post the link to the site.

My test code is

 

<html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        		"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
			<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head></head>
<body>
<p>This is html Hello World</p>
<?php
echo"This is php Hello World";
<?
</body>
</html>

Link to comment
Share on other sites

This is the redirect code


echo'<td>';
    $target='bookmark_list.php?product_id='.$product_id;
display_bookmark($target, 'bookmark', 'add to browse list');
echo'</td>';

and the function


function display_bookmark($target, $image, $alt)
{
	echo "<a href=\"$target\"><img src=\"images/$image".".gif\" 
           alt=\"$alt\" border=0 height = 57 width = 55></a>";	
}

this is the page that updates the bookmark array and rediects.

<?php
ob_start();
require_once('db_fns.php');
require_once ('./includes/config.inc.php');
@ $product_id = $_GET['product_id'];
if($product_id)
{
    //new property selected
    	if(!isset($_SESSION['browse']))
    {
      	$_SESSION['browse'] = array();
    }
    //update browse list
    $_SESSION['browse'][]="$product_id";
    }	
    		// Start defining the URL.Return to browsing
		$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
		// Check for a trailing slash.
		if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) 
		{
			$url = substr ($url, 0, -1); // Chop off the slash.
		}
		// Add the page.
		$url .= '/index.php';

		ob_end_clean(); // Delete the buffer.
		header("Location: $url");
		exit(); // Quit the script.

?>
    	

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.