leegreaves Posted October 5, 2009 Share Posted October 5, 2009 can anyone help me with an error i keep getting on my code...have had some help on here with trying to get a login script to work correctly and did get some headway with it. but now im getting another error code come up, ive been shown how to insert a session register in my code but not sure why im getting this error: Warning: session_register() [function.session-register]: Cannot send session cookie - headers already sent by (output started at /home/tastscou/public_html/index.php:9) in /home/tastscou/public_html/index.php on line 188 Warning: session_register() [function.session-register]: Cannot send session cache limiter - headers already sent (output started at /home/tastscou/public_html/index.php:9) in /home/tastscou/public_html/index.php on line 188 Warning: Cannot modify header information - headers already sent by (output started at /home/tastscou/public_html/index.php:9) in /home/tastscou/public_html/index.php on line 190 It says something about a side effect that existed till php 4.2.3 but cudnt see everything that was noted cos my page was obscuring it. Any ideas as to whats happening here? Quote Link to comment https://forums.phpfreaks.com/topic/176613-solved-php-error/ Share on other sites More sharing options...
cags Posted October 5, 2009 Share Posted October 5, 2009 Anything that modifies headers must be right at the top of the script and called before any output is made. Since session_register() modifies the header it must be called at the top of the script. Quote Link to comment https://forums.phpfreaks.com/topic/176613-solved-php-error/#findComment-931077 Share on other sites More sharing options...
leegreaves Posted October 5, 2009 Author Share Posted October 5, 2009 Right after posting this, id made an alteration...i was told that all php code must go at the top of page...which mine wasnt...that sorted that problem out there ( or so it seemed) now im getting this error: Login Succesful - Please wait while you are redirected Warning: Cannot modify header information - headers already sent by (output started at /home/tastscou/public_html/login_success.php: in /home/tastscou/public_html/login_success.php on line 10 !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> This is my login_success.php script which it refers to: <? session_start(); if(!session_is_registered(myusername)){ header("location:index.php"); } ?> <? echo "Login Succesful - Please wait while you are redirected"; header ("location:chat.php"); ?> !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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> </body> </html> <font size="+6" face="Arial, Helvetica, sans-serif"></font> ==== Any ideas on this? iIm trying to work this out at the moment but wud appreciate any pointers Quote Link to comment https://forums.phpfreaks.com/topic/176613-solved-php-error/#findComment-931081 Share on other sites More sharing options...
.josh Posted October 5, 2009 Share Posted October 5, 2009 why are you even using session_register? It's deprecated and slotted for removal in php6. Anyways, as to your new errors, that is because you are calling the header function after output. You can't do that either. I don't really know why you are trying to do that anyways, as instantly sends you to the location, so it's not like the user will see the echoe'd message anyways. Quote Link to comment https://forums.phpfreaks.com/topic/176613-solved-php-error/#findComment-931085 Share on other sites More sharing options...
cags Posted October 5, 2009 Share Posted October 5, 2009 As I said in the previous post you cannot send headers after you start outputing data, so this.... echo "Login Succesful - Please wait while you are redirected"; header ("location:chat.php"); Is not possible. If you really need to display login success first you will have to redirect with HTML/JavaScript, but I personally don't see the point. They know they have logged in successfully because you have forwarded them to a member page. Also I'd recommend against using short_tags (<? ?>), you should really always use full tags (<?php ?>). Edit: Crayon Violent beat me to some of it. Quote Link to comment https://forums.phpfreaks.com/topic/176613-solved-php-error/#findComment-931089 Share on other sites More sharing options...
leegreaves Posted October 5, 2009 Author Share Posted October 5, 2009 ive corrected that code by omitting the 2nd header, so how would i redirect the page to the member area after a successful login..if i shudnt be using the header command? You say by redirecting by html/javascript...can u not redirect using php? Quote Link to comment https://forums.phpfreaks.com/topic/176613-solved-php-error/#findComment-931094 Share on other sites More sharing options...
.josh Posted October 5, 2009 Share Posted October 5, 2009 you can redirect with the header command, just remove the echo right above it. If you really really want to have a message like that before actually redirecting, you can output a meta tag that redirects, instead (or with javascript). Quote Link to comment https://forums.phpfreaks.com/topic/176613-solved-php-error/#findComment-931098 Share on other sites More sharing options...
leegreaves Posted October 5, 2009 Author Share Posted October 5, 2009 AHA...so i seem to have sorted such a small (and probly easy...to experienced coders that is) problem...ive got a successful redirect to a test page. Now the last part. If the file i want redirection to is in a different folder in my web root folder...would i just simply point to it by this way: if my folder is called, for example, folder one and i need to redirect to a page in it...would i change the code to the following: header ("location:/folder one/file"); Quote Link to comment https://forums.phpfreaks.com/topic/176613-solved-php-error/#findComment-931104 Share on other sites More sharing options...
leegreaves Posted October 5, 2009 Author Share Posted October 5, 2009 aha no need for an answer to this question...i was gonna try that way already and obviously it is the correct way...so this problem is now solved. Quote Link to comment https://forums.phpfreaks.com/topic/176613-solved-php-error/#findComment-931110 Share on other sites More sharing options...
cags Posted October 5, 2009 Share Posted October 5, 2009 Yes, as you say it works. One thing I will point out though, be carefull using spaces in folder names. Quote Link to comment https://forums.phpfreaks.com/topic/176613-solved-php-error/#findComment-931114 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.