Solved

Redirecting a user

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
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…
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.

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now