Jump to content


Photo

Using IF to send user to another URL


  • Please log in to reply
5 replies to this topic

#1 LHBraun

LHBraun
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 19 August 2006 - 04:45 PM

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  ???

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 19 August 2006 - 05:17 PM

You're looking for the header() function. http://www.php.net/header

Ken

#3 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 19 August 2006 - 05:20 PM

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(); ?>

Tell me the problem, I will try tell you the solution

#4 LHBraun

LHBraun
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 20 August 2006 - 08:32 PM

Thanks - super duper help  ;D It works perfectly  :-*

#5 slipperyfish

slipperyfish
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 20 August 2006 - 09:19 PM

what's ob_start() ???

#6 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 20 August 2006 - 10:35 PM

I am sure you have heard of php.net
http://es2.php.net/m...on.ob-start.php

Basicly, turns on Output Buffering (OB)
This allows you to send HTM headers mid way through a php script
Tell me the problem, I will try tell you the solution




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users