vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   PHP Redirect (https://vborg.vbsupport.ru/showthread.php?t=49415)

inthezone 02-27-2003 01:44 AM

PHP Redirect
 
I'm writing a conditional script that uses vB's global.php, and I'm attempting to redirect unregistered users to the user cp login screen. However, since I am using a header include on the page, I get a Cannot modify header information - headers already sent error. I've tried commenting out the line that requires the header, and the redirect works fine. With the require line intact, I get the error and no redirect.

PHP Code:

<?php

chdir
('/path/to/forums/');
require(
'./global.php');

require(
'/path/to/header.php');

if (
$bbuserinfo['usergroupid']==1
{
header("Location: http://www.mydomain.com/forums/usercp.php");
exit;
}
else
{
echo 
"Welcome back, ".$bbuserinfo['username']."!";
}

require(
'/path/to/footer.php');

?>

How can I get it to redirect properly while still using the header? (BTW, header.php and footer.php are strictly HTML with no php code inside.)



Edit-I guess putting the header and footer requires in the "else" part of the conditional would work. Is there another way to do this that I am missing?

mr e 02-27-2003 02:09 AM

use a javascript redirect, not sure what it is exactly but it works, or you could try a meta redirect but im not sure if that'll work

Kriek 03-01-2003 10:09 PM

Output Buffering

Use output buffering with ob_start() and ob_end_flush(). Although ob_end_flush() isn't needed in MOST cases because it is called automatically at the end of script execution by PHP itself when output buffering is turned on either in the php.ini or by calling ob_start()

PHP Code:

<?php ob_start(); 

// entire script, code, or page here

ob_end_flush(); ?>

Output buffering (PHP 4.0) was originally designed to solve HTTP header errors. I should also mention that Output buffers are stackable, that is, you may call ob_start() while another ob_start() is active. Just make sure that you call ob_end_flush() the appropriate number of times. If multiple output callback functions are active, output is being filtered sequentially through each of them in nesting order.

VeoMorphine 03-03-2003 06:38 PM

check your global.php for any spaces or new lines after the ?> and before the <?


All times are GMT. The time now is 01:41 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01077 seconds
  • Memory Usage 1,721KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete