close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

PHP Redirect advice.

Thread began 3/08/2010 4:21 am by Nathon Jones Web Design | Last modified 3/08/2010 3:53 pm by Justin Nemeth | 1075 views | 3 replies |

Nathon Jones Web Design

PHP Redirect advice.

Hi. I'm just learning PHP in preparation for a switch from classic ASP.

One thing I do a lot in ASP is to redirect a user depending on the existance of content in one, or more, form fields submitted from the previous page.

<%
If Request.Form("Name") <> "" Then
Response.Redirect("fail.asp")
End If
%>

How is this done in PHP? Appreciate any advice. Thanks.

Regards
Nath.

Sign in to reply to this post

Justin Nemeth

You can use the header() function. So a redirect would look like this:

php:
<?php header('Location: fail.php'); ?>


I think the its the same as ASP, but just make sure you don't have any output before you call the header function. So no html or print statements basically.

-justin

Sign in to reply to this post

Nathon Jones Web Design

what about the form field?

Hi Justin.

Thanks for the input. Where though, in the example you've provided, does the PHP script check for the form field input?

In my ASP example, it checks to see if a form field entry, "Name", from the previous page, has a value before redirecting. In your example it looks like you are just redirecting, regardless of whether or not the "Name" field has a value.

Hope you can clarify that. Thanks.
Nath.

Sign in to reply to this post

Justin Nemeth

Oh, I thought you were asking specifically about the redirect line. The entire code would look like this, assuming you are posting the form.

php:
if(!empty($_POST['Name'])) { 
  header('Location: fail.php');
}



$_POST gives you an array of all the elements in your form. Similarily you can use $_GET if you your form method is GET. By using !empty() that is making sure the variable exists in the $_POST array and that is not "".

-justin

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...