A
A
Anton2017-07-07 22:13:46
PHP
Anton, 2017-07-07 22:13:46

How to display data from a script in php?

Here is the code that shows the user's location.
Having slightly corrected it, the script displays just the name of the city.
I need to insert the name of the city in php so that it looks like this:
$A = the city that was defined
Then embed it in the comparison construct
If $A = Moscow, then output the php code (Bitrix component)
Otherwise, output another component.
How to put a city in $A from a script?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
twobomb, 2017-07-07
@twobomb

Here you download the script and the database . You throw everything in one folder + my code and rejoice.

include("./SxGeo.php");

$SxGeo = new SxGeo('SxGeoCity.dat');
if($SxGeo->get(get_ip())["city"]["name_ru"] == "Москва"){
    //Что-то делаем
}
else{
    //Делаем что-то другое
}

function get_ip()
{
    if (!empty($_SERVER['HTTP_CLIENT_IP']))
    {
        $ip=$_SERVER['HTTP_CLIENT_IP'];
    }
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
    {
        $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else
    {
        $ip=$_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question