View Full Version : php if statement help
bobby2guns2003
November 6th, 2005, 15:44
Hey, I would I make a php if statement that would do this:
if $forumid = 11 then redirect to www.example.com
Tree
November 6th, 2005, 17:16
As long as you haven't had any output on that page, try
if ($forumid == 11)
{
header("Location: http://www.example.com");
}
robert allen
November 7th, 2005, 11:38
if ($forumid == 11)
{
header("Location: http://www.example.com");
}
The above is your code, should it be this below? (Semi colon at the end of line 1)
if ($forumid == 11);
{
header("Location: http://www.example.com");
}
themoose
November 7th, 2005, 12:08
lol, you like picking holes in Tree NC's code, dont you? :D :P
robert allen
November 7th, 2005, 12:22
lol, you like picking holes in Tree NC's code, dont you? :D :P
No, i was pointing it out so that the thread starter does not have bad code on there site which will cause errors.
R4g1ng
November 8th, 2005, 07:17
if ($forumid == 11)
{
header("Location: http://www.example.com");
}
The above is your code, should it be this below? (Semi colon at the end of line 1)
if ($forumid == 11);
{
header("Location: http://www.example.com");
}
No, it shouldn't. You don't have a semi-colon with functions that have {} like while, if, else etc. Only what's inside the {}
Tree
November 8th, 2005, 09:39
Putting a semi-colon after the if statement would return a parse error. On some more-lenient servers, it might just terminate the if statement.
Canuckkev
November 8th, 2005, 11:30
And keep in mind you can only use the "header" function to redirect if there has been no HTML output yet.
R4g1ng
November 8th, 2005, 21:23
^ Or cookie/session setting
ryza
November 12th, 2005, 23:01
Hey, I would I make a php if statement that would do this:
if $forumid = 11 then redirect to www.example.com
maybe something like this could work:
<?php
/* predefined list of available url redirects - could also be array from database*/
$urls=array();
$urls[1]="http://www.google.com";
$urls[2]="http://www.freewebspace.net";
$urls[3]="http://www.deluxnetwork.com";
if(isset($id)){
$url=$urls[$id];
if($url==""){
header("Location: http://www.default.com/");
}
else{
header("Location: $urls[$id]");
}
}
?>
keith
November 13th, 2005, 10:04
if ($forumid == 11)
{
header("Location: http://www.example.com");
}
The above is your code, should it be this below? (Semi colon at the end of line 1)
if ($forumid == 11);
{
header("Location: http://www.example.com");
}
Wow. You know absolutely nothing about PHP syntax, do you?
R4g1ng
November 13th, 2005, 11:25
I don't think that was necessary. One of the most basic rules of PHP is to have a semi-colon at the end of things, with some exceptions. If he just started learning, he might've not known that.
hostndomain
November 28th, 2005, 04:51
if ($forumid == 11)
{
header("Location: http://www.example.com");
}
is OK but if you see some HTML headers ERROR just add this line on start of the page before any code and html.
ob_start();
Tree
November 28th, 2005, 09:38
Um, this thread should have died 15 days ago...
Powered by vBulletin® Version 4.1.7 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.