Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

variable from google ads only works on page refersh


Go to End


1135 Views

Avatar
neilos

Community Member, 19 Posts

27 October 2012 at 12:53am

Hi,

I am trying to get a variable from various google location ads to change the phone number depending on the ?number=xxx from the ad.

The number displays a default value unless the page is refreshed, then the variable is displayed.

Is there a better way of doing this that will display the variable number without the need for a page refresh?

In page.ss

<% if phonenumber %>$phonenumber <% else %>0800 xxx xxx<% end_if %>

In page.php

public function Phonenumber() {
	 include('defines.php');
return strip_tags (Session::get ('number'));
}

And defines.php

<?php

ob_start();
if (!isset($_SESSION)) {
@session_start();
}
if (!isset($_SESSION['number']))
  {
  $phonenumber = $_GET['number'];
  $_SESSION['number'] = $phonenumber;
	  }

ob_end_flush(); 
?>