Lassie Posted November 26, 2007 Share Posted November 26, 2007 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. ?> Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 26, 2007 Share Posted November 26, 2007 For debugging purposes, try echoing $url to the page instead of using the redirect to verify that the $url is properly created. <?php ob_end_clean(); // Delete the buffer. //header("Location: $url"); echo "The URL is: $url"; exit(); // Quit the script. ?> Quote Link to comment Share on other sites More sharing options...
Lassie Posted November 26, 2007 Author Share Posted November 26, 2007 Thanks for coming back. I still get a blank page. Quote Link to comment Share on other sites More sharing options...
revraz Posted November 26, 2007 Share Posted November 26, 2007 You probably have errors suppressed and are getting a Header already sent error. Try to use either a HTML or a Java redirect instead and see if that works. Quote Link to comment Share on other sites More sharing options...
Lassie Posted November 26, 2007 Author Share Posted November 26, 2007 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'); ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted November 26, 2007 Share Posted November 26, 2007 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. Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 26, 2007 Share Posted November 26, 2007 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. ?> Quote Link to comment Share on other sites More sharing options...
Lassie Posted November 26, 2007 Author Share Posted November 26, 2007 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? Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 26, 2007 Share Posted November 26, 2007 It would take longer to ask that and get a response than to just try it. So, yes, I would try it. Quote Link to comment Share on other sites More sharing options...
Lassie Posted November 26, 2007 Author Share Posted November 26, 2007 same result code still displayed. I will rework the script piece by piece. Thank you for you help Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 27, 2007 Share Posted November 27, 2007 If the "code" is being displayed then then the code is not being interpreted. Is the code in an "html" page and not a PHP page? Although that would not explain why some of the code is not being displayed. BUt, there's definitely something else going on here. Quote Link to comment Share on other sites More sharing options...
Lassie Posted November 28, 2007 Author Share Posted November 28, 2007 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> Quote Link to comment Share on other sites More sharing options...
adam291086 Posted November 28, 2007 Share Posted November 28, 2007 <?php echo"This is php Hello World"; <? // this is wrong should be ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
Lassie Posted November 28, 2007 Author Share Posted November 28, 2007 Sorry, typo. code is ok in test folder but no php displayed only html. Quote Link to comment Share on other sites More sharing options...
adam291086 Posted November 28, 2007 Share Posted November 28, 2007 post the code that a) redirects you and b) the code that makes up the new page that users are redirected to. Quote Link to comment Share on other sites More sharing options...
Lassie Posted November 28, 2007 Author Share Posted November 28, 2007 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. ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.