Solved

Redirecting a user

Posted on 2001-06-22
4
164 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 100 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Cookie not unsetting 7 27
PHP error function not working on AWS 10 67
what do I need to host my own web sites? 13 50
Extracting content from meta tag PHP MYHTML DOM 3 20
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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…
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…
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…

808 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