1

I have config.php and function.php, I save it in the header.php file.

require 'func/config.php';
require 'func/function.web.php';
require 'func/action.web.php';
require 'func/Facebook/autoload.php';
require 'func/Google/vendor/autoload.php';

config.php :

$query_config = $server_conn->query("select * from site_config") or die ("Config Site : ".$server_conn->error);
$row_config = $query_config->fetch_assoc();

$about_config = $row_config['about_config'];
$kkp_config = $row_config['kkp_config'];
$hjkb_config = $row_config['hjkb_config'];
$pk_config = $row_config['pk_config'];
$fanspage_config = $row_config['fanspage_config'];
$twitter_config = $row_config['twitter_config'];
$youtube_config = $row_config['youtube_config'];
$address_config = $row_config['address_config'];
$phone_config = $row_config['phone_config'];
$email_config = $row_config['email_config'];

$appidfb_config = $row_config['appidfb_config'];
$appsecfb_config = $row_config['appsecfb_config'];
$callbackfb_config = $row_config['callbackfb_config'];
$appidgp_config = $row_config['appidgp_config'];
$appsecgp_config = $row_config['appsecgp_config'];
$callbackgp_config = $row_config['callbackgp_config'];

function.php : Pure Function

function InputForm($data, $server_conn){
  $data = trim($data);
  $data = strip_tags($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  $data = mysqli_real_escape_string($server_conn, $data);
  return $data;
}

Function For including HTML WITH PHP

function breakingnews($server_conn){
    $x = 0;
    $result = SiteQuery($server_conn, "SELECT id_news,title_news
    FROM data_news
    WHERE breaking_news = '1'
    ORDER BY time_news desc
    LIMIT 10");
    while ($row = $result->fetch_assoc()){
        $x++;
        if ($x === 1){
            echo '<div class="carousel-item active">
              <a href="'.RealURL().'infonews/'.$row['id_news'].'/'.text_dash($row['title_news']).'">
                '.$row['title_news'].'
              </a>
            </div>';
        } else {
            echo '<div class="carousel-item">
              <a href="'.RealURL().'infonews/'.$row['id_news'].'/'.text_dash($row['title_news']).'">
                '.$row['title_news'].'
              </a>
            </div>';
        }
    }
}

action.php

if (isset($_POST['submit-deletecat'])){
    if (isset($_SESSION['id_users'])){
        $id_category = InputForm($_POST['submit-deletecat'], $server_conn);

        $result = SiteQueryBind($server_conn, "DELETE FROM site_category WHERE id_category = ?", "i",
        $id_category);
        $message = $result;

    } else {
        $message = 'Please login first.';
    }
    echo "<script type='text/javascript'>alert('$message');</script>";

}

and require 'func/Facebook/autoload.php'; require 'func/Google/vendor/autoload.php'; this SDK from facebook and Google

Note : all the code above is an example that I took from each file, to clarify its usefulness.

  • Yes, because every time you have to load a single file to memory. Take a look at how to use Composer or build your own PHP Autoloader. https://stackoverflow.com/questions/3607543/what-is-autoload-in-php – Labradorcode Nov 14 '19 at 09:47
  • 1
    (You don’t need to prefix your question titles with `Q : ` [edited & removed] - you are on a Q&A site here, so that you are asking a question with a new post, is already implied …) – 04FS Nov 14 '19 at 09:59
  • sorry, i just see other question hehe – Collab Byte Nov 14 '19 at 10:00
  • Including all possible classes and functions on each and every page seems damn simple and very convenient - but as you said it is slow. You should include only those files which are really needed for the given script. Yes, those files will be compiled and cached by OpCache - but still it does not hurt if you put some additional thought. – IVO GELOV Nov 14 '19 at 12:42
  • so, in your mind, I have to separate each function, and enter only what is needed. correct ? – Collab Byte Nov 14 '19 at 13:13

0 Answers0