Jump to content

Using IF to send user to another URL


LHBraun

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  ???
Link to comment
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(); ?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.