PHPNEWTOIT Posted January 13, 2009 Share Posted January 13, 2009 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 Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 13, 2009 Share Posted January 13, 2009 <?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; ?> Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted January 13, 2009 Share Posted January 13, 2009 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.