I understand that I might not be too specific in what I want, but I'll try to explain myself as good as I can.
I want to monetize my website, and I'm pretty new to web development. I want everyone except chosen people, to get ads displayed. I have setup mysql accounts etc. and I am trying to detect what rank a session is. What I do atm., is inside of php tags, I get the session, and do
if($_SESSION['category'] == "3"){
I am just wondering, how I would be able to add this code, inside of the brackets of above code. I've tried echo 'CODE'; but I couldn't get it to work. I'd really appreciate any help I can get.
Code I want run:
<script type="text/javascript">//<![CDATA[
(function() {
var configuration = {
"token": "NOT SURE I CAN SHARE THIS",
"excludeDomains": [
"NONE"
],
"capping": {
"limit": 5,
"timeout": 24
},
"entryScript": {
"type": "timeout",
"timeout": 3000,
"capping": {
"limit": 5,
"timeout": 24
}
},
"exitScript": {
"enabled": true
},
"popUnder": {
"enabled": true
}
};
var script = document.createElement('script');
script.async = true;
script.src = '//cdn.shorte.st/link-converter.min.js';
script.onload = script.onreadystatechange = function () {var rs = this.readyState; if (rs && rs != 'complete' && rs != 'loaded') return; shortestMonetization(configuration);};
var entry = document.getElementsByTagName('script')[0];
entry.parentNode.insertBefore(script, entry);
})();
//]]></script>
What I've tried
if ($_SESSION['category' == "3" {
echo '<script type="text/javascript">//<![CDATA[
(function() {
var configuration = {
"token": "NOT SURE I CAN SHARE THIS",
"excludeDomains": [
"NONE"
],
"capping": {
"limit": 5,
"timeout": 24
},
"entryScript": {
"type": "timeout",
"timeout": 3000,
"capping": {
"limit": 5,
"timeout": 24
}
},
"exitScript": {
"enabled": true
},
"popUnder": {
"enabled": true
}
};
var script = document.createElement('script');
script.async = true;
script.src = '//cdn.shorte.st/link-converter.min.js';
script.onload = script.onreadystatechange = function () {var rs = this.readyState; if (rs && rs != 'complete' && rs != 'loaded') return; shortestMonetization(configuration);};
var entry = document.getElementsByTagName('script')[0];
entry.parentNode.insertBefore(script, entry);
})();
//]]></script> ';
}
As I am concerned you want to show some add to people except some people wo don't want to see the adds. I suggest you to store your javascript code in .js file and than call it by php. Actually it is not a calling like require or include. You need to print just the text below, of course replacing the full path/file_name.js name of your file.
<?php
echo "<script type="text/javascript" src="path/file_name.js"></script>";
?>
Example:
<?php
if ($_SESSION['category'] == "3" {
echo "<script type="text/javascript" src="path/file_name.js"></script>";
}
?>
Aim of doing this is to get more readale, understandable, managale code.
You can intermingle PHP with HTML, javascript even CSS.. Use the opening and closing PHP tag
<?php
.... some php script
if($_SESSION['category'] == "3"){
// exit PHP to output javascript
?>
<script type="text/javascript">//<![CDATA[
(function() {
var configuration = {
"token": "NOT SURE I CAN SHARE THIS",
"excludeDomains": [
"NONE"
],
. . . . snipped for brevity
//]]></script>
<h1>some plain HTML</h1> <p>Using php short tag is handy
to print out PHP vars </p> ©<?=date("Y")?>
<?php // back to PHP mode
echo 'pretty cool';
// and out again
?>