C
C
Cider Cherenkov2019-03-15 18:34:47
1C-Bitrix
Cider Cherenkov, 2019-03-15 18:34:47

Connecting a simple php script to Bitrix, how?

Hello, this is my first time with Bitrix. You just need to simply connect the SxGeo database to the site to check the country, and if the attempt is not included in the list, then close the site (required, without htaccess, etc.).
in index.php I insert before

require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php");

code I need:
include($_SERVER["DOCUMENT_ROOT"]."/SxGeo.php");
$SxGeo = new SxGeo($_SERVER["DOCUMENT_ROOT"].'/SxGeo.dat');
$SxGeo = new SxGeo($_SERVER["DOCUMENT_ROOT"].'/SxGeo.dat');
$ip = $_SERVER['REMOTE_ADDR'];
$zap = $SxGeo->get($ip);
if(in_array($zap , array('RU','UA'))) {
  exit();
}

But it doesn't work! Tell me how to do it right in Bitrix...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mysterion, 2019-03-15
@Mysterion

if the effort is not included in the list, then close the site

Replace: with:
if(!in_array($zap , array('RU','UA')))

A
Alexander, 2019-03-15
Madzhugin @Suntechnic

You will include this in each file before require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php"); ?
Well, that's not the way.
Add this check to at least init.php. And it's better in some file, which you just connect to init.php *
This is what concerns the connection specifically to Bitrix.
As for the Bible itself - first fix your solution on an empty regular file without Bitrix. Then connect to Bitrix. Otherwise, SxGeo obviously does not work for you, but the question seems to be about Bitrix.
I won’t say that such a solution is bad in itself - and you will slaughter a lot of users from those countries from which they need to be skipped - I hope you yourself perfectly understand and the desire to saw off a leg is fully realized, but I still want to say that to connect this on every hit bible is an expensive pleasure. Better set a cookie after you missed a user once and don't check all users with this cookie. It is possible to store a sign in session in principle.
----------------------------------
* - I mean /local/php_interface/init.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question