SitePoint Sponsor |
|
User Tag List
Results 1 to 9 of 9
Thread: Redirection based on browswer
-
Apr 3, 2005, 23:45 #1
- Join Date
- Apr 2005
- Posts
- 4
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Redirection based on browswer
I'm new to PHP and I am trying to get a redirection to work based on if the user has Firefox or Internet Explorer. So far I have:
<?php
$browser = get_browser( null, true )
if( $browser['browser'] == 'Firefox' )
{
header('location: ff.htm');
}
else
{
header('location: ie.htm');
?>
But upon loading it, the redirection won't happen. The host I have uses .php4, don't know if it makes a difference. Any help is greatly appreciated!
-
Apr 4, 2005, 01:03 #2
- Join Date
- Mar 2005
- Location
- The Netherlands
- Posts
- 73
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
you need another semicolon, and another '}'. Like this:
<?php
$browser = get_browser( null, true );
if( $browser['browser'] == 'Firefox' )
{
header('location: ff.htm');
}
else
{
header('location: ie.htm');
}
?>There is no signature...
-
Apr 4, 2005, 01:09 #3
What does print_r($browser) tell you?
Are you suppressing php warnings? I just did a test locally, and got this: "Warning: get_browser(): browscap ini directive not set."
-
Apr 4, 2005, 15:01 #4
- Join Date
- Apr 2005
- Posts
- 4
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Well, that code works now, except it doesn't redirect based on broswer properly. It automatically fails the if statement and goes to else. I'm assuming it's a browser name problem. I tried getting browser info and inputing various things for browser name, but didn't have any luck. What should Firefox and MSIE be called so they will be detected properly?
-
Apr 4, 2005, 15:10 #5
- Join Date
- Aug 2003
- Location
- Manchester, UK
- Posts
- 4,007
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Why not echo it as a test and see what it's set to?
echo $browser['browser'];
exit;
-
Apr 4, 2005, 15:47 #6
- Join Date
- May 2004
- Location
- Oxford, UK
- Posts
- 138
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I've never really liked or trusted the get_browser() function. Normally I'd use something like this instead:
PHP Code:if ((isset($_SERVER['HTTP_USER_AGENT'])) && (strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== false)) {
// The user has Firefox
}
-
Apr 4, 2005, 18:37 #7
- Join Date
- Apr 2005
- Posts
- 4
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I have this now:
<?php
if ((isset($_SERVER['HTTP_USER_AGENT'])) && (strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== false)) {
// The user has Firefox
{
header('location: ff.htm');
}
else
{
header('location: ie.htm');
}
?>
-
Apr 4, 2005, 18:43 #8
- Join Date
- Oct 2004
- Location
- United states
- Posts
- 663
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
try this
<?php
if ((isset($_SERVER['HTTP_USER_AGENT'])) && (strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== false)) {
// The user has Firefox
header('location: ff.htm');
}
else
{
header('location: ie.htm');
}
?>Valentine's Day Gift for your girl,
but you have to know her size
have a nice day then.
-
Apr 4, 2005, 20:06 #9
- Join Date
- Apr 2005
- Posts
- 4
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Wooo! It works now, thank you very much!
Bookmarks