За последние 24 часа нас посетили 22424 программиста и 1149 роботов. Сейчас ищут 637 программистов ...

кто может на php 7

Тема в разделе "Прочие вопросы по PHP", создана пользователем kinlok, 18 мар 2017.

  1. kinlok

    kinlok Активный пользователь

    С нами с:
    18 мар 2017
    Сообщения:
    50
    Симпатии:
    0
    Ребят я недавна начал изучать php кто может икаму не лень перевести вот этат код на php 7
    Код (Text):
    1. if(!defined('MOZG'))
    2.     die('Hacking attempt!');
    3.  
    4. class db{
    5.  
    6.     var $db_id = false;
    7.     var $query_num = 0;
    8.     var $query_list = array();
    9.     var $mysql_error = '';
    10.     var $mysql_version = '';
    11.     var $mysql_error_num = 0;
    12.     var $mysql_extend = "MySQLi";
    13.     var $MySQL_time_taken = 0;
    14.     var $query_id = false;
    15.  
    16.    
    17.     function connect($db_user, $db_pass, $db_name, $db_location = 'localhost', $show_error=1){
    18.         $db_location = explode(":", $db_location);
    19.  
    20.         if (isset($db_location[1])) {
    21.  
    22.             $this->db_id = @mysqli_connect($db_location[0], $db_user, $db_pass, $db_name, $db_location[1]);
    23.  
    24.         } else {
    25.  
    26.             $this->db_id = @mysqli_connect($db_location[0], $db_user, $db_pass, $db_name);
    27.  
    28.         }
    29.  
    30.         if(!$this->db_id) {
    31.             if($show_error == 1) {
    32.                 $this->display_error(mysqli_connect_error(), '1');
    33.             } else {
    34.                 return false;
    35.             }
    36.         }
    37.  
    38.         $this->mysql_version = mysqli_get_server_info($this->db_id);
    39.  
    40.         if(!defined('COLLATE'))
    41.         {
    42.             define ("COLLATE", "cp1251");
    43.         }
    44.  
    45.         mysqli_query($this->db_id, "SET NAMES '" . COLLATE . "'");
    46.  
    47.         return true;
    48.     }
    49.    
    50.     function query($query, $show_error=true){
    51.         $time_before = $this->get_real_time();
    52.  
    53.         if(!$this->db_id) $this->connect(DBUSER, DBPASS, DBNAME, DBHOST);
    54.        
    55.         if(!($this->query_id = mysqli_query($this->db_id, $query) )) {
    56.  
    57.             $this->mysql_error = mysqli_error($this->db_id);
    58.             $this->mysql_error_num = mysqli_errno($this->db_id);
    59.  
    60.             if($show_error) {
    61.                 $this->display_error($this->mysql_error, $this->mysql_error_num, $query);
    62.             }
    63.         }
    64.            
    65.         $this->MySQL_time_taken += $this->get_real_time() - $time_before;
    66.        
    67.         $this->query_num ++;
    68.  
    69.         return $this->query_id;
    70.     }
    71.    
    72.     function get_row($query_id = ''){
    73.         if ($query_id == '') $query_id = $this->query_id;
    74.  
    75.         return mysqli_fetch_assoc($query_id);
    76.     }
    77.  
    78.     function get_array($query_id = ''){
    79.         if ($query_id == '') $query_id = $this->query_id;
    80.  
    81.         return mysqli_fetch_array($query_id);
    82.     }
    83.    
    84.     function super_query($query, $multi = false, $cache_prefix = false, $system_cache = false){
    85.        
    86.         //Если включен кеш, то проверяем на его существование
    87.         if($cache_prefix){
    88.        
    89.             if($system_cache)
    90.            
    91.                 $data = system_cache($cache_prefix);
    92.                
    93.             else
    94.            
    95.                 $data = mozg_cache($cache_prefix);
    96.            
    97.         }
    98.        
    99.         //Если есть ответ с кеша
    100.         if($data){
    101.            
    102.             $unSerData = unserialize($data);
    103.            
    104.             if($unSerData)
    105.            
    106.                 return $unSerData;
    107.                
    108.             else
    109.            
    110.                 return array();
    111.            
    112.         } else {
    113.  
    114.             if(!$multi) {
    115.  
    116.                 $this->query($query);
    117.                 $data = $this->get_row();
    118.                 $this->free();  
    119.  
    120.                 //Если включен кеш, то создаём его
    121.                 if($cache_prefix){
    122.                
    123.                     $cache_rows = serialize($data);
    124.                    
    125.                     mozg_create_cache($cache_prefix, $cache_rows);
    126.                    
    127.                 }
    128.                
    129.                 return $data;
    130.                
    131.             } else {
    132.                 $this->query($query);
    133.                
    134.                 $rows = array();
    135.                 while($row = $this->get_row()) {
    136.                     $rows[] = $row;
    137.                 }
    138.  
    139.                 $this->free();          
    140.  
    141.                 //Если включен кеш, то создаём его
    142.                 if($cache_prefix){
    143.                
    144.                     $cache_rows = serialize($rows);
    145.                    
    146.                     if($system_cache)
    147.                    
    148.                         creat_system_cache($cache_prefix, $cache_rows);
    149.                        
    150.                     else
    151.                    
    152.                         mozg_create_cache($cache_prefix, $cache_rows);
    153.                 }
    154.                
    155.                 return $rows;
    156.  
    157.             }
    158.        
    159.         }
    160.     }
    161.    
    162.     function num_rows($query_id = ''){
    163.         if ($query_id == '') $query_id = $this->query_id;
    164.  
    165.         return mysqli_num_rows($query_id);
    166.     }
    167.    
    168.     function insert_id(){
    169.         return mysqli_insert_id($this->db_id);
    170.     }
    171.  
    172.     function get_result_fields($query_id = '') {
    173.         if ($query_id == '') $query_id = $this->query_id;
    174.  
    175.         while ($field = mysqli_fetch_field($query_id))
    176.         {
    177.             $fields[] = $field;
    178.         }
    179.        
    180.         return $fields;
    181.        }
    182.  
    183.     function safesql( $source ){
    184.         if ($this->db_id) return mysqli_real_escape_string ($this->db_id, $source);
    185.         else return mysql_escape_string($source);
    186.     }
    187.  
    188.     function free( $query_id = '' ){
    189.  
    190.         if ($query_id == '') $query_id = $this->query_id;
    191.  
    192.         @mysqli_free_result($query_id);
    193.     }
    194.  
    195.     function close(){
    196.         @mysqli_close($this->db_id);
    197.     }
    198.  
    199.     function get_real_time(){
    200.         list($seconds, $microSeconds) = explode(' ', microtime());
    201.         return ((float)$seconds + (float)$microSeconds);
    202.     }  
    203.  
    204.     function display_error($error, $error_num, $query = ''){
    205.         if($query) {
    206.             // Safify query
    207.             $query = preg_replace("/([0-9a-f]){32}/", "********************************", $query); // Hides all hashes
    208.             $query_str = "$query";
    209.         }
    210.        
    211.         echo $error;
    212.        
    213.         echo '<?xml version="1.0" encoding="iso-8859-1"?>
    214.         <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    215.         <html xmlns="http://www.w3.org/1999/xhtml">
    216.         <head>
    217.         <title>Ошибка</title>
    218.         <meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
    219.         </head>
    220.         <body>
    221.             <font size="4">Ошибка сервера, попробуйте обновить страницу позже.</font>
    222.         </body>
    223.         </html>';
    224.        
    225.         exit();
    226.     }
    227.  
    228. }
     
  2. [vs]

    [vs] Суперстар
    Команда форума Модератор

    С нами с:
    27 сен 2007
    Сообщения:
    10.553
    Симпатии:
    631
    Разве этот код не работает на PHP 7?
     
  3. kinlok

    kinlok Активный пользователь

    С нами с:
    18 мар 2017
    Сообщения:
    50
    Симпатии:
    0
    нет
     
  4. [vs]

    [vs] Суперстар
    Команда форума Модератор

    С нами с:
    27 сен 2007
    Сообщения:
    10.553
    Симпатии:
    631
    @kinlok нужно найти конкретную причину с помощью этих рекомендаций: http://phpfaq.ru/debug
     
  5. denis01

    denis01 Суперстар
    Команда форума Модератор

    С нами с:
    9 дек 2014
    Сообщения:
    12.230
    Симпатии:
    1.715
    Адрес:
    Молдова, г.Кишинёв
    Пишет ошибки?
     
  6. kinlok

    kinlok Активный пользователь

    С нами с:
    18 мар 2017
    Сообщения:
    50
    Симпатии:
    0
    ошибка заключаеца вот вэтам коде
    PHP:
    1. function safesql( $source ){
    2.         global $db_config;
    3.         if(!$this->db_id) $this->connect($db_config['user'], $db_config['password'], $db_config['name'], $db_config['host']);
    4.         return mysqli_real_escape_string($this->db_id, $source);
    5.     }
    6. вот вэтой строке
    7.  
    8. return mysqli_real_escape_string($this->db_id, $source);
     
    #6 kinlok, 18 мар 2017
    Последнее редактирование модератором: 18 мар 2017
  7. romach

    romach Старожил

    С нами с:
    26 окт 2013
    Сообщения:
    2.904
    Симпатии:
    719
    Текст ошибки скопировать? Не, мы ведь сюда пришли в загадки играть, а не проблему решать.
     
  8. [vs]

    [vs] Суперстар
    Команда форума Модератор

    С нами с:
    27 сен 2007
    Сообщения:
    10.553
    Симпатии:
    631
    @kinlok в приведенным вами коде, эта функция выглядит иначе
    ошибка в жирной строке. Дело в том, что в PHP7 больше нет функций mysql_. А вот здесь:
    как раз ошибок нет.
     
  9. kinlok

    kinlok Активный пользователь

    С нами с:
    18 мар 2017
    Сообщения:
    50
    Симпатии:
    0
    Notice: Undefined index: act in W:\domains\testfd.ru\system\init.php on line 75

    Notice: Undefined index: lang in W:\domains\testfd.ru\system\init.php on line 99

    Notice: Undefined index: act in W:\domains\testfd.ru\system\modules\functions.php on line 1166

    Notice: Undefined index: act in W:\domains\testfd.ru\system\modules\functions.php on line 1167

    Notice: Undefined index: mobile_enable in W:\domains\testfd.ru\system\modules\functions.php on line 274

    Notice: Undefined index: mobile in W:\domains\testfd.ru\system\modules\functions.php on line 1184

    Fatal error: Uncaught Error: Call to undefined function mysql_escape_string() in W:\domains\testfd.ru\system\classes\mysql.php:198 Stack trace: #0 W:\domains\testfd.ru\system\modules\login.php(7): db->safesql('127.0.0.1') #1 W:\domains\testfd.ru\system\init.php(135): include('W:\\domains\\test...') #2 W:\domains\testfd.ru\index.php(25): include('W:\\domains\\test...') #3 {main} thrown in W:\domains\testfd.ru\system\classes\mysql.php on line 198
     
  10. kinlok

    kinlok Активный пользователь

    С нами с:
    18 мар 2017
    Сообщения:
    50
    Симпатии:
    0
    памаги вот сетой ошибкай

    <br%20/><b>Deprecated</b>:%20%20Methods%20with%20the%20same%20name%20as%20their%20class%20will%20not%20be%20constructors%20in%20a%20future%20version%20of%20PHP;%20thumbnail%20has%20a%20deprecated%20constructor%20in%20<b>W:/domains/testfd.ru/system/classes/images.php</b>%20on%20line%20<b>17</b><br%20/>8


    Код (Text):
    1. class thumbnail {
    2.     var $img;
    3.     var $watermark_image_light;
    4.     var $watermark_image_dark;
    5.    
    6.     function thumbnail($imgfile) {
    7.         //detect image format
    8.  
    9.         $info = @getimagesize($imgfile);
    10.  
    11.         if( $info[2] == 2 ) {
    12.             $this->img['format'] = "JPEG";
    13.             $this->img['src'] = @imagecreatefromjpeg( $imgfile );
    14.         } elseif( $info[2] == 3 ) {
    15.             $this->img['format'] = "PNG";
    16.             $this->img['src'] = @imagecreatefrompng( $imgfile );
    17.         } elseif( $info[2] == 1 ) {
    18.             $this->img['format'] = "GIF";
    19.             $this->img['src'] = @imagecreatefromgif( $imgfile );
    20.         } else {
    21.             echo "Not Supported File! Thumbnails can only be made from .jpg, gif and .png images!";
    22.             @unlink( $imgfile );
    23.             exit();
    24.         }
    25.  
    26.         if( !$this->img['src'] ) {
    27.             echo "Not Supported File! Thumbnails can only be made from .jpg, gif and .png images!";
    28.             @unlink( $imgfile );
    29.             exit();
    30.        
    31.         }
    32.  
    33.         $this->img['lebar'] = @imagesx( $this->img['src'] );
    34.         $this->img['tinggi'] = @imagesy( $this->img['src'] );
    35.         $this->img['lebar_thumb'] = $this->img['lebar'];
    36.         $this->img['tinggi_thumb'] = $this->img['tinggi'];
    37.         //default quality jpeg
    38.         $this->img['quality'] = 90;
    39.        
    40.     }
    41.    
    42.     function size_auto($size = 100, $site = 0, $jqCrop = 0) {
    43.  
    44.         $size = explode ("x", $size);
    45.        
    46.         if($jqCrop){
    47.            
    48.             return $this->jqCrop( intval($size[0]), intval($size[1]), $jqCrop);
    49.            
    50.         } else if ( count($size) == 2 ) {
    51.             $size[0] = intval($size[0]);
    52.             $size[1] = intval($size[1]);
    53.             return $this->crop( intval($size[0]), intval($size[1]) );
    54.  
    55.         } else {
    56.             $size[0] = intval($size[0]);
    57.             return $this->scale( intval($size[0]), $site);
    58.  
    59.         }
    60.  
    61.     }
    62.  
    63.     function crop($nw, $nh) {
    64.  
    65.         $w = $this->img['lebar'];
    66.         $h = $this->img['tinggi'];
    67.  
    68.         if( $w <= $nw AND $h <= $nh ) {
    69.             $this->img['lebar_thumb'] = $w;
    70.             $this->img['tinggi_thumb'] = $h;
    71.             return 0;
    72.         }
    73.  
    74.         $nw = min($nw, $w);
    75.         $nh = min($nh, $h);
    76.  
    77.         $size_ratio = max($nw / $w, $nh / $h);
    78.  
    79.         $src_w = ceil($nw / $size_ratio);
    80.         $src_h = ceil($nh / $size_ratio);
    81.  
    82.         $sx = floor(($w - $src_w)/2);
    83.         $sy = floor(($h - $src_h)/2);
    84.  
    85.         $this->img['des'] = imagecreatetruecolor($nw, $nh);
    86.  
    87.         if ( $this->img['format'] == "PNG" ) {
    88.             imagealphablending( $this->img['des'], false);
    89.             imagesavealpha( $this->img['des'], true);
    90.         }
    91.  
    92.         imagecopyresampled($this->img['des'],$this->img['src'],0,0,$sx,0,$nw,$nh,$src_w,$src_h);
    93.  
    94.         $this->img['src'] = $this->img['des'];
    95.         return 1;
    96.     }
    97.    
    98.     function jqCrop($nw, $nh, $cropData) {
    99.         $cropDataExp = explode('|', $cropData);
    100.         $left = $cropDataExp[0];
    101.         $top = $cropDataExp[1];
    102.        
    103.         if(!$left OR $left < 0 OR $left > $nw) $left = 0;
    104.         if(!$top OR $top < 0 OR $top > $nh) $top = 0;
    105.  
    106.         if($nw < 100) $nw = 100;
    107.         if($nh < 100) $nh = 100;
    108.        
    109.         $w = $this->img['lebar'];
    110.         $h = $this->img['tinggi'];
    111.  
    112.         if( $w <= $nw AND $h <= $nh ) {
    113.             $this->img['lebar_thumb'] = $w;
    114.             $this->img['tinggi_thumb'] = $h;
    115.             return 0;
    116.         }
    117.  
    118.         $nw = min($nw, $w);
    119.         $nh = min($nh, $h);
    120.  
    121.         $size_ratio = max($nw / $w, $nh / $h);
    122.  
    123.         $src_w = ceil($nw / $size_ratio);
    124.         $src_h = ceil($nh / $size_ratio);
    125.  
    126.         $this->img['des'] = imagecreatetruecolor($nw, $nh);
    127.  
    128.         if ( $this->img['format'] == "PNG" ) {
    129.             imagealphablending( $this->img['des'], false);
    130.             imagesavealpha( $this->img['des'], true);
    131.         }
    132.  
    133.         imagecopyresampled($this->img['des'], $this->img['src'], 0, 0, $left, $top, $nw, $nh, $nw, $nh);
    134.  
    135.         $this->img['src'] = $this->img['des'];
    136.         return 1;
    137.     }
    138.  
    139.     function scale($size = 100, $site = 0) {
    140.  
    141.         $site = intval( $site );
    142.        
    143.         if( $this->img['lebar'] <= $size and $this->img['tinggi'] <= $size ) {
    144.             $this->img['lebar_thumb'] = $this->img['lebar'];
    145.             $this->img['tinggi_thumb'] = $this->img['tinggi'];
    146.             return 0;
    147.         }
    148.        
    149.         switch ($site) {
    150.            
    151.             case "1" :
    152.                 if( $this->img['lebar'] <= $size ) {
    153.                     $this->img['lebar_thumb'] = $this->img['lebar'];
    154.                     $this->img['tinggi_thumb'] = $this->img['tinggi'];
    155.                     return 0;
    156.                 } else {
    157.                     $this->img['lebar_thumb'] = $size;
    158.                     $this->img['tinggi_thumb'] = ($this->img['lebar_thumb'] / $this->img['lebar']) * $this->img['tinggi'];
    159.                 }
    160.                
    161.                 break;
    162.            
    163.             case "2" :
    164.                 if( $this->img['tinggi'] <= $size ) {
    165.                     $this->img['lebar_thumb'] = $this->img['lebar'];
    166.                     $this->img['tinggi_thumb'] = $this->img['tinggi'];
    167.                     return 0;
    168.                 } else {
    169.                     $this->img['tinggi_thumb'] = $size;
    170.                     $this->img['lebar_thumb'] = ($this->img['tinggi_thumb'] / $this->img['tinggi']) * $this->img['lebar'];
    171.                 }
    172.                
    173.                 break;
    174.            
    175.             default :
    176.                
    177.                 if( $this->img['lebar'] >= $this->img['tinggi'] ) {
    178.                     $this->img['lebar_thumb'] = $size;
    179.                     $this->img['tinggi_thumb'] = ($this->img['lebar_thumb'] / $this->img['lebar']) * $this->img['tinggi'];
    180.                
    181.                 } else {
    182.                    
    183.                     $this->img['tinggi_thumb'] = $size;
    184.                     $this->img['lebar_thumb'] = ($this->img['tinggi_thumb'] / $this->img['tinggi']) * $this->img['lebar'];
    185.                
    186.                 }
    187.                
    188.                 break;
    189.         }
    190.  
    191.         if ($this->img['lebar_thumb'] < 1 ) $this->img['lebar_thumb'] = 1;
    192.         if ($this->img['tinggi_thumb'] < 1 ) $this->img['tinggi_thumb'] = 1;
    193.        
    194.         $this->img['des'] = imagecreatetruecolor( $this->img['lebar_thumb'], $this->img['tinggi_thumb'] );
    195.  
    196.         if ( $this->img['format'] == "PNG" ) {
    197.             imagealphablending( $this->img['des'], false);
    198.             imagesavealpha( $this->img['des'], true);
    199.         }
    200.  
    201.         @imagecopyresampled( $this->img['des'], $this->img['src'], 0, 0, 0, 0, $this->img['lebar_thumb'], $this->img['tinggi_thumb'], $this->img['lebar'], $this->img['tinggi'] );
    202.        
    203.         $this->img['src'] = $this->img['des'];
    204.         return 1;
    205.  
    206.     }
    207.    
    208.     function jpeg_quality($quality = 90) {
    209.         //jpeg quality
    210.         $this->img['quality'] = $quality;
    211.     }
    212.    
    213.     function save($save = "") {
    214.        
    215.         if( $this->img['format'] == "JPG" || $this->img['format'] == "JPEG" ) {
    216.             //JPEG
    217.             imagejpeg( $this->img['src'], $save, $this->img['quality'] );
    218.         } elseif( $this->img['format'] == "PNG" ) {
    219.             //PNG
    220.             imagealphablending( $this->img['src'], false);
    221.             imagesavealpha( $this->img['src'], true);
    222.             imagepng( $this->img['src'], $save );
    223.         } elseif( $this->img['format'] == "GIF" ) {
    224.             //GIF
    225.             imagegif( $this->img['src'], $save );
    226.         }
    227.        
    228.         imagedestroy( $this->img['src'] );
    229.     }
    230.    
    231.     function show() {
    232.         if( $this->img['format'] == "JPG" || $this->img['format'] == "JPEG" ) {
    233.             //JPEG
    234.             imageJPEG( $this->img['src'], "", $this->img['quality'] );
    235.         } elseif( $this->img['format'] == "PNG" ) {
    236.             //PNG
    237.             imagePNG( $this->img['src'] );
    238.         } elseif( $this->img['format'] == "GIF" ) {
    239.             //GIF
    240.             imageGIF( $this->img['src'] );
    241.         }
    242.        
    243.         imagedestroy( $this->img['src'] );
    244.     }
    245. }
     
  11. [vs]

    [vs] Суперстар
    Команда форума Модератор

    С нами с:
    27 сен 2007
    Сообщения:
    10.553
    Симпатии:
    631
    @kinlok это не ошибка вовсе)
     
  12. kinlok

    kinlok Активный пользователь

    С нами с:
    18 мар 2017
    Сообщения:
    50
    Симпатии:
    0
    памаги исправить ?
     
  13. Fell-x27

    Fell-x27 Суперстар
    Команда форума Модератор

    С нами с:
    25 июл 2013
    Сообщения:
    12.155
    Симпатии:
    1.769
    Адрес:
    :сердА
    Я конечно может совсем бестактный, но, @kinlok, ты вроде из Перми, а не с Точикистона, не коверкай так русский язык, пожалуйста.
     
  14. [vs]

    [vs] Суперстар
    Команда форума Модератор

    С нами с:
    27 сен 2007
    Сообщения:
    10.553
    Симпатии:
    631
    @kinlok надо вместо function thumbnail писать function __construct. Но ты теперь обязан перевести текст ошибки и понять, в чем суть.
     
  15. kinlok

    kinlok Активный пользователь

    С нами с:
    18 мар 2017
    Сообщения:
    50
    Симпатии:
    0
    спосиба тебе бальшое заменил функцию function __construct. и заработала тока точка была лишнея а вастальном все заработала

    тут еше адна пахоже ета паследния ашибка

    Fatal error: Uncaught Error: Class 'parse' not found in W:\domains\ivinete.net\core\classes\wall.php:292
    вот в этам коде

    include ROOT_DIR.'core/classes/forwall.php';
    $parse = new parse();