Jump to content

Archived

This topic is now archived and is closed to further replies.

LHBraun

Using IF to send user to another URL

Recommended Posts

Hello everybody - here is a PHP freshman in need of help :)

I am getting some data from a MySQL database and depending of the value of one of the variables I want to sent the user to one of 2 different URLs...

For example:
if $row["var"]=0 then send user to http://www.mydomain.com/page1.php
if $row["var"]=1 then send user to http://www.mydomain.com/page2.php

I just cannot find out how to do this - I assume I need to do it in the php part of the code?

Any help is much appreciated  ???

Share this post


Link to post
Share on other sites
You're looking for the header() function. http://www.php.net/header

Ken

Share this post


Link to post
Share on other sites
you want to use an if statement, yes

you can do this several ways

if($row["var"] == 0){
header("Location: http://www.example.com/page1.php");
}

if($row["var"] == 1){
header("Location: http://www.example.com/page2.php");
}

OR

switch($row["var"]){
case "0":
header("Location: http://www.example.com/page1.php");
break;
case "1":
header("Location: http://www.example.com/page2.php");
break;
default:
//do something else
}

Either way you need to have ob_start on line 1
<?php ob_start(); ?>

Share this post


Link to post
Share on other sites
I am sure you have heard of php.net
http://es2.php.net/manual/en/function.ob-start.php

Basicly, turns on Output Buffering (OB)
This allows you to send HTM headers mid way through a php script

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.