canadabeeau Posted November 22, 2009 Share Posted November 22, 2009 Hi, I have a PHP function that is called in another PHP page. That is index.php calls func_my(); func_my() works like this: function func_my(){ $method = $_SESSION['data']; unset($_SESSION['data']); list($one, $two) = split("#", $method, 2); if($one == "0"){ echo "Goodday"; } else { header('location: http://www.google.com.au'); }; }; Except the header redirect is not rdirecting to google, it just loads the page with no echo becuase it !=0 and does nothing,anyone can you please help with this ssue. Thankyou in advance Quote Link to comment Share on other sites More sharing options...
keldorn Posted November 22, 2009 Share Posted November 22, 2009 It might be the ; after the last 2 brackets. I surprised the script ran at all with that? Second you may need to put exit; after header(); so that the script stops completely. Quote Link to comment Share on other sites More sharing options...
canadabeeau Posted November 22, 2009 Author Share Posted November 22, 2009 UPDATE: I did as asked above remove the two ";" and adde4d exit; However I forgot to add that when I run this function it does not load anything below it (continue the oage. For example after the function I have text and if I run the function so it does the redirect not only does it not redirect it does no load the text below, so it is kind of stopping. More help would be greatly appreciated Quote Link to comment Share on other sites More sharing options...
keldorn Posted November 22, 2009 Share Posted November 22, 2009 To you have php tags opening and closing above it with html? Turn on error_reporting(E_ALL); in the top of the script. Does it say, Cannot set headers, headers already sent? if so you cannot put a header in a place where you already have outputted html. Thats why you should separate your html from business logic. Quote Link to comment Share on other sites More sharing options...
canadabeeau Posted November 22, 2009 Author Share Posted November 22, 2009 Warning: Cannot modify header information - headers already sent by (output started at C:\inetpub\wwwroot\_inc\php\nav.php:27) in C:\inetpub\wwwroot\apps\my\functions.php on line 47 What do I do to fix this, I need to redirect if the value in not 0, how can I solve this, what does this error actually mean for me? Quote Link to comment Share on other sites More sharing options...
keldorn Posted November 22, 2009 Share Posted November 22, 2009 This requires to understand how the html page is sent. The first part of a page is called the headers, which is sent first, then after that you can buffer out the html. So logically you cannot set a header, when the header for the page has already been sent. That whats PHP does when you open can close php tags with html, once you close the PHP tag and put html, the header is sent. After that point, you cannot set any more thigns that modify the headers, like cookies, sessions, and header(). You might want to installed LiveHTTPheaders for Firefox, if you use firefox, then you can what a header looks like. Quote Link to comment Share on other sites More sharing options...
canadabeeau Posted November 22, 2009 Author Share Posted November 22, 2009 So how can I do this redirect then? and is this accurate http://www.geeklog.net/faqman/index.php?op=view&t=38 Quote Link to comment Share on other sites More sharing options...
keldorn Posted November 22, 2009 Share Posted November 22, 2009 Well yeah if you have whitespace before the first <?php tag, then php will send the headers right away. It will assume you started the page with html. Either you will have to restruture your page, maby do the that bit of logic in the first php tag, or a cheap hack might be to use ob_start(); which stop sending of the header, until it hits ob_end_flush(); Then when you hit that header() redirect, use ob_end_clean() before it (Discards the html) then just send the header and exit; This an example: <?php ob_start(); $test = '1'; ?> <p>Hello world foo bar</p> <?php if($test == '0'){ echo "And goodday"; } else { ob_end_clean(); header("Location: http://google.com"); exit; } ob_end_flush(); ?> Quote Link to comment Share on other sites More sharing options...
canadabeeau Posted November 22, 2009 Author Share Posted November 22, 2009 Everyone please look athmy D.I.C forum too, so I dont have to double post information http://www.dreamincode.net/forums/index.php?showtopic=140727&st=0&gopid=842040&#entry842040 Quote Link to comment Share on other sites More sharing options...
keldorn Posted November 22, 2009 Share Posted November 22, 2009 btw I thought you were getting a software patent and were making some kind of software? Yet you dont know these basic things. Everyone want to start at the top. Quote Link to comment Share on other sites More sharing options...
canadabeeau Posted November 22, 2009 Author Share Posted November 22, 2009 This happens to be for a different project, and software patent cleared for the other one :-). Quote Link to comment Share on other sites More sharing options...
canadabeeau Posted November 22, 2009 Author Share Posted November 22, 2009 For solution see http://www.dreamincode.net/forums/index.php?showtopic=140727&pid=842077&st=0&#entry842077 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.