Beginning PHPBeginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
trying to display browser specific
this is what i have dont so for but gettting error message.
what i want to script to do is to direct the user to a new page based on whether the browser is IE or something else
just started learning php 2days ago so i dont not if i need an if else statement to do this
when ever i run the code i keep getting error message
Warning: preg_match() [function.preg-match]: Unknown modifier '1' in C:\broot\do_redirect.php on line 4
Warning: Cannot modify header information - headers already sent by (output started at C:\Webroot\do_redirect.php:4) in C:\broot\do_redirect.php on line
<?php
$agent = getenv("http_user_agent");
if (preg_match ("/msie/1", "$agent")) {
$result = "you are using microsoft internet explorer.";
}
else if (preg_match ("/mozilla/i", "$agent")) {
$result = " you are using netscape.";
}
else {
$result = "you are using $agent";
}
// set location if provided from form, else set it to default page:
$location = (!empty($_POST['location'])) ? $_POST['location'] :
"http://www.msn.com/";
"http://www.microsoft.com/";
"http://www.expedia.com/";
"http://www.aol.com/";
"http://www.yahoo.com/";
"http://www.netscape.com/";
// go to that page:
header("Location: $location");
?>
Why you use if or else loop.There is no Need To use this
You simply write this code it will provide you the whole
information about your browser and OS
<?php
$agent = getenv("http_user_agent");
$result = "you are using $agent";
echo $result;
Hello Dear
You Should Have Declear Header before
any echo/print statment or before any HTML tag
and before Header you can not live any blank line
I hope so it's solve your problem