Jump to content

Help with PHP code to switch phone number


PHPNEWTOIT

Recommended Posts

Hi

 

I am stuggling with code to change the phone number displayed on the website depedning on the incoming link.

 

For example the incomings links will be like this:-

 

http://www.mysite.com/index.php?a=1

http://www.mysite.com/index.php?a=2

http://www.mysite.com/index.php?a=3

 

It work ok until someone uses no incoming link for example http://www.mysite.com/index.php any ideas how I can fix this please.

 

 

Notice: Undefined variable: referer in C:\Program Files\EasyPHP 2.0b1\www\y3kdemo\templates\track.php on line 10

 

Notice: Undefined variable: referer in C:\Program Files\EasyPHP 2.0b1\www\y3kdemo\templates\track.php on line 13

default no to show

 

<?php
$phoneno = 'somedefaultvalue'; 

if(isset($_GET['a'])) 
{ 
$referer = $_GET['a']; 
} 
switch($referer) 
{ 
case '1': 
$phoneno = 'phone for campaign 1'; 
break; 
case '2': 
$phoneno = 'phone for campaign 2'; 
break; 


default: 
$phoneno = 'default no to show'; 
break; 
} 

echo $phoneno;
?>

 

 

Many thanks for your help.

 

Roy

<?php
$referer = isset($_GET['a']) ? $_GET['a'] : null; 
switch($referer) { 
  case '1': 
    $phoneno = 'phone for campaign 1'; 
    break; 
  case '2': 
    $phoneno = 'phone for campaign 2'; 
    break; 
  default: 
    $phoneno = 'somedefaultvalue'; 
} 
echo $phoneno;
?>

You should only do the switch if $_GET['a'] is set:

<?php
if (isset($_GET['a'])) {
   switch ($_GET['a']) {
      case '1':
         $phoneno = 'phone for campaign 1';
         break;
      case '2':
         $phoneno = 'phone for campaign 2';
         break;
      default:
         $phoneno = 'default no to show';
    }
} else
   $phoneno = 'default no to show';
echo $phoneno;
?>

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.