Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Redirecting a user

Posted on 2001-06-22
4
Medium Priority
?
169 Views
Last Modified: 2012-05-04
Hello,
I would like, depending on their browser version, to redirect users to another URL (say, if their browser won't support layers,...). Anybody can help?
For info, here's the script I have so far written.

<html>
<head>
<title>Test?</title>
<?php    
$r=$HTTP_USER_AGENT;
$regexp="Mozilla/4";
if (ereg($regexp, $r, $reg)) echo "Good!!<p>";
elseif (!ereg($regexp, $r, $reg))
{
Header("Location: http://www.php.net");
}
?>
</head>
<body>

The browser you use is <?php echo $HTTP_USER_AGENT; ?>

</body>
</html>

Why won't it work
0
Comment
Question by:philbrom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 15

Expert Comment

by:a.marsh
ID: 6220082
First thing - you will get a warning because you have given output to the browser before attempting to redirect using a HTTP header....

I honestly think you should do this on the client side - use Javascript.

What browsers do you need to test for and hence redirect to different pages? If you provide the necessary information I can put the javascript together for you.

:o)

Ant
0
 

Accepted Solution

by:
Curieux earned 400 total points
ID: 6220245
Your file should look like this (BEGIN AT THE FIRST LINE).

-----------------TOP of the page------------------------
<?php    
$r=$HTTP_USER_AGENT;
$regexp="Mozilla/4";
if (ereg($regexp, $r, $reg)) echo "Good!!<p>";
elseif (!ereg($regexp, $r, $reg))
{
Header("Location: http://www.php.net");
}
?>
<html>
<head>
<title>Test?</title>
</head>
<body>

The browser you use is <?php echo $HTTP_USER_AGENT; ?>

</body>
</html>
-----------------------End of script -------------------

it will redirect if $regexp<>"Mozilla/4" for example

I hope this helps  ;)

0
 
LVL 5

Expert Comment

by:harwantgrewal
ID: 6221736
Use javascript I think it will help you if you want I will provide you code

Harry
0
 
LVL 15

Expert Comment

by:a.marsh
ID: 6221887
Did you read my comment harwantgrewal?

:o\

Ant
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question