Re: [PHP] Error when execute header('location: otherpage.php') after email been sent out. Any Workaround?

2009-08-28 Thread hack988 hack988
Some Php's tigger info output to client before you set header.try this
code first
---
ob_start();//first line write this code
some code for your self
header(location:index.php);
ob_end_flush();
---
second.
You must check php.ini found that if flush implicit option turn on.
implicit_flush = On
=
implicit_flush = Off

test your codes again.

If codes run correctly,check your codes line by lines ,found that such
as 'echo','print'... and so on before 'you
header(location:index.php)' line.
2009/8/28 Keith survivor_...@hotmail.com:
 I have a user sign up page that collects sign up information from user with
 form.
 This form will then be submitted to another process.php page for setting up
 the user account and send email to the user.
 After the email been sent out, the user will be directed back to homepage
 with header(location: index.php).
 However, error happen with warning: [Cannot modify header information -
 headers already sent by...]
 Any workaround for this?

 Thanks for help!
 Keith



 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Error when execute header('location: otherpage.php') after email been sent out. Any Workaround?

2009-08-28 Thread Ashley Sheridan
On Fri, 2009-08-28 at 17:32 +0800, Keith wrote:
 I have a user sign up page that collects sign up information from user with 
 form.
 This form will then be submitted to another process.php page for setting up 
 the user account and send email to the user.
 After the email been sent out, the user will be directed back to homepage 
 with header(location: index.php).
 However, error happen with warning: [Cannot modify header information - 
 headers already sent by...]
 Any workaround for this?
 
 Thanks for help!
 Keith
  
 
 

You don't need a workaround. The header(Location...) thing will only
work if you have not sent any content to the browser yet. That includes
even a single space or newline.

It looks like in your process.php page, something is being output to the
browser. Are you able to do a code dump of that page?

Thanks,
Ash
http://www.ashleysheridan.co.uk




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Error when execute header('location: otherpage.php') after email been sent out. Any Workaround?

2009-08-28 Thread Floyd Resler
Another solution would be to use JavaScript.  In your process.php  
script you could do this:

printhere
script language=javascript
window.location.href=index.php
/script
here;

Not strictly a PHP solution but it works.

Take care,
Floyd

On Aug 28, 2009, at 5:34 AM, Ashley Sheridan wrote:


On Fri, 2009-08-28 at 17:32 +0800, Keith wrote:
I have a user sign up page that collects sign up information from  
user with

form.
This form will then be submitted to another process.php page for  
setting up

the user account and send email to the user.
After the email been sent out, the user will be directed back to  
homepage

with header(location: index.php).
However, error happen with warning: [Cannot modify header  
information -

headers already sent by...]
Any workaround for this?

Thanks for help!
Keith





You don't need a workaround. The header(Location...) thing will only
work if you have not sent any content to the browser yet. That  
includes

even a single space or newline.

It looks like in your process.php page, something is being output to  
the

browser. Are you able to do a code dump of that page?

Thanks,
Ash
http://www.ashleysheridan.co.uk




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Error when execute header('location: otherpage.php') after email been sent out. Any Workaround?

2009-08-28 Thread Martin Scotta
On Fri, Aug 28, 2009 at 9:36 AM, Floyd Resler fres...@adex-intl.com wrote:

 Another solution would be to use JavaScript.  In your process.php script
 you could do this:
 printhere
 script language=javascript
window.location.href=index.php
 /script
 here;

 Not strictly a PHP solution but it works.

 Take care,
 Floyd


 On Aug 28, 2009, at 5:34 AM, Ashley Sheridan wrote:

  On Fri, 2009-08-28 at 17:32 +0800, Keith wrote:

 I have a user sign up page that collects sign up information from user
 with
 form.
 This form will then be submitted to another process.php page for setting
 up
 the user account and send email to the user.
 After the email been sent out, the user will be directed back to homepage
 with header(location: index.php).
 However, error happen with warning: [Cannot modify header information -
 headers already sent by...]
 Any workaround for this?

 Thanks for help!
 Keith




 You don't need a workaround. The header(Location...) thing will only
 work if you have not sent any content to the browser yet. That includes
 even a single space or newline.

 It looks like in your process.php page, something is being output to the
 browser. Are you able to do a code dump of that page?

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk




 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


Actually there aren't a safe way to make a redirect. Every technique relies
on the client-side to perform the redirection.

We have 4 alternatives (correct me if I miss anything) to do a safe
redirection.

   1. header Location
   2. meta tag refresh
   3. javascript
   4. the user


We will try every one in the given order...

Let's suppose we want to redirect the client to $url...

?php

session_write_close();
header( 'Location: '. $url ); # redirect by http header (1)

?html
head
titleRedirecting.../title

!-- redirect by meta tag (2) --
meta http-equiv=refresh content=2;url=?php echo $url? /

script type=text/javascript/*![CDATA[*/
// redirect by javascript (3)
window.location = '?php echo $url ?';
/*]]*//script

/head
body
pYou are about to be redirected to ?php echo $url? in 2
seconds/p
p
!-- redirect by user (4) --
a href=?php echo $url?
Click here if your browser do not redirect automatically
/a
/p
/body
/html
?php exit; ?


It's recommended that your use a common redirect method in your site, this
is not mandatory but it is a good practice.

This simple script also helps to prevent session problems under some evil
web-server by closing the session before any output.



-- 
Martin Scotta


Re: [PHP] Error when execute header('location: otherpage.php') after email been sent out. Any Workaround?

2009-08-28 Thread Ashley Sheridan
On Fri, 2009-08-28 at 10:34 -0300, Martin Scotta wrote:
 Actually there aren't a safe way to make a redirect 
 
 We have 4 alternatives (correct me if I miss anything) to do a safe
 redirection.

Erm wtf?!

The best bet is always going with a header() redirect. The only time
I've seen that fail is when the developer of the PHP script has made a
mistake. The browser should always honor this type of redirect, and you
have none of the issues with Javascript turned off, browser plugins
blocking redirects, or stupid users etc.

Thanks,
Ash
http://www.ashleysheridan.co.uk




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Error when execute header('location: otherpage.php') after email been sent out. Any Workaround?

2009-08-28 Thread Keith

Hi all,
Yes, you are right, it was due to echo for testing purpose not been 
commented out prior to header().
However, there is hidden root cause too --  PHPMailer will echo invalid 
address to the screen.
When I have tested with 1 valid email address and 1 invalid with 
someth...@locahost, PHPMailer will echo out the invalid someth...@localhost.
However, in this case, $mail-send() still will return value of TRUE as long 
as at least 1 email been sent out.
After I have commented out all these [echo], no more header issue occur 
again.


It's works too using Floyd's recommended javascript! However, the message 
will echoed out first before redirect to index.php, but this is fast enough 
to be neglectable.


I have one more question regarding error logging.
I have set as below:

ini_set('log_errors', 1);
ini_set('error_log', http://domain.com/log/logfile.txt;);
ini_set('error_reporting', 'E_ALL');
ini_set('error_append_string', '\r\n');

I have simulated an error which can be displayed on screen because I've put 
ini_set('display_errors',1).

However, the error was not been logged.

Which format should I used for log file? *.log or *.txt?

Since I'm using third party web hosting, I can only access web directory, 
should I use

[http://domain.com/log/logfile.*] or
[C:\some_path\domain.com\log\logfile.*] or just
[/log/logfile.*]?

Thanks!
Keith


Floyd Resler fres...@adex-intl.com wrote in message 
news:a536e452-54a2-4f55-8ae0-28e875a59...@adex-intl.com...
Another solution would be to use JavaScript.  In your process.php  script 
you could do this:

printhere
script language=javascript
window.location.href=index.php
/script
here;

Not strictly a PHP solution but it works.

Take care,
Floyd

On Aug 28, 2009, at 5:34 AM, Ashley Sheridan wrote:


On Fri, 2009-08-28 at 17:32 +0800, Keith wrote:
I have a user sign up page that collects sign up information from  user 
with

form.
This form will then be submitted to another process.php page for 
setting up

the user account and send email to the user.
After the email been sent out, the user will be directed back to 
homepage

with header(location: index.php).
However, error happen with warning: [Cannot modify header  information -
headers already sent by...]
Any workaround for this?

Thanks for help!
Keith





You don't need a workaround. The header(Location...) thing will only
work if you have not sent any content to the browser yet. That  includes
even a single space or newline.

It looks like in your process.php page, something is being output to  the
browser. Are you able to do a code dump of that page?

Thanks,
Ash
http://www.ashleysheridan.co.uk




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php






--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Error when execute header('location: otherpage.php') after email been sent out. Any Workaround?

2009-08-28 Thread Martin Scotta
On Fri, Aug 28, 2009 at 10:39 AM, Ashley Sheridan
a...@ashleysheridan.co.ukwrote:

 On Fri, 2009-08-28 at 10:34 -0300, Martin Scotta wrote:
  Actually there aren't a safe way to make a redirect
 
  We have 4 alternatives (correct me if I miss anything) to do a safe
  redirection.

 Erm wtf?!

 The best bet is always going with a header() redirect. The only time
 I've seen that fail is when the developer of the PHP script has made a
 mistake. The browser should always honor this type of redirect, and you
 have none of the issues with Javascript turned off, browser plugins
 blocking redirects, or stupid users etc.

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk




What you are is truth if it only applies to computer browsers.
There are many clients where the Location header don't work.

Curl is a good example, you can determine to follow the Redirect or just
skip it.
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false)

Another example could be mobile phones, especially wml based, do not follow
a redirection and you have to provide a click here to redirect link and
relies on the user to follow the redirection.

Do not trust that your client is always a browser. It could be anything that
can open a connection and send a request.

Also you can't know who is at the other side. The client can provide fake
UA, IP, everything... or can't send anything but the need to make a valid
request.

-- 
Martin Scotta


Re: [PHP] Error when execute header('location: otherpage.php') after email been sent out. Any Workaround?

2009-08-28 Thread Stuart
2009/8/28 Martin Scotta martinsco...@gmail.com:
 On Fri, Aug 28, 2009 at 10:39 AM, Ashley Sheridan
 a...@ashleysheridan.co.ukwrote:

 On Fri, 2009-08-28 at 10:34 -0300, Martin Scotta wrote:
  Actually there aren't a safe way to make a redirect
 
  We have 4 alternatives (correct me if I miss anything) to do a safe
  redirection.

 Erm wtf?!

 The best bet is always going with a header() redirect. The only time
 I've seen that fail is when the developer of the PHP script has made a
 mistake. The browser should always honor this type of redirect, and you
 have none of the issues with Javascript turned off, browser plugins
 blocking redirects, or stupid users etc.

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk




 What you are is truth if it only applies to computer browsers.
 There are many clients where the Location header don't work.

 Curl is a good example, you can determine to follow the Redirect or just
 skip it.
 curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false)

 Another example could be mobile phones, especially wml based, do not follow
 a redirection and you have to provide a click here to redirect link and
 relies on the user to follow the redirection.

 Do not trust that your client is always a browser. It could be anything that
 can open a connection and send a request.

 Also you can't know who is at the other side. The client can provide fake
 UA, IP, everything... or can't send anything but the need to make a valid
 request.

In the realm of assumptions made by developers, that the client
understands and will correctly process a 301/302 response is one of
the safer assumptions. It's certainly safer than assuming the client
will respect a meta tag or javascript.

If you really try to deal with every possible client to that extent
you'll never ship anything. Yes it's important to be as supportive as
possible, but care should be taken to pick the battles that are worth
fighting.

-Stuart

-- 
http://stut.net/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Error when execute header('location: otherpage.php') after email been sent out. Any Workaround?

2009-08-28 Thread Ben Dunlap
 Which format should I used for log file? *.log or *.txt?

Doesn't matter to PHP -- but you do need to provide a local path, not a URL.

 [http://domain.com/log/logfile.*] or

No...

 [C:\some_path\domain.com\log\logfile.*] or just

Yes!

Ben

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Error when execute header('location: otherpage.php') after email been sent out. Any Workaround?

2009-08-28 Thread Ashley Sheridan
On Fri, 2009-08-28 at 09:28 -0700, Ben Dunlap wrote:
  Which format should I used for log file? *.log or *.txt?
 
 Doesn't matter to PHP -- but you do need to provide a local path, not a URL.
 
  [http://domain.com/log/logfile.*] or
 
 No...
 
  [C:\some_path\domain.com\log\logfile.*] or just
 
 Yes!
 
 Ben
 
You should try and put the log somewhere that is not in the web root, to
prevent anyone from accessing it and getting information which could
help a hack.


Thanks,
Ash
http://www.ashleysheridan.co.uk




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Error when execute header('location: otherpage.php') after email been sent out. Any Workaround?

2009-08-28 Thread Keith

Ash, Ben, Thanks!

For my web server, I can access to:
./httpdocs
./httpsdocs

all the http documents are stored inside httpdocs and SSL documents inside 
httpsdocs.
The web root you mean here is referred to ./httpdocs and ./httpsdocs or the 
parent directory of them?
If I  put the logfile inside ./log/logfile.txt where ./log is same level as 
./httpdocs, can the web users access it?


Thanks!
Keith


Ashley Sheridan a...@ashleysheridan.co.uk wrote in message 
news:1251477059.27899.117.ca...@localhost...

On Fri, 2009-08-28 at 09:28 -0700, Ben Dunlap wrote:

 Which format should I used for log file? *.log or *.txt?

Doesn't matter to PHP -- but you do need to provide a local path, not a 
URL.


 [http://domain.com/log/logfile.*] or

No...

 [C:\some_path\domain.com\log\logfile.*] or just

Yes!

Ben


You should try and put the log somewhere that is not in the web root, to
prevent anyone from accessing it and getting information which could
help a hack.


Thanks,
Ash
http://www.ashleysheridan.co.uk





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php