If your application outputs something ( like an error message or a
blank line out of the <?php ?> ) you can't modify headers.
Raw HTTP response:
-------------------------------
HTTP/1.1 200 OK
<-- headers begin
Date: Sun, 25 May 2008 23:42:55 GMT
Server: Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5 with Suhosin-Patch
Last-Modified: Fri, 02 May 2008 00:21:54 GMT
ETag: "1cf38-2d-44c345e7b6c80"
Accept-Ranges: bytes
Content-Length: 45
Connection: close
Content-Type: text/html
<-- headers ends
<html><body><h1>It works!</h1></body></html>
<-- data for the response
So if you started to output the data, you can't add headers. So you
better make sure you aren't outputting nothing before trying to send
headers.
Other alternative is to use output buffering.
Keep in mind that sending a redirect header does not stop the
execution of your script, you need to call exit.
All of this and much more can be found in the PHP manual: http://php.net
And if you need to know how cake does the redirect, simply look into
source the code:
http://api.cakephp.org/libs_2controller_2controller_8php-source.html#l00461
Regards,
- Dardo Sordi.
On Sun, May 25, 2008 at 8:23 PM, Raistlin Majere <[EMAIL PROTECTED]> wrote:
>
> Is that how CakePHP not already sends headers?
>
> On 25 maio, 17:11, "Olexandr Melnyk" <[EMAIL PROTECTED]> wrote:
>> Set error_reporting to E_ALL and display_errors to on, to make sure there's
>> nothing being sent to the browser before the header() line.
>>
>> On 5/25/08, Raistlin Majere <[EMAIL PROTECTED]> wrote:
>>
>>
>>
>>
>>
>> > I am trying to create a version of my site without CakePHP to use a
>> > different free host.
>>
>> > after this much code
>>
>> > $this->set('title', 'Create');
>> > if (!empty($this->params['form'])) {
>> > $email = ($this->params['form']['data']['Account']['email']);
>> > $password = ($this->params['form']['data']['Account']
>> > ['password']);
>> > $exists = $this->Account->query("SELECT * FROM accounts WHERE
>> > email = '$email' AND password = '$password'");
>> > if ($this->Account->save($this->params['form']['data']) &&
>> > empty($exists)) {
>> > $_SESSION['trying'] = 'The account was created.';
>> > } else {
>> > $_SESSION['trying'] = 'The account was not created!';
>> > }
>> > $this->redirect('/articles/result');
>>
>> > }
>>
>> > redirection still works
>>
>> > but after this much code
>>
>> > include ('..\others\definitions.php');
>> > mysql_connect("localhost", "root", "92506002") or die(mysql_error());
>>
>> > mysql_select_db("opinionsofamateurs") or die(mysql_error());
>> > $email=$_POST['email'];
>> > $password=$_POST['password'];
>> > $email=htmlentities($email);
>> > $email=mysql_real_escape_string($email);
>> > $password=htmlentities($password);
>> > $password=mysql_real_escape_string($password);
>> > $db_email=mysql_query("SELECT * FROM `accounts` WHERE email =
>> > '$email'");
>> > $db_email=mysql_fetch_row($db_email);
>> > $db_password=mysql_query("SELECT * FROM `accounts` WHERE email =
>> > '$email' AND password = '$password'");
>> > $db_password=mysql_fetch_row($db_password);
>> > if ($email != VALID_EMAIL)
>> > {
>>
>> > header("Location: create3.php?error=invalid_email");
>>
>> > } else if ($email == $db_email)
>> > {
>> > header("Location: create3.php?error=already_email");
>> > } else {
>> > if($password != VALID_PASSWORD)
>> > {
>> > header("Location: create3.php?error=invalid_password");
>> > } else if ($password == $db_password)
>> > {
>> > header("Location: create3.php?error=already_password");
>> > } else {
>> > mysql_query('INSERT INTO `accounts` VALUES (``, $email,
>> > $password)');
>> > }
>> > }
>> > mysql_close();
>>
>> > redirection does not work
>>
>> > Can anybody explain why?
>>
>> --
>> Sincerely yours,
>> Olexandr Melnykhttp://omelnyk.net/
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---