0

I am running adsense on my site and using php includes files where entire adsense code is placed named ga1.php, ga2.php, ga3.php and ga4.php. everything within the code is identical except for a link colours meaning that on each page refresh or by going to any other page on my site, new include is used containing Google Adsense code with new colour of the links. this is all handled by the following code:

<?php 
session_start();

if (isset($_SESSION['cnt'])){$_SESSION['cnt'] += 1; if( $_SESSION['cnt'] > 4)$_SESSION['cnt'] =1;}
else {$_SESSION['cnt'] = 1;}
include("/var/www/vhosts/MySite.com/httpdocs/includes/ga" . $_SESSION['cnt'] . ".php");

?>

everything works fine except for one thing, I do not want to use session_start() since it sets up the following in header response:

Set-Cookie:   PHPSESSID=u8rvtkbjas94ifsa5okhskkim5; path=/
Expires:      Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma:   no-cache 

I can have session_start() on some of my pages, where session need to be tracked but not on all, so looking for some solution to solve my problem if there is any?

Your suggestions are always of the great value to me and always really appreciated.

AlexB
  • 2,164
  • 6
  • 27
  • 61

1 Answers1

1

You could use the GET command to pass the number to other pages. Just replace the _SESSION with _GET and add to the end of your include:

include("/var/www/vhosts/MySite.com/httpdocs/includes/ga" . $_GET['cnt'] . ".php?cnt=".$_GET['cnt']);

Alternatively, you could use the following to get the number after the ga:

$cnt=substr($_SERVER['REQUEST_URI'], -5, 1);

Hope this helps!

ABC
  • 718
  • 8
  • 23
  • you should never allow functions such as include or require to use unfiltered user variables. The above example is unsafe. – Martin Sommervold Nov 25 '12 at 18:51
  • Thanks for you reply, but I am not quite with you on this one, I have tried to replace all _SESSION with_GET, but nothing seem to be happening. IS there any chance to send a code in the way to make it little more understandable? – AlexB Nov 25 '12 at 20:11
  • Would you be able to send the updated code? And in regards to @Martin's point you could use Pregmatch to make sure it's a number eg: – ABC Nov 25 '12 at 23:16
  • Sorry, ran out of edit time, what I meant to say was: Would you be able to send the updated code? And in regards to @Martin's point you could use Pregmatch to make sure it's a number eg: if(preg_match('/[1-4]/',$_GET['cnt'])){//continue} – ABC Nov 25 '12 at 23:23
  • I think I have found an easy solution that did the trick { } – AlexB Nov 25 '12 at 23:26
  • I will give it a go to see if this works, but not until tomorrow, it is getting a bit late and I have an early start tomorrow. Thanks for your help. – AlexB Nov 25 '12 at 23:31
  • Just wanted to update my preg_match: if(preg_match('/^[1-4]\z/',$_GET['cnt'])){//code} – ABC Nov 26 '12 at 00:55