Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/176613-solved-php-error/
Share on other sites

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:8) 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

Link to comment
https://forums.phpfreaks.com/topic/176613-solved-php-error/#findComment-931081
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/176613-solved-php-error/#findComment-931085
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/176613-solved-php-error/#findComment-931089
Share on other sites

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");

Link to comment
https://forums.phpfreaks.com/topic/176613-solved-php-error/#findComment-931104
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.