This is a discussion on Validation: Problems with header(Location) in PHP within the PHP General forums, part of the PHP Programming Forums category; On Wed, 2003-09-24 at 16:22, Martin Raychev wrote: > Hi! > > I am kind of newbie ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
On Wed, 2003-09-24 at 16:22, Martin Raychev wrote:
> Hi! > > I am kind of newbie coming from ASP and I came upon some hindrances, which > could be because of not knowing enough of PHP > > The problem is: > I am trying to make a form with good and user-friendly validation. After > failure to validate properly some of the fields and going to another page > i.e. the <form action="anotherpage.php"> I need to go back to the previos > page where the form is. > In ASP I would use Response.Redirect and that's it but the > > header (Location...) in PHP is said that it must be on top of the HTML page > before anything else. This doesn't seems to work for me. > > Does anyone has a solution to this problem? A simple, ignore the real problem, solution is to turn on output buffering. The real problem is that you probably have output occuring before the validation occurs, which is why you can't redirect. Solving this will prevent the need for output buffering. Another solution is, once you detect an error, to output a javascript redirect. This is probably the dirtiest IMHO. Cheers, Rob. -- ..------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `------------------------------------------------------------' |
|
|||
|
On Thursday 25 September 2003 04:22, Martin Raychev wrote:
> I am kind of newbie coming from ASP and I came upon some hindrances, which > could be because of not knowing enough of PHP > > The problem is: > I am trying to make a form with good and user-friendly validation. After > failure to validate properly some of the fields and going to another page > i.e. the <form action="anotherpage.php"> I need to go back to the previos > page where the form is. > In ASP I would use Response.Redirect and that's it but the > > header (Location...) in PHP is said that it must be on top of the HTML page > before anything else. This doesn't seems to work for me. What is your *exact* code and *how* does it not work? > Does anyone has a solution to this problem? Not unless we know what you're doing wrong. -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * ------------------------------------------ Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general ------------------------------------------ /* "Is it really you, Fuzz, or is it Memorex, or is it radiation sickness?" -- Sonic Disruptors comics */ |
|
|||
|
On Thursday 25 September 2003 06:58, Martin Raychev wrote:
> Thank you for answering me. I am sending the code that you requested. I've > shotened it for brevity. The idea is that I am going to make the validation > in the (2nd) "newaccount2.php" file which is the confirmation file. If > everything is OK I will just print the correct filled-in data. Otherwise I > would like to redirect the users back to the previous page [irrelevant code snip] In your original post you say that you had problems with redirecting using header(). Again, please: 1) describe *how* it's not working. 2) post the *relevant* code > I've surfed a little but found no ellegant validation solution so > far. There are plenty of ready-to-use validation classes at www.phpclasses.org -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * ------------------------------------------ Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general ------------------------------------------ /* 44. Say, What does "Superblock Error" mean, anyhow? --Top 100 things you don't want the sysadmin to say */ |
|
|||
|
HTTP 1.1 says the following:
1. Client (with web browser) sends GET request to server. 2. Server responds with something like: Content-type: text/html Content-size:...blah...blah...blah.... 3. Server sends the web page. The header is sent on #2. What is happening is that somewhere in the code you are outputting the HTML. So PHP reads: 1. Client (with web browser) sends GET request to server. 2. Server responds with something like: Content-type: text/html Content-size:...blah...blah...blah.... 3. Server sends the web page. 4. Server responds with something like: Redirect (or whatever it is) Content-type: text/html Content-size:...blah...blah...blah.... But because step 2 (which is also step 4) can only happen once, PHP outputs an error. You need to locate the snippet of code outputting anything first, and disable it. Of course, I will not get into whether or not hiding headers from the user is a good idea. (In some forms of CGI scripting you would actually have to type: print "Content-type: text/html\n\n" before doing anything else.) -Dan |
|
|||
|
On Wed, 2003-09-24 at 20:46, Martin Raychev wrote:
> Hi Jason, > > it's not the code snip that is important but the fact that I DO have to have > header(Location...) statement BEFORE anything else on the second php page. This is incorrect. You MUST have the header( ... ) BEFORE any statement that OUTPUTS to the BROWSER :) Feel free to validate before the header, but don't output any content INCLUDING whitespace. Cheers, Rob. > How can I do this since in order to validate form data with PHP I have to > have validating code and the header statement to appear later, i.e. not > first? > > Thank you, > > Martin. > > ----- Original Message ----- > From: "Jason Wong" <php-general@gremlins.biz> > Newsgroups: php.general > To: <php-general@lists.php.net> > Sent: Tuesday, September 23, 2003 6:10 PM > Subject: Re: [php] Validation: Problems with header(Location) in PHP > > > > On Thursday 25 September 2003 06:58, Martin Raychev wrote: > > > > > Thank you for answering me. I am sending the code that you requested. > I've > > > shotened it for brevity. The idea is that I am going to make the > validation > > > in the (2nd) "newaccount2.php" file which is the confirmation file. If > > > everything is OK I will just print the correct filled-in data. Otherwise > I > > > would like to redirect the users back to the previous page > > > > [irrelevant code snip] > > > > In your original post you say that you had problems with redirecting using > > header(). > > > > Again, please: > > > > 1) describe *how* it's not working. > > 2) post the *relevant* code > > > > > I've surfed a little but found no ellegant validation solution so > > > far. > > > > There are plenty of ready-to-use validation classes at www.phpclasses.org > > > > > > -- > > Jason Wong -> Gremlins Associates -> www.gremlins.biz > > Open Source Software Systems Integrators > > * Web Design & Hosting * Internet & Intranet Applications Development * > > ------------------------------------------ > > Search the list archives before you post > > http://marc.theaimsgroup.com/?l=php-general > > ------------------------------------------ > > /* > > 44. Say, What does "Superblock Error" mean, anyhow? > > > > --Top 100 things you don't want the sysadmin to say > > */ > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- ..------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `------------------------------------------------------------' |
|
|||
|
On Thursday 25 September 2003 08:46, Martin Raychev wrote:
This is exasperating as well as a waste of time! > it's not the code snip that is important Of course it is important. It is *your* code which is causing something which *ought to work* to not work. > but the fact that I DO have to > have header(Location...) statement BEFORE anything else on the second php > page. How can I do this since in order to validate form data with PHP I > have to have validating code and the header statement to appear later, i.e. > not first? The manual explains quite clearly how and where you should put the header() statement. -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * ------------------------------------------ Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general ------------------------------------------ /* No matter which way you have to march, its always uphill -- Murphy's Military Laws n�66 */ |
|
|||
|
Hi!
I am kind of newbie coming from ASP and I came upon some hindrances, which could be because of not knowing enough of PHP The problem is: I am trying to make a form with good and user-friendly validation. After failure to validate properly some of the fields and going to another page i.e. the <form action="anotherpage.php"> I need to go back to the previos page where the form is. In ASP I would use Response.Redirect and that's it but the header (Location...) in PHP is said that it must be on top of the HTML page before anything else. This doesn't seems to work for me. Does anyone has a solution to this problem? Many thanks in advance! Martin. |
|
|||
|
Hi Jason,
Thank you for answering me. I am sending the code that you requested. I've shotened it for brevity. The idea is that I am going to make the validation in the (2nd) "newaccount2.php" file which is the confirmation file. If everything is OK I will just print the correct filled-in data. Otherwise I would like to redirect the users back to the previous page ("newaccount1.php"). <html> <title>This is newaccount1.php</title> <form name="form1" method="post" action="newaccount2.php"> <input name="Dosubmit" type="hidden" value="0" id="Hidden1"> Name <input type="text" name="Name" id="name" size="30" /><br /> <input type="text" name="Email" size="30" /><br /> Street Address <input type="text" name="Address" id="Address" size="30" /><br /> <input type="submit" value="Next" /> </form> </body> </html> Btw, for the functionality I want to achieve is it better that I submit the data to the same form ($php_self)? It would probably be better as I'll avoid redirecting to and back all the time. I've surfed a little but found no ellegant validation solution so far. Thank you very much, Martin. |
|
|||
|
Hi Jason,
it's not the code snip that is important but the fact that I DO have to have header(Location...) statement BEFORE anything else on the second php page. How can I do this since in order to validate form data with PHP I have to have validating code and the header statement to appear later, i.e. not first? Thank you, Martin. ----- Original Message ----- From: "Jason Wong" <php-general@gremlins.biz> Newsgroups: php.general To: <php-general@lists.php.net> Sent: Tuesday, September 23, 2003 6:10 PM Subject: Re: [php] Validation: Problems with header(Location) in PHP > On Thursday 25 September 2003 06:58, Martin Raychev wrote: > > > Thank you for answering me. I am sending the code that you requested. I've > > shotened it for brevity. The idea is that I am going to make the validation > > in the (2nd) "newaccount2.php" file which is the confirmation file. If > > everything is OK I will just print the correct filled-in data. Otherwise I > > would like to redirect the users back to the previous page > > [irrelevant code snip] > > In your original post you say that you had problems with redirecting using > header(). > > Again, please: > > 1) describe *how* it's not working. > 2) post the *relevant* code > > > I've surfed a little but found no ellegant validation solution so > > far. > > There are plenty of ready-to-use validation classes at www.phpclasses.org > > > -- > Jason Wong -> Gremlins Associates -> www.gremlins.biz > Open Source Software Systems Integrators > * Web Design & Hosting * Internet & Intranet Applications Development * > ------------------------------------------ > Search the list archives before you post > http://marc.theaimsgroup.com/?l=php-general > ------------------------------------------ > /* > 44. Say, What does "Superblock Error" mean, anyhow? > > --Top 100 things you don't want the sysadmin to say > */ |
|
|||
|
Got a client site in Thailand that is about 13 hours
different from the Web Server time so with any date/time stamping I need to add the 13 hours. However, when it comes time for DST, I'd hate to have to code for that or remember to manually change the time stamping. Is there some kind of automated function that determines the time zone of one location to another and stamps the correct time -- with or without DST? I guess otherwise you'd have to do something like: if > Oct 31st and < April XX { time+12 } else { time+13 Obviously not the correct code but that's the idea. Am I off base here? Is there a simpler method or something I'm not thinking of? If the server was dedicated I would just fix the server time to be Thailand time, but it's a shared server and I can't do that. Thanks in advance! __________________________________ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com |