Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

code to redirect user to a new tab and new page if browser is IE

Posted on 2012-08-24
12
Medium Priority
?
593 Views
Last Modified: 2012-08-28
Hi

I'm looking for code either in PHP or javascript that will detect if a browser is IE and if so, pop open a new window or TAB and redirect the user to specific link

thanks a ton
0
Comment
Question by:markgal26
  • 6
  • 5
11 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 38331546
This is a teaching example that I have used successfully in the past.  See if the pattern makes sense for your app.

<?php // RAY_browser_detect.php
error_reporting(E_ALL);
echo "<pre>";

// SHOW A PIECE OF THE SERVER ARRAY
var_dump($_SERVER["HTTP_USER_AGENT"]);
var_dump($_SERVER["HTTP_ACCEPT"]);

// SOME BROWSERS
$firefox  = strpos($_SERVER['HTTP_USER_AGENT'],"Firefox");
$ie       = strpos($_SERVER['HTTP_USER_AGENT'],"MSIE");
$opera    = strpos($_SERVER['HTTP_USER_AGENT'],"Opera");
$ns       = strpos($_SERVER['HTTP_USER_AGENT'],"Netscape");
$safari   = strpos($_SERVER['HTTP_USER_AGENT'],"Safari");
$chrome   = strpos($_SERVER['HTTP_USER_AGENT'],"Chrome");

// REPORT
$browser = FALSE;
if ($firefox)
{
    $browser = "Firefox";
}
if ($ie)
{
    $browser = "IE";
}
if ($opera)
{
    $browser = "Opera";
}
if ($ns)
{
    $browser = "Netscape";
}
if ($safari)
{
    $browser = "Safari";
}
if ($chrome)
{
    $browser = "Chrome";
}

if (!$browser)
{
    $browser = $_SERVER['HTTP_USER_AGENT'];
}
echo PHP_EOL;
echo $browser;
echo PHP_EOL;

// FLASH DETECTION
$flash = FALSE;
if(stripos($_SERVER['HTTP_ACCEPT'], "application/x-shockwave-flash"))
{
    $flash = TRUE;
}
var_dump($flash);

Open in new window

HTH, ~Ray
0
 

Author Comment

by:markgal26
ID: 38331551
Thanks for the reply.  where do I add the link I want the page to re-direct to? And will it pop-up a new window when it does? thanks again
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 38331564
If you're not familiar with PHP, this book might be helpful:
http://www.sitepoint.com/books/phpmysql5/

And PHP.net has its own tutorials:
http://us3.php.net/tut.php

If any of this is too much or otherwise confusing, please be respectful of your time and consider the advantages of hiring a PHP professional to write the code for you.  You can find the pros at elance.com and other similar sites.  I believe that time is money and I never waste time on something I do not understand at a professional level.

HTH, ~Ray
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:markgal26
ID: 38331611
Ray - I appreciate your thoughtful replies.  I'm close to getting it right, just don't have the part that tells it to open a new window.  I'm betting there is something I can stick is this code that will redirect it to a new windows/tab and not refresh it it in the same window

<!--[if IE]>
  <meta http-equiv="refresh" content="0;http://www.mysite.com/iesplash/">
<![endif]-->
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 38332186
You might be able to use JavaScript.  Window.open() could work.
http://www.quirksmode.org/js/popup.html
http://www.w3schools.com/jsref/met_win_open.asp
0
 

Author Comment

by:markgal26
ID: 38332654
I will play with java and get back to you, thx again. If you come up with anything for PHP let me know. cheers
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 38332725
PHP can be used to send JavaScript (not the same thing as Java, the language) from the server to the client.  Here is an example of how to do that:

<?php // RAY_temp_markgal26.php


// JAVASCRIPT TO OPEN A NEW WINDOW FROM http://www.w3schools.com/jsref/met_win_open.asp
$js = <<<JS
<script>
window.open('http://www.LAPRBass.com/RAY_iesplash.php', 'popUp', 'width=200,height=200');
</script>
JS;


// DETECT INTERNET EXPLORER
if (strpos($_SERVER['HTTP_USER_AGENT'],"MSIE"))
{
    // ACTIVATE THIS TO LOAD THE SCRIPT IN THE SAME WINDOW
    // echo ' <meta http-equiv="refresh" content="0;http://www.LAPRBass.com/RAY_iesplash.php">';
    
    // THROW THE JAVASCRIPT TO THE BROWSER
    echo $js;
}
else
{
    echo 'YOU ARE NOT USING MSIE';
}

Open in new window

<?php // RAY_iesplash.php
echo "YOU ARE USING IE";

Open in new window

HTH, ~Ray
0
 

Author Closing Comment

by:markgal26
ID: 38342433
Thanks for the help here.  This is enough to get me where I need to be and I'll post back when its complete
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 38342998
Please see the grading guidelines:
http://www.experts-exchange.com/help/viewHelpPage.jsp?helpPageID=26

Since I gave you at tested and working code sample, please explain why you marked the grade down without telling me what was wrong.  I think the question was answered.  What was I missing?
0
 

Author Comment

by:markgal26
ID: 38343054
i meant to put A, must have hit B by accident or tabbed to it.  Let me try to fix
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 38343076
Thanks.  A moderator can fix it for you.  Hit the Request Attention link near the original post.

Glad I hadn't misunderstood the question!
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

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…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to count occurrences of each item in an array.
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

564 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