Install code samples
From Mocean Mobile Wiki
Contents |
Getting the Site/Zone ids
- Go to the respective network http://*.moceanmobile.net
- Click on 'Publisher Sites & Content'
- Click on 'Manage' for the desired site/app
- Click on 'Code'
PHP install code
<?php
// change to "live" to disable demo mode and show real ads
define("MOCEANV2_MODE", "live");
function moceanv2_ad()
{
$ua = $_SERVER['HTTP_USER_AGENT'];
$ip = (stristr($ua,"opera mini") && array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER))
? trim(end(split(",", $_SERVER['HTTP_X_FORWARDED_FOR'])))
: $_SERVER['REMOTE_ADDR'];
// prepare url parameters of request
$moceanv2_get = 'site='.urlencode('85');
$moceanv2_get .= '&ip='.urlencode($ip);
$moceanv2_get .= '&ua='.urlencode($ua);
$moceanv2_get .= '&url='.urlencode(sprintf("http%s://%s%s", (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == TRUE ? "s": ""), $_SERVER["HTTP_HOST"], $_SERVER["REQUEST_URI"]));
$moceanv2_get .= '&zone='.urlencode('85');
$moceanv2_get .= '&adstype=3'; // type of ads (1 - text only, 2 - images only, 3 - text + images, 6 - sms)
$moceanv2_get .= '&key=1';
//$moceanv2_get .= '&lat=1';
//$moceanv2_get .= '&long=1';
$moceanv2_get .= '&count=1'; // quantity of ads
$moceanv2_get .= '&version='.urlencode('php_0001'); // php code version
$moceanv2_get .= '&keywords='; // keywords to search ad delimited by commas (not necessary)
$moceanv2_get .= '&over_18=0'; // filter by ad over 18 content (0 or 1 - deny over 18 content , 2 - only over 18 content, 3 - allow all ads including over 18 content)
$moceanv2_get .= '¶mBORDER='.urlencode('#000000'); // ads border color
$moceanv2_get .= '¶mHEADER='.urlencode('#cccccc'); // header color
$moceanv2_get .= '¶mBG='.urlencode('#eeeeee'); // background color
$moceanv2_get .= '¶mTEXT='.urlencode('#000000'); // text color
$moceanv2_get .= '¶mLINK='.urlencode('#ff0000'); // url color
//check UID
if ( isset($_COOKIE['MOCEAN_AD_UDID']) ) {
if(setcookie('MOCEAN_AD_UDID', $_COOKIE['MOCEAN_AD_UDID'], time() + 60 * 60 * 24 * 7)) {
$moceanv2_get .= '&udid='.urlencode($_COOKIE['MOCEAN_AD_UDID']);
}
} else {
$udid = md5(time()+rand());
if(setcookie('MOCEAN_AD_UDID', $udid, time() + 60 * 60 * 24 * 7)) {
$moceanv2_get .= '&udid='.urlencode($udid);
}
}
if(MOCEANV2_MODE == "test") $moceanv2_get .= '&test=1';
// send request
$moceanv2_request = @fsockopen('ads.mocean.mobi', 80, $errno, $errstr, 1);
if ($moceanv2_request) {
stream_set_timeout($moceanv2_request, 3000);
$query = "GET /ad?".$moceanv2_get." HTTP/1.0\r\n";
$query .= "Host: ads.mocean.mobi\r\n";
$query .= "Connection: close\r\n";
// IIS support
if(isset($_SERVER['ALL_HTTP']) && is_array($_SERVER['ALL_HTTP'])) {
foreach ($_SERVER['ALL_HTTP'] as $name => $value) {
$query .= "CS_$name: $value\r\n";
}
}
elseif(isset($_SERVER['ALL_HTTP'])) {
$array = explode("\n",$_SERVER['ALL_HTTP']);
foreach ($array as $value) {
if($value) {
$query .= "CS_$value\r\n";
}
}
}
foreach ($_SERVER as $name => $value) {
$query .= "CS_$name: $value\r\n";
}
$query .= "\r\n";
fwrite($moceanv2_request, $query);
$moceanv2_info = stream_get_meta_data($moceanv2_request);
$moceanv2_timeout = $moceanv2_info['timed_out'];
$moceanv2_contents = "";
$moceanv2_body = false;
$moceanv2_head = "";
while (!feof($moceanv2_request) && !$moceanv2_timeout) {
$moceanv2_line = fgets($moceanv2_request);
if(!$moceanv2_body && $moceanv2_line == "\r\n") $moceanv2_body = true;
if(!$moceanv2_body) $moceanv2_head .= $moceanv2_line;
if($moceanv2_body && !empty($moceanv2_line)) $moceanv2_contents .= $moceanv2_line;
$moceanv2_info = stream_get_meta_data($moceanv2_request);
$moceanv2_timeout = $moceanv2_info['timed_out'];
}
fclose($moceanv2_request);
if (!preg_match('/^HTTP\/1\.\d 200 OK/', $moceanv2_head)) $moceanv2_timeout = true;
if($moceanv2_timeout) return "";
return $moceanv2_contents;
}
}
?>
<?php
// copy this snippet elsewhere on your page for display more of ads
echo moceanv2_ad();
?>
PHP CURL install code
<?php
// change to "live" to disable demo mode and show real ads
define("MOCEANV2_MODE", "test");
function moceanv2_ad()
{
$ua = $_SERVER['HTTP_USER_AGENT'];
$ip = (stristr($ua,"opera mini") && array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER))
? trim(end(split(",", $_SERVER['HTTP_X_FORWARDED_FOR'])))
: $_SERVER['REMOTE_ADDR'];
// prepare url parameters of request
$moceanv2_get = 'site='.urlencode('85');
$moceanv2_get .= '&ip='.urlencode($ip);
$moceanv2_get .= '&ua='.urlencode($ua);
$moceanv2_get .= '&url='.urlencode(sprintf("http%s://%s%s", (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == TRUE ? "s": ""), $_SERVER["HTTP_HOST"], $_SERVER["REQUEST_URI"]));
$moceanv2_get .= '&zone='.urlencode('85');
$moceanv2_get .= '&adstype=3'; // type of ads (1 - text only, 2 - images only, 3 - text + images, 6 - sms)
$moceanv2_get .= '&key=1';
//$moceanv2_get .= '&lat=1';
//$moceanv2_get .= '&long=1';
$moceanv2_get .= '&count=1'; // quantity of ads
$moceanv2_get .= '&keywords='; // keywords to search ad delimited by commas (not necessary)
$moceanv2_get .= '&over_18=0'; // filter by ad over 18 content (0 or 1 - deny over 18 content , 2 - only over 18 content, 3 - allow all ads including over 18 content)
$moceanv2_get .= '¶mBORDER='.urlencode('#000000'); // ads border color
$moceanv2_get .= '¶mHEADER='.urlencode('#cccccc'); // header color
$moceanv2_get .= '¶mBG='.urlencode('#eeeeee'); // background color
$moceanv2_get .= '¶mTEXT='.urlencode('#000000'); // text color
$moceanv2_get .= '¶mLINK='.urlencode('#ff0000'); // url color
//check UID
if ( isset($_COOKIE['MOCEAN_AD_UDID']) ) {
if(setcookie('MOCEAN_AD_UDID', $_COOKIE['MOCEAN_AD_UDID'], time() + 60 * 60 * 24 * 7)) {
$moceanv2_get .= '&udid='.urlencode($_COOKIE['MOCEAN_AD_UDID']);
}
} else {
$udid = md5(time()+rand());
if(setcookie('MOCEAN_AD_UDID', $udid, time() + 60 * 60 * 24 * 7)) {
$moceanv2_get .= '&udid='.urlencode($udid);
}
}
if(MOCEANV2_MODE == "test") $moceanv2_get .= '&test=1';
$sc_headers = array();
foreach ($_SERVER as $name => $value) {
$sc_headers[] = "CS_$name: $value";
}
// send request
$url="http://ads.mocean.mobi:80/ad?".$moceanv2_get;
$timeout=3; //timeout in seconds
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $sc_headers);
$html=@curl_exec($ch);
@curl_close($ch);
if($html!==false) return $html;
else return "";
}
?>
<?php
// copy this snippet elsewhere on your page for display more of ads
echo moceanv2_ad();
?>
JSP install code
<%@ page import="java.util.*,java.io.*,java.net.*, java.security.*, java.math.*" %>
<%
// copy this snippet elsewhere on your page for display more of ads
out.print(moceanv2_ad(request));
%>
<%!
// change to "live" to disable demo mode and show real ads
private static final String MOCEANV2_MODE = "test";
private String moceanv2_ad(HttpServletRequest request)
{
StringBuilder moceanv2_contents = new StringBuilder();
try {
// prepare url parameters of request
StringBuilder moceanv2_get = new StringBuilder();
moceanv2_get.append("site=").append("85");
moceanv2_get.append("&ua=").append(URLEncoder.encode(request.getHeader("User-Agent"), "UTF-8"));
moceanv2_get.append("&ip=").append(URLEncoder.encode(request.getRemoteAddr(),"UTF-8"));
moceanv2_get.append("&url=").append(URLEncoder.encode(request.getRequestURL().toString(), "UTF-8"));
moceanv2_get.append("&zone=").append("85");
moceanv2_get.append("&adstype=3"); // type of ads (1 - text only, 2 - images only, 3 - text + images, 6 - sms)
moceanv2_get.append("&key=1");
//moceanv2_get.append("&lat=1");
//moceanv2_get.append("&long=1");
moceanv2_get.append("&keywords="); // keywords to search ad delimited by commas (not necessary)
moceanv2_get.append("&country="); // country of visitor
moceanv2_get.append("®ion="); // region of visitor
moceanv2_get.append("&size_required=0"); // if img size attributes are required
moceanv2_get.append("¶mBORDER=").append(URLEncoder.encode("#000000", "UTF-8")); // ads border color
moceanv2_get.append("¶mHEADER=").append(URLEncoder.encode("#cccccc", "UTF-8")); // header color
moceanv2_get.append("¶mBG=").append(URLEncoder.encode("#eeeeee", "UTF-8")); // background color
moceanv2_get.append("¶mTEXT=").append(URLEncoder.encode("#000000", "UTF-8")); // text color
moceanv2_get.append("¶mLINK=").append(URLEncoder.encode("#ff0000", "UTF-8")); // url color
if(MOCEANV2_MODE.equals("test")) moceanv2_get.append("&test=1");
// send request
BufferedReader moceanv2_reader = null;
try {
URL moceanv2_url = new URL("http://ads.mocean.mobi:80/ad");
HttpURLConnection moceanv2_request = (HttpURLConnection)moceanv2_url.openConnection();
moceanv2_request.setRequestMethod("POST");
moceanv2_request.setDoOutput(true);
moceanv2_request.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
moceanv2_request.setRequestProperty("Content-Length", Integer.toString(moceanv2_get.length()));
Enumeration e = request.getHeaderNames();
if(e != null && e.hasMoreElements()) {
while(e.hasMoreElements()) {
String hdr = (String) e.nextElement();
moceanv2_request.addRequestProperty("ch_"+hdr,request.getHeader(hdr));
}
}
moceanv2_request.setConnectTimeout(3000);
moceanv2_request.setReadTimeout(3000);
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(moceanv2_request.getOutputStream()));
writer.write(moceanv2_get.toString());
writer.close();
moceanv2_reader = new BufferedReader(new InputStreamReader(moceanv2_request.getInputStream()));
for (String line = null; (line = moceanv2_reader.readLine()) != null;)
moceanv2_contents.append(line);
} catch(java.net.SocketTimeoutException ste) {
moceanv2_contents.append("");
} catch (Exception e) {
} finally {
try {
if(moceanv2_reader != null) {
moceanv2_reader.close();
}
} catch(Exception e) {
}
}
} catch(Exception ex) {
}
return moceanv2_contents.toString();
}
%>
ASP install code
<%
'copy this snippet elsewhere on your page for display more of ads
Response.Write(moceanv2Ad())
%>
<script runat="server" language="vbs">
Function moceanv2Ad()
'change to "live" to disable demo mode and show real ads
Dim MOCEANV2_MODE
MOCEANV2_MODE = "test"
'prepare url parameters of request
On Error Resume Next
Dim moceanv2_page_url
If (Request.ServerVariables("HTTPS") = "off") Then moceanv2_page_url = "http://" Else moceanv2_page_url = "https://" End If
moceanv2_page_url = moceanv2_page_url & Request.ServerVariables("HTTP_HOST")
moceanv2_page_url = moceanv2_page_url & Request.ServerVariables("PATH_INFO")
Dim moceanv2_get
moceanv2_get = "site=" & "85"
moceanv2_get = moceanv2_get & "&ua=" & Server.URLEncode(Request.ServerVariables("HTTP_USER_AGENT"))
moceanv2_get = moceanv2_get & "&ip=" & Server.URLEncode(Request.ServerVariables("REMOTE_ADDR"))
moceanv2_get = moceanv2_get & "&url=" & Server.URLEncode(moceanv2_page_url)
moceanv2_get = moceanv2_get & "&zone=85"
moceanv2_get = moceanv2_get & "&adstype=3" 'type of ads (1 - text only, 2 - images only, 3 - text + images, 6 - sms)
moceanv2_get = moceanv2_get & "&key=1"
'moceanv2_get = moceanv2_get & "&lat=1"
'moceanv2_get = moceanv2_get & "&long=1"
moceanv2_get = moceanv2_get & "&keywords=" ' keywords to search ad delimited by commas (not necessary)
moceanv2_get = moceanv2_get & "&over_18=0" 'filter by ad over 18 content (0 or 1 - deny over 18 content , 2 - only over 18 content, 3 - allow all ads including over 18 content)
moceanv2_get = moceanv2_get & "&count=1" 'quantity of ads
moceanv2_get = moceanv2_get & "¶mBORDER=" & Server.URLEncode("#000000") 'ads border color
moceanv2_get = moceanv2_get & "¶mHEADER=" & Server.URLEncode("#cccccc") 'header color
moceanv2_get = moceanv2_get & "¶mBG=" & Server.URLEncode("#eeeeee") 'background color
moceanv2_get = moceanv2_get & "¶mTEXT=" & Server.URLEncode("#000000") 'text color
moceanv2_get = moceanv2_get & "¶mLINK=" & Server.URLEncode("#ff0000") 'url color
If MOCEANV2_MODE = "test" Then moceanv2_get = moceanv2_get & "&test=1" End If
'send request
Response.Buffer = True
Dim moceanv2_request
Set moceanv2_request = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
moceanv2_request.setTimeouts 3000, 3000, 3000, 3000
moceanv2_request.Open "GET", "http://ads.mocean.mobi:80/ad?" & moceanv2_get, False
moceanv2_request.setRequestHeader "Content-Type","application/x-www-form-urlencoded"
moceanv2_request.Send
moceanv2Ad = moceanv2_request.responseText
Set moceanv2_request = Nothing
Err.clear
If Err.number <> 0 Then
moceanv2Ad = ""
End If
End Function
</script>
CGI/PERL install code
use LWP::UserAgent;
use URI::URL;
# copy this snippet elsewhere on your page for display more of ads
print moceanv2_ad();
sub moceanv2_ad
{
# change to "live" to disable demo mode and show real ads
my $moceanv2_mode = 'test';
# prepare url parameters of request
my $moceanv2_page_url = sprintf('http%s://%s%s',($ENVHTTPS ne '' ? 's': ''), $ENVHTTP_HOST, $ENVREQUEST_URI);
my %moceanv2_get = (
'site' => 85,
'ua' => $ENVHTTP_USER_AGENT,
'ip' => $ENVREMOTE_ADDR,
'url' => $moceanv2_page_url,
'zone' => '85',
'adstype' => '3', # type of ads (1 - text only, 2 - images only, 3 - text + images, 6 - sms)
'key' => '1',
#'lat' => '1',
#'long' => '1',
'count' => '1',
'keywords' => "", # keywords to search ad delimited by commas (not necessary)
'over_18' => '0', # filter by ad over 18 content (0 or 1 - deny over 18 content , 2 - only over 18 content, 3 - allow all ads including over 18 content)
'paramBORDER' => '#000000', # ads border color
'paramHEADER' => '#cccccc', # header color
'paramBG' => '#eeeeee', # background color
'paramTEXT' => '#000000', # text color
'paramLINK' => '#ff0000', # url color
);
$moceanv2_gettest = '1' if($moceanv2_mode eq 'test');
# send request
my $moceanv2_uri = URI::URL->new("http://ads.mocean.mobi:80/ad");
my $moceanv2_request = LWP::UserAgent->new;
$moceanv2_request->timeout(3);
my $moceanv2_response = $moceanv2_request->post($moceanv2_uri, \%moceanv2_get);
if ($moceanv2_response->is_error()) {
return "";
} else {
return $moceanv2_response->content();
}
}
VB.NET install code
<%
'copy this snippet elsewhere on your page for display more of ads
Response.Write(moceanv2_ad())
%>
<script runat="server">
Function moceanv2_ad() As String
'change to "live" to disable demo mode and show real ads
Dim MOCEANV2_MODE As String = "test"
'prepare url parameters of request
Dim moceanv2_get As StringBuilder = New StringBuilder()
moceanv2_get.Append("site=").Append("85")
moceanv2_get.Append("&ua=").Append(HttpUtility.UrlEncode(Request.UserAgent, Encoding.UTF8))
moceanv2_get.Append("&ip=").Append(HttpUtility.UrlEncode(Request.UserHostAddress, Encoding.UTF8))
moceanv2_get.Append("&url=").Append(HttpUtility.UrlEncode(Request.Url.ToString(), Encoding.UTF8))
moceanv2_get.Append("&zone=").Append(HttpUtility.UrlEncode("85", Encoding.UTF8))
moceanv2_get.Append("&adstype=3") 'type of ads (1 - text only, 2 - images only, 3 - text + images, 6 - sms)
moceanv2_get.Append("&keywords=") ' keywords to search ad delimited by commas (not necessary)
moceanv2_get.Append("&whitelabel=0") ' filter by whitelabel(0 - all, 1 - only whitelabel, 2 - only non-whitelabel)
moceanv2_get.Append("&premium=0") ' filter by premium status (0 - non-premium, 1 - premium only, 2 - both)
moceanv2_get.Append("&over_18=0") ' filter by ad over 18 content (0 or 1 - deny over 18 content , 2 - only over 18 content, 3 - allow all ads including over 18 content)
moceanv2_get.Append("&key=1")
'moceanv2_get.Append("&lat=1")
'moceanv2_get.Append("&long=1")
moceanv2_get.Append("&count=1") 'quantity of ads
moceanv2_get.Append("¶mBORDER=").Append(HttpUtility.UrlEncode("#000000", Encoding.UTF8)) 'ads border color
moceanv2_get.Append("¶mHEADER=").Append(HttpUtility.UrlEncode("#cccccc", Encoding.UTF8)) 'header color
moceanv2_get.Append("¶mBG=").Append(HttpUtility.UrlEncode("#eeeeee", Encoding.UTF8)) 'background color
moceanv2_get.Append("¶mTEXT=").Append(HttpUtility.UrlEncode("#000000", Encoding.UTF8)) 'text color
moceanv2_get.Append("¶mLINK=").Append(HttpUtility.UrlEncode("#ff0000", Encoding.UTF8)) 'url color
If MOCEANV2_MODE = "test" Then moceanv2_get.Append("&test=1")
'send request
Dim moceanv2_contents As StringBuilder = New StringBuilder()
Try
Dim moceanv2_get_bytes As Byte() = System.Text.Encoding.UTF8.GetBytes(moceanv2_get.ToString)
Dim moceanv2_request As System.Net.WebRequest = System.Net.WebRequest.Create("http://ads.mocean.mobi:80/ad")
moceanv2_request.Method = "POST"
moceanv2_request.ContentType = "application/x-www-form-urlencoded"
moceanv2_request.ContentLength = moceanv2_get_bytes.Length()
moceanv2_request.Timeout = 3000
Dim moceanv2_os As System.IO.Stream = moceanv2_request.GetRequestStream()
moceanv2_os.Write(moceanv2_get_bytes, 0, moceanv2_get_bytes.Length())
moceanv2_os.Close()
Dim moceanv2_response As System.Net.HttpWebResponse = CType(moceanv2_request.GetResponse, System.Net.HttpWebResponse)
Dim moceanv2_ios As System.IO.Stream = moceanv2_response.GetResponseStream()
Dim moceanv2_reader As System.IO.StreamReader = New System.IO.StreamReader(moceanv2_ios)
moceanv2_contents.Append(moceanv2_reader.ReadToEnd())
Catch moceanv2_e As Exception
moceanv2_contents.Append("")
End Try
Return moceanv2_contents.ToString()
End Function
</script>
C# install code
<%
// copy this snippet elsewhere on your page for display more of ads
Response.Write(moceanv2_ad());
%>
<script runat="server">
// change to "live" to disable demo mode and show real ads
const string MOCEANV2_MODE = "test";
string moceanv2_ad()
{
// prepare url parameters of request
StringBuilder moceanv2_get = new StringBuilder();
moceanv2_get.Append("site=").Append("85");
moceanv2_get.Append("&ua=").Append(HttpUtility.UrlEncode(Request.UserAgent, Encoding.UTF8));
moceanv2_get.Append("&ip=").Append(HttpUtility.UrlEncode(Request.UserHostAddress, Encoding.UTF8));
moceanv2_get.Append("&url=").Append(HttpUtility.UrlEncode(Request.Url.ToString(), Encoding.UTF8));
moceanv2_get.Append("&zone=").Append(HttpUtility.UrlEncode("85", Encoding.UTF8));
moceanv2_get.Append("&adstype=3"); // type of ads (1 - text only, 2 - images only, 3 - text + images, 6 - sms)
moceanv2_get.Append("&key=1");
//moceanv2_get.Append("&lat=1");
//moceanv2_get.Append("&long=1");
moceanv2_get.Append("&keywords="); // keywords to search ad delimited by commas (not necessary)
moceanv2_get.Append("&over_18=0"); // filter by ad over 18 content (0 or 1 - deny over 18 content , 2 - only over 18 content, 3 - allow all ads including over 18 content)
moceanv2_get.Append("&count=1"); // quantity of ads
moceanv2_get.Append("¶mBORDER=").Append(HttpUtility.UrlEncode("#000000", Encoding.UTF8)); // ads border color
moceanv2_get.Append("¶mHEADER=").Append(HttpUtility.UrlEncode("#cccccc", Encoding.UTF8)); // header color
moceanv2_get.Append("¶mBG=").Append(HttpUtility.UrlEncode("#eeeeee", Encoding.UTF8)); // background color
moceanv2_get.Append("¶mTEXT=").Append(HttpUtility.UrlEncode("#000000", Encoding.UTF8)); // text color
moceanv2_get.Append("¶mLINK=").Append(HttpUtility.UrlEncode("#ff0000", Encoding.UTF8)); // url color
if (MOCEANV2_MODE == "test") moceanv2_get.Append("&test=1");
// send request
StringBuilder moceanv2_contents = new StringBuilder();
try {
byte[] moceanv2_get_bytes = System.Text.Encoding.UTF8.GetBytes(moceanv2_get.ToString());
System.Net.WebRequest moceanv2_request = System.Net.WebRequest.Create("http://ads.mocean.mobi:80/ad");
moceanv2_request.Method = "POST";
moceanv2_request.ContentType = "application/x-www-form-urlencoded";
moceanv2_request.ContentLength = moceanv2_get_bytes.Length;
moceanv2_request.Timeout = 3000;
System.IO.Stream moceanv2_os = moceanv2_request.GetRequestStream();
moceanv2_os.Write(moceanv2_get_bytes, 0, moceanv2_get_bytes.Length);
moceanv2_os.Close();
System.Net.HttpWebResponse moceanv2_response = (System.Net.HttpWebResponse)moceanv2_request.GetResponse();
System.IO.StreamReader moceanv2_reader = new System.IO.StreamReader(moceanv2_response.GetResponseStream());
moceanv2_contents.Append(moceanv2_reader.ReadToEnd().Trim());
} catch (Exception) {
moceanv2_contents.Append("");
}
return moceanv2_contents.ToString();
}
</script>
Ruby on Rails install code
<%
require 'net/http'
require 'uri'
require 'md5'
def moceanv2_ad(request)
# change to "live" to disable demo mode and show real ads
moceanv2_mode = "test"
# prepare url parameters of request
moceanv2_get = {}
moceanv2_get["site"] = "7057"
moceanv2_get["ua"] = request.user_agent
moceanv2_get["ip"] = request.remote_ip
moceanv2_get["url"] = request.request_uri
moceanv2_get["zone"] = "12310"
moceanv2_get["adstype"] = "3" # type of ads (1 - text only, 2 - images only, 3 - text + images, 6 - sms)
moceanv2_get["key"] = "1"
#moceanv2_get["lat"] = "1"
#moceanv2_get["long"] = "1"
moceanv2_get["keywords"] = "" # keywords to search ad delimited by commas (not necessary)
moceanv2_get["over_18"] = "0" # filter by ad over 18 content (0 or 1 - deny over 18 content , 2 - only over 18 content, 3 - allow all ads including over 18 content)
moceanv2_get["count"] = "1" # quantity of ads
moceanv2_get["paramBORDER"] = "#000000" # ads border color
moceanv2_get["paramHEADER"] = "#cccccc" # header color
moceanv2_get["paramBG"] = "#eeeeee" # background color
moceanv2_get["paramTEXT"] = "#000000" # text color
moceanv2_get["paramLINK"] = "#ff0000" # url color
moceanv2_get["test"] = "1" if moceanv2_get == "test"
# send request
begin
moceanv2_uri = URI.parse("http://ads.mocean.mobi:80/ad")
moceanv2_request = Net::HTTP::Post.new(moceanv2_uri.path)
moceanv2_request.set_form_data(moceanv2_get)
moceanv2_conn = Net::HTTP.new(moceanv2_uri.host, moceanv2_uri.port)
moceanv2_conn.read_timeout = 3.0
moceanv2_conn.open_timeout = 3.0
moceanv2_response = moceanv2_conn.start {|moceanv2_http| moceanv2_http.request(moceanv2_request) }
moceanv2_contents = moceanv2_response.body
rescue Timeout::Error => te
moceanv2_contents = ""
rescue
end
moceanv2_contents
end
%>
<%=
# copy this snippet elsewhere on your page for display more of ads
moceanv2_ad(request)
%>
JS(Client Side) install code
Javascript Ad Serving API
Include in the head of your page:
<script src='http://img.ads.mocean.mobi/js/mobile.js'></script>
Then, in any place you want an ad to appear, paste this code:
<script>
AdRequest_({
// Common vars
site:'85',
zone:'85',
type:2,
target:'',
defaultHtml:'',
clickPrepend:'',
pixelUrl:'',
service:'http://ads.mocean.mobi/ad'
});
</script>
Explanation:
1) site and zone: publisher identifiers
2) type: Type of ads to be returned (1 - text, 2 - image, 4 - richmedia ad). You can set different combinations with these values. For example, 3 = 1 + 2 (text + image), 7 = 1 + 2 + 4 (text + image + richmedia) and so on. Default value is ’-1’ that means any type of ads can be returned. 3) target: The link target; set to "_blank" if you want the clicked ad to open in a new window
4) defaultHtml: content to be displayed if no ad comes back from the server.
5) clickPrepend: whatever is here will be added verbatim to the beginning of all clickable urls.
6) pixelUrl: If this is set, the ad will make a call to the url when the ad is shown.
7) img_width and img_height: In the case of an image (type:2) these settings will override the image's natural size. This is not recommended.
XHTML/WML install code
<div><a href="http://ads.mocean.mobi/redir?dkey=#RANDOM#"><img src="http://ads.mocean.mobi/ad?zone=12310&adstype=2&image=1&dkey=#RANDOM#"/></a></div> Please replace #RANDOM# above with a random number for cache bursting.
