Hello!

There is a site, in it on the page contacts.php and in the "basement" (the basement is connected on the pages via INCLUDE) of the site on each page are indicated certain phone numbers.

The task is to ensure that when you go to the site from an external link with a certain GET variable (for example: http://site.ru/page.php?my=1 ), the phone numbers change in contacts.php and the "basement" of the site.

I suggested that it could be implemented using the SESSION mechanism ($ _SESSION) , with this mechanism I tried to figure it out and apply, but without success, I can not catch up with the logic.

Tell me some example of how to implement it if it is possible, or any source for the sessions (lessons, books, etc.) unless of course I'm on the right track!

THANK!

  • 2
    Someone else will write more, but the general course is: 0) Enable the session mechanism (session_start ()). 1) Check the availability of the GET parameter. 2) If the parameter is found, then we write this fact into the session. 3) In the footer, we check the session and the GET parameter (if the session is written at the very end), if we find the necessary condition and change the phones. - etki

3 answers 3

If the change of numbers occurs depending on the referrer, then I will offer you the following algorithm: In the index.php at the very top, we register the start of the session:

session_start(); 

Immediately after it:

 // Проверяем не перешли ли к нам с сайтов, требуемых для смены телефонов: if($_SERVER['HTTP_REFERER'] == 'http://site.ru/page.php?my=1'){ $_SESSION['phone'] = 1; } elseif($_SERVER['HTTP_REFERER'] == 'http://site2.ru/page.php?my=1'){ $_SESSION['phone'] = 2; }; 

After that, wherever you need to insert the phone, we insert something like this:

 if(isset($_SESSION['phone'])){ // Если существует сесионная переменная проверяем её значение и вставляем соответствующий телефон(ы) switch($_SESSION['phone']){ case'1': echo $phone1; break; case'2': echo $phone1; break; } } else{ // Если сесионная переменная не была создана то вставляем телефон(ы) назначеные по умолчанию. echo $defaultPhone; }; 

Something like this.

  • I tried, it produces the following: Warning: session_start () [function.session-start]: Cannot send session cache limiter - headers already sent - cheh1
  • one
    unsurprisingly, the session needs to start before any conclusion - etki
  • I agree, I removed the signature of the BOM, everything is fine, only the village displays on krakozyabrah, for some reason puts the encoding - Cyrillic - cheh1
  • changed the encoding on the web server, everything is fine! Thanks to all! - cheh1 pm

If each link has its own GET , then why do you need a " session "? Session quite resource-intensive process.

Create an array with phone numbers (unless of course pull from the database) and a variable (for phone output) and place it in contacts.php and in the basement .

For example:

 $arr = array("79161234561","79161234562","79161234563"); // http://site.ru ?id=1 if(isset($_GET[id])){ $id=$_GET[id]; $tel = $arr[$id]; //получаем 79161234562 } //размещаем переменную $tel в contacts.php и подвале 

    Good evening. And why here, the session itself?

    page.php

     $my_val=$_GET['my']; include('contacts.php'); 

    contacts.php

     <?php if($my_val==1){ echo "такой вот номер телефона"; }else{ echo "нет, ты не свой, на тебе такой вот номер телефона"; } ?> 

    about the session: here is the link, but only use echo, as shown there, is worth it :)