It looks like you're mixing up Javascript and PHP.
document.referrer
is Javascript and
include
is PHP.
Since Javascript happens on the client, you would need to either display a page containing your Javascript code and redirect to another to get the effect you want, or do it all in PHP where you can use the include command:
<?php
if(isset($_SERVER['HTTP_REFERER']) &&
strpos($_SERVER['HTTP_REFERER'],'http://oursite.com') === 0) {
include "index2.php";
} else {
include "mobiledetection.php";
}
?>
You should also note that the referrer is not reliable - the browser does not have to send it, so you should decide what to do if you don't know where the visitor has come from.
For testing, you can disable sending referrer details using the Web Developer FireFox add-on.