hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Loading Another Page From PHP
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

Loading Another Page From PHP

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 09-01-2002, 09:20 PM
bvanderwerf bvanderwerf is offline
Junior Guru Wannabe
 
Join Date: Aug 2002
Posts: 35

Loading Another Page From PHP


I guess I should preface this by saying I am using the methodology of creating static HTML pages and sprinkling in PHP code as necessary. I know this may be considered Bad Practice, but I like using Dreamweaver templates and laying out my screens in a WYSIWYG editor.

So, using this methodogy, how does one load a specific page based on the results of a form?

Take, for example, a customer login screen. When the form is submitted, one of several pages might be presented to the user: an entry form if this is a new user, the desired page if the login is successful, the login form again (with an error message) if the e-mail can't be found or the password is bad, or an acknowledgement page if the customer requests the password be e-mailed to them.

In the script called when the form is submitted, I've been using a JavaScript window.location call to the right page, depending on what the customer selected, valid data, etc. It occurs to me that this is probably not the best solution (e.g. the user can turn JavaScript off), but what is?

Any feedback on my this subject would be appreciated.

--Bruce

Reply With Quote


Sponsored Links
  #2  
Old 09-01-2002, 10:50 PM
shaunewing shaunewing is offline
Premium Member
 
Join Date: Jun 2002
Location: Sydney, Australia
Posts: 1,744
You could use the Header to redirect the person dependent on variables.

I'll give a generic example using the variable $usrType which you can then alter to suit your needs.

PHP Code:
if($usrType == "newuser"
{
  
Header("Location: http://www.yoursite.com/newuser.php");
}
elseif(
$usrType == "verified")
{
  
Header("Location: http://www.yoursite.com/verified.php");
}
elseif(
$usrType == "badpwd")
{
  
Header("Location: http://www.yoursite.com/login.php");
}
else
{
  
Header("Location: http://www.yoursite.com/unknown.php");

Basically this shows how you can redirect to different pages depending on a certain condition which is what I assume you're after.

I should point out that the Header tag *must* be on your page before any text has been output to the user.

I hope that helps.

--Shaun

__________________
Shaun Ewing
http://shaun.net

Reply With Quote
  #3  
Old 09-01-2002, 11:31 PM
mind21_98 mind21_98 is offline
Web Hosting Master
 
Join Date: Dec 2000
Location: San Diego, CA
Posts: 1,571
If you use output buffering, you can put Header() anywhere, provided that it's in between ob_start() and ob_end_flush(). For instance:

<?php
ob_start();
echo "test text";
Header("Location: http://www.microsoft.com/");
ob_end_flush();
?>

__________________
-Mooneer
Thoughtbug Software: Hosting shouldn't require any thought.
Legitimate host? Support the Code of Ethical Conduct

Reply With Quote
Sponsored Links
  #4  
Old 09-01-2002, 11:33 PM
:: paVel :: :: paVel :: is offline
Web Hosting Guru
 
Join Date: Jul 2002
Location: Australia
Posts: 324
Hey,
Thats right, u can use Header() function to redirect users...
Here is some code that would check the fields in one script:
PHP Code:
if (!$username
{
   echo 
"USERNAME is empty"
}
else if (!
preg_match("/^[a-zA-Z0-9_-]+$/"$username))
{
   echo 
"Username can only contain latters and numbers";
}
else if (
strlen($username)>20 || strlen($username)<3
{
   echo 
"Username must be between 3-20 characters";
}
else if (
$pass!=$cpass
{
   echo 
"Passwords entered were not the same";
}
else if (!
eregi("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,3}$",$email) && $email != ""
{
   echo 
"E-mail adress that you entered is not valid";
}
else 
// if everything is OK
{
   
// DO something, if everything is correct.!

Hope that helps!

Reply With Quote
  #5  
Old 09-02-2002, 05:08 AM
apokalyptik apokalyptik is offline
Newbie
 
Join Date: Aug 2002
Posts: 19
Theres a really easy way to do that, condider:

index.html
Code:
<html>
<body>
<form method="get" action="select.php">
<input type="text" name="page" value="load.php">
<input type="submit">
</form>
</body>
</html>
select.php
Code:
<?php
switch ( $page ) {
 case 'info':
  include('./info.php');
  break;
 case 'menu':
  include('menu.php');
  break;
 case 'static':
  include('./static.html');
  break;
 default:
  include('index.html');
}
?>

__________________
irc.apokalyptik.com http://www.apokalyptik.com http://www.apokalyptik.com/forum/

Reply With Quote
  #6  
Old 09-02-2002, 08:31 AM
dreamrae.com dreamrae.com is offline
Web Hosting Master
 
Join Date: Aug 2002
Location: Baltimore, Maryland
Posts: 580
remember, cookies before using header(char i)

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
WiredTree Decreases Customer Website Loading Times with SSD Caching Web Hosting News 2013-04-02 13:56:08
1&1 Study Shows 72 Percent of US Online Shoppers Will Abandon Slow Sites for Competitors Web Hosting News 2012-07-13 16:18:05
Certified Hosting Deploys Varnish HTTP Caching for Faster Hosting Services Web Hosting News 2012-02-28 14:10:30
Host Color Offers Free CDN with Shared Web Hosting Web Hosting News 2011-12-19 16:30:09
Google Launches Page Speed CDN Service Web Hosting News 2011-07-28 20:39:17


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?