Where do I put the script?

Installing and configuring Tera-WURFL on your server.

Where do I put the script?

Postby IMSM » Thu Jan 27, 2011 10:38 am

Hi,
I am the proverbial "Least Common Denominator;" I have very little technical background and experience. So I'll apologize up-front for my seemingly elementary question(s) and I ask for your patience with me.

With that being said, the tera-WURFL project appears to be exactly what I'm looking for. My goal is to redirect my mobile visitor, when they visit my http://www.SITEURL.com to my http://www.m.SITEURL.com.

I've gone through the installation of tera-WURFL and it's up and running. At least on the back end.

I'm hitting a wall as to exactly where on my index.html page I put the script? Or for that matter, should I be using .html in the first place? Or should I be using a .php file as the index page?
Also, the example I saw at gotoandlearn.com shows the script being place ABOVE everything. As in, it starts on the first line. This is a little confusing to me as most of my experience tells me that this script should NOT go that high on the page, but if I'm wrong, so-be-it.

Here is the script I'm attempting to run:

Code: Select all
<?php
require_once './TeraWurfl.php';
$wurflObj = new TeraWurfl();
$wurflObj->getDeviceCapabilitiesFromAgent();

// see if this client is on a wireless device
if($wurflObj->getDeviceCapability("is_wireless_device")){
   header("Location: http://www.m.SITEURL.com/");
}
?>

Where SITEURL is my site.

Bottom line:
Where do I put the script?
Thanks,
IMSM
IMSM
 
Posts: 5
Joined: Thu Jan 27, 2011 9:57 am

Re: Where do I put the script?

Postby IMSM » Sun Jan 30, 2011 6:51 pm

I think I figured it out.
I pretty much just followed what the guy at gotoandlearn.com posted.
Here's the code:
Code: Select all
<?php

require_once("Tera-Wurfl/TeraWurfl.php");
$wurflObj = new TeraWurfl();
$wurflObj->getDeviceCapabilitiesFromAgent();
$isWireless = $wurflObj->getDeviceCapability("is_wireless_device");

if($isWireless)
   header("location: http://www.m.mobideviceads.com");

?>


Now... where I put it mattered.
I created an index.php file.
I put the code all the way at the top.

Code: Select all
<?php

require_once("Tera-Wurfl/TeraWurfl.php");
$wurflObj = new TeraWurfl();
$wurflObj->getDeviceCapabilitiesFromAgent();
$isWireless = $wurflObj->getDeviceCapability("is_wireless_device");

if($isWireless)
   header("location: http://www.m.mobideviceads.com");

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Mobi Device Ads - Mobile Advertising</title>
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-7257505-13']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
</head>

<body>
</body>
</html>


Frustrating to say the least, but I think I figured it out.
Hope that helps others.
IMSM
 
Posts: 5
Joined: Thu Jan 27, 2011 9:57 am

Re: Where do I put the script?

Postby kamermans » Fri Feb 04, 2011 2:05 pm

Hi - sorry about the slow response, somehow I missed the notification about this topic. The key here is understanding the difference between server-side scripts and client-side scripts. PHP is a server-side scripting language and is evaluated before anything is sent to the client (browser). For this reason, you can place PHP wherever you want on the page; however, if you are redirecting someone to another page it must be at the top of the page, otherwise the content above the script may get sent to the browser before the redirect request is sent - this is a bad thing and, depending on your PHP config, may throw and error on your page. The reason you need to use the .php extension is that it tells your webserver that this is a PHP script and it needs to be evaluated as such. Putting PHP code on a .html page will simply send it to the browser which is not capable of evaluating it, so it will just be printed on the screen.
Thanks,

Steve Kamerman
Tera-WURFL Author
COO of ScientiaMobile

IMPORTANT ANNOUNCEMENT! Tera-WURFL and WURFL have joined forces! We have launched ScientiaMobile to provide commercial support for our device detection solutions.

Tera-WURFL.com | Device Explorer
kamermans
Site Admin
 
Posts: 323
Joined: Wed Mar 10, 2010 12:06 pm
Location: Fort Worth, TX

Re: Where do I put the script?

Postby IMSM » Mon Feb 28, 2011 3:52 pm

I apologize if this is a dupe, but I did not see my earlier post... if it is, please delete.

My page: mobideviceads dot com/pbma dot html is showing code on the page... what did I do wrong?

Please take a look at the code and tell me.
Thanks.
IMSM
 
Posts: 5
Joined: Thu Jan 27, 2011 9:57 am


Return to Installation / Configuration

Who is online

Users browsing this forum: No registered users and 4 guests

cron