Search code examples
phpoopforeachfwrite

fwrite put table with foreach


I want to make html file that while be a ip adress and insert what client do via $_SERVER

My problem is that i cant make table in that file so code is this

FTP

public static function Write($Wfile, $Wtext)
{
    $open = fopen($Wfile, "w+");
    fwrite($open, $Wtext);
}

File to create log

public function __construct()
{
chdir("Log");
$this->_file = $_SERVER['REMOTE_ADDR'] .".html";
if(!is_file($this->_file)){
    ftpFile::Write($this->_file,$this->Standards());
}

public function Standards()
{
    $html = "<html>\r\n <body>\r\n <table cellpadding='10'>";
    return $html;
}

AND WHAT I WANT TO INSERT NOW

        public function Set()
        {
    $indicesServer = array(
    'PHP_SELF', 
    'argv', 
    'argc', 
    'GATEWAY_INTERFACE', 
    'SERVER_ADDR', 
    'SERVER_NAME', 
    ......
foreach ($indicesServer as $arg){ 
return '<tr><td>'.$arg.'</td><td>' . $_SERVER[$arg] . '</td></tr>'; 
}

so i try return, echo, print, file put content and i only get one result and that is last in my array.

ONCE Again i want to create log for user that come to my site and everthing inside $_SERVER write one time when sesion_id active and every where client go i want to insert and what $_POST insert in that file. Many of that i do only this is need to be fixed... TNX all


Solution

  • Your bottom code snippet doesn't work because you are attempting to return inside foreach loop: you can only return from a function once. Try this:

    public function Set()
    {
        $indicesServer = array(
            'PHP_SELF', 
            'argv', 
            'argc', 
            'GATEWAY_INTERFACE', 
            'SERVER_ADDR', 
            'SERVER_NAME', 
            ......
    
        $ret = "";
        foreach ($indicesServer as $arg)
            $ret .= '<tr><td>'.$arg.'</td><td>' . $_SERVER[$arg] . '</td></tr>'; 
        return $ret;
    }