-1

I need your help.

I want to show different phone # based on what page (within same site) user came from.

Everthing will take place within same website.

All users will come to same page - misite.com/phone.php

Example:

  • If user came from misite.com/page1.php, show phone number 1
  • If user came from misite.com/page2.php, show phone number 2
  • If user came from misite.com/page3.php, show phone number 3

Else, show default phone number (if I do not list a specific page).

I guess it will ba a if / elseif statement, but i'm not a coder and don't know how to sturcture it correctly.

I'm looking for example of code please.

I also thing I will need to us to use $_SERVER['HTTP_REFERER']; for this.

Thank you for any help!

Levchik
  • 496
  • 1
  • 5
  • 19
  • 1
    " but i'm not a coder and don't know how to sturcture it correctly" you either need to learn or hire some one, –  Apr 20 '15 at 21:07
  • You won't always get a referrer, http://stackoverflow.com/questions/6880659/in-what-cases-will-http-referer-be-empty – chris85 Apr 20 '15 at 21:08
  • Is this all on the same site?? Or from one site to another site? I ask because sessions or cookies will work if all from same site.. – Jason Apr 20 '15 at 21:08
  • @Dagon I took PHP / JS / SQL class, but am not good enough to structure this. Coding is not my full time job. Also this is the site for people to ask questions and get answers - not for comments like yours - it's not helpful at all. I know I can hire someone but it will take much longer than asking a question here. – Levchik Apr 20 '15 at 21:08
  • instead of using `$_SERVER['HTTP_REFERER']`, consider adding a parameter to the phone page using query string ( e.g. `example.com/phone.php?phoneId=1` ) – Ramy Nasr Apr 20 '15 at 21:09
  • @Jason - yes, all on the same site - updated Q – Levchik Apr 20 '15 at 21:11

1 Answers1

2

IF all these pages are on the same site, I would use sessions.

On each page, set a session to something you can test against later. On one page:

//Start session first   
session_start();
//Then choose a keyword to put in the single quotes & have it equal a unique number
    $_SESSION['page'] = 1;

On another page:

session_start();
$_SESSION['page'] = 2;

On another page:

session_start();
$_SESSION['page'] = 3;

Then on the page where you want to display a phone number, do a test:

session_start();
switch ($_SESSION['page']) {
    case 0:
        $phone="555-555-5555";
        break;
    case 1:
        $phone="555-555-5556";
        break;
    case 2:
        $phone="555-555-5557";
        break;
    default:
        $phone="555-555-5558";
}

Then, echo $phone

Quick note, some shared hosting providers have issues using sessions out of the box, not sure why but I have run into it.

Jason
  • 396
  • 4
  • 19
  • so if user came form somepage.html which is not listed in switch statement, how do I show default number? – Levchik Apr 20 '15 at 21:14
  • add: default: $phone="number" – Jason Apr 20 '15 at 21:15
  • If user came from `misite.com/aboutus.html` how do I list that in switch statement? – Levchik Apr 20 '15 at 21:16
  • On aboutus.html, set a session to a unique number not used on any other page... then add that to the switch statement, use corresponding phone number. – Jason Apr 20 '15 at 21:17
  • how would I do that (set session)? – Levchik Apr 20 '15 at 21:18
  • First, you must start sessions with: session_start(); THEN $_SESSION['page'] = a number – Jason Apr 20 '15 at 21:19
  • so I don't ask you a series of lead-on questions, can you provide sample code? For example I don't understand this part `switch ($_SESSION['page']) ` – Levchik Apr 20 '15 at 21:20
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/75757/discussion-between-jason-and-roofing-calculator). – Jason Apr 20 '15 at 21:20