question about header and validation

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

i have a question about using header("Location: filename.html"); in

with my present code i have a few echo statements followed by
header("Location: filename.html"); because i have echo

statements before header("Location: filename.html"); i am getting an
error that headers have already been sent. i cannot

remove the echo statements as they are doing an important task. based
on this situation i can use echo followed by the html

code for the filename in filename.html if i do this the code will run
into a few 100's of lines and due to this i would like

to use header("Location: filename.html");

i have tried the following code and it works =

echo " <form name='errorpage' action='error.php' method='post'> </
       <script type='text/javascript' language='javascript'>
document.errorpage.submit(); </script> ";
however if javascript is turned off this redirection will not work.

could you please suggest if there is an alternative to using echo
statement first followed by
header("Location: filename.html");

i am using the following php validation for forms which is not working
very well

$specialcharacters = '#^([a-zA-Z0-9]+)$#';
with this code for a name if i type "first name" with a space it is
considering the space and treating as a special character

however it should validate for letters and numbers only. how can i
write '/^[a-zA-Z]+$/'; to ignore spaces

$firstnamecheck = '/^[a-zA-Z]+$/';
with this code if i type for example "first name" as per the error is
states that the string needs to contain letters. though

i typed letters because of the space it is not treating as letters.
how can i rewrite this '/^[a-zA-Z]+$/';

please advice.


Re: question about header and validation


For 1, you can do require('filename.html') to insert that text into
your page.

For 2, add a space character inside the brackets to match spaces as


John Peters

Quoted text here. Click to load it

Re: question about header and validation

Sudhakar wrote:
Quoted text here. Click to load it

Why do you have echo statements which would never be seen if the
redirect is performed?  At worst, you might get a flash on the screen,
but unless you have a really slow link, you'll never be able to read it.

Quoted text here. Click to load it

If you're going to do the redirect, don't do the echo's.  As noted
above, they would serve no purpose.

Your javascript will work, but only if the user has javascript enabled.

Quoted text here. Click to load it

Add \s inside the brackets if you want any whitespace (tab, etc.), or
just a space character if all you want is spaces.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: question about header and validation


Quoted text here. Click to load it

First thing: The Location URI must be absolute as required by HTTP.

Quoted text here. Click to load it

How can they be important, if they will never be seen? You should re-
order your code and keep the branching logic on top.

Another option would be to use output buffering, but in this case it
would be just another workaround for a bad code design.

Quoted text here. Click to load it

Ugly. Such hacks are never a solution and just cause more problems.

Quoted text here. Click to load it

I'm not sure I can follow you. What do you expect the regular
expressions to do? The first one does exactly what you've described - it
validates for letters and numbers only. If there's any other char, it
wouldn't match. So what's the problem?


Site Timeline