Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7005861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:24:16+00:00 2026-05-27T21:24:16+00:00

I have put together a mobile website for us, and have the main site,

  • 0

I have put together a mobile website for us, and have the main site, madisonstudios.com, redirecting to the mobile site, madisonstudios.mobi, if the device is a mobile device.

I also put a full website button on the mobile site, and when the referrer is the mobile site, it sets a cookie, but I had a problem with still having it redirecting on the first click to the full site, and then once you clicked it the second time it went to the full website.

To solve this issue I added a variable of $setcookie and set it to 1, so to make it skip the redirect. My code below.

I think this is a kind of messy way to do this, and think that there has to be a cleaner way, does anyone have a suggestion that would make sense for me to use. Am I going about this the right way?

<?php
if($_SERVER['HTTP_REFERER'] == "http://www.madisonstudios.mobi/" || $_SERVER['HTTP_REFERER'] == "http://madisonstudios.mobi/")
{
    setcookie('fromMobi', true, time()+3600*24);
    $setcookie = 1;
}

if ($_COOKIE["fromMobi"] == 1 || $setcookie == 1)
{

} else {
    $uamatches = array("midp", "j2me", "avantg", "docomo", "novarra", "palmos", "palmsource", "240x320", "opwv", "chtml", "pda", "windows\ ce", "mmp\/", "blackberry", "mib\/", "symbian", "wireless", "nokia", "hand", "mobi", "phone", "cdm", "up\.b", "audio", "SIE\-", "SEC\-", "samsung", "HTC", "mot\-", "mitsu", "sagem", "sony", "alcatel", "lg", "erics", "vx", "NEC", "philips", "mmm", "xx", "panasonic", "sharp", "wap", "sch", "rover", "pocket", "benq", "java", "pt", "pg", "vox", "amoi", "bird", "compal", "kg", "voda", "sany", "kdd", "dbt", "sendo", "sgh", "gradi", "jb", "\d\d\di", "moto","webos");

    foreach($uamatches as $uastring){
    if(preg_match("/".$uastring."/i",$_SERVER["HTTP_USER_AGENT"]))
    {
    header('Location: http://www.madisonstudios.mobi');
    }
    }
}
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:24:17+00:00Added an answer on May 27, 2026 at 9:24 pm

    I would do this:

    <?php
    
      // Use stripos() for tidiness, case-insensitivity and ignoring subdomains and paths
      if (stripos($_SERVER['HTTP_REFERER'],'madisonstudios.mobi') !== FALSE) {
    
        // We came from mobi, set the cookie that says so
        setcookie('fromMobi', true, time()+3600*24);
    
      } else if (empty($_COOKIE["fromMobi"])) {
        // We only do this if the cookie is not set or it has a value that evaluates
        // to FALSE - empty() does this check for us in one go
    
        // Look for mobile browsers and redirect them to mobi
        $uamatches = array("midp", "j2me", "avantg", "docomo", "novarra", "palmos", "palmsource", "240x320", "opwv", "chtml", "pda", "windows\ ce", "mmp\/", "blackberry", "mib\/", "symbian", "wireless", "nokia", "hand", "mobi", "phone", "cdm", "up\.b", "audio", "SIE\-", "SEC\-", "samsung", "HTC", "mot\-", "mitsu", "sagem", "sony", "alcatel", "lg", "erics", "vx", "NEC", "philips", "mmm", "xx", "panasonic", "sharp", "wap", "sch", "rover", "pocket", "benq", "java", "pt", "pg", "vox", "amoi", "bird", "compal", "kg", "voda", "sany", "kdd", "dbt", "sendo", "sgh", "gradi", "jb", "\d\d\di", "moto","webos");
        foreach ($uamatches as $uastring) {
          if (preg_match("/".$uastring."/i",$_SERVER["HTTP_USER_AGENT"])) {
            header('Location: http://www.madisonstudios.mobi/');
            // If we find one we know we can exit straight away because the user
            // is getting redirected
            exit;
          }
        }
    
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, I'm wondering if any of you have put together a for-profit e-commerce site
Trying to do a simple web app with jquery mobile. I have put together
I have put together an example page detailing my problem My website is going
I have put together a script where the main image loads once clicked on
I have put together a small ASP.NET MVC 2 site that does some very
I have put together a navigation bar which expands a submenu on hover. See
I have put together a .net winform application which consumes a wcf service exposed
I have put together an API that responds to a POST request by putting
I have put together an image scroller using jquery, like this function rotateImages(whichHolder, start)
I am a powershell novice. After days of searching.... I have put together a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.