L
L
lex2017-04-17 21:58:23
PHP
lex, 2017-04-17 21:58:23

Why is my code not working?

I'm making a mobile version, and redirecting to mobile devices, respectively, I found the mobile detect php library, I sort of sewed it in correctly

<?
include 'mdetect/Mobile_Detect.php';
$detect = new Mobile_Detect;

$useurl = '';


if ( $detect->isMobile() ) {


    global $DB;
    
    $err_mess = "<br /> err<br />";

     $url = $_SERVER['REQUEST_URI'];

    $results = $DB->Query("SELECT * FROM b_url_redirect_forge", false, $err_mess.__LINE__);

    if($results){
        while ($row = $results->Fetch())
        {
            switch ($url){ 
                            case $row['f_url'] or "/news/*" or "/offers/*" :
                      $trueurl = $DB->Query("SELECT `m_url` FROM `b_url_redirect_forge` WHERE f_url='".$url."' ");
                      $tu = $trueurl->Fetch();
                      $useurl = $tu;
                      
                      header('Location: mobileurl'.$tu['m_url'].''); 
                      exit();
                      break;
                        default : 
                            header('Location: 'mobileurl' '); 
                  exit();
                  break;
            }
        }
    }else{
        echo 'No matches';
    };
}
?>

I upload this to a template that, according to the Bitrix parameter (file system condition /mobile/ or not)
, maybe it needs to be somehow sewn into init, but for some reason it doesn’t work, mb something doesn’t reach and I don’t understand how to debug

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
VisualIdeas, 2017-04-17
@VisualIdeas

header('Location: "mobileurl'.$tu['m_url'].'"'); 
//...
header('Location: "mobileurl" ');

U
Uniq, 2017-04-18
@padonnak

$results->Fetch() - what do you want to get with this?
Should be $result->fetch_assoc() or fetch_row()
depending on what array you want to get
header('Location: mobileurl'.$tu['m_url'].'');
what is mobileurl?? (the link must be either http:// or on the same server /xxx )
header(' Location: xxxx.ru '. $tu['m_url'] ); - should be like this
header(' Location: xxxx.ru '); - it should be like this
if you have url in a variable then just write 'Location' . $url

Y
Yaroslav Alexandrov, 2017-04-18
@alexyarik

camouf.ru/blog-note/1320 - working version for Bitrix

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question