Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Redirecting a user

Posted on 2001-06-22
4
Medium Priority
?
170 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
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

783 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