Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #11997

Re: Regarding split text and match from data base

Path csiph.com!usenet.pasdenom.info!aioe.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Arno Welzel <usenet@arnowelzel.de>
Newsgroups comp.lang.php
Subject Re: Regarding split text and match from data base
Date Wed, 27 Nov 2013 12:31:03 +0100
Lines 83
Message-ID <5295D7F7.7080308@arnowelzel.de> (permalink)
References <676203c7-7d21-4513-92d5-7a9111c2eaa6@googlegroups.com> <2ca0dc82-85a2-4e57-b6b8-ada747640289@googlegroups.com> <l723lj$ugf$2@dont-email.me> <b9bfb809-4513-4262-a0c9-65acf113aa43@googlegroups.com> <5295D781.8090403@arnowelzel.de>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-Trace individual.net fFouoF2FmBeRFz/Ur7MUzw3h5oj/7AkO7KYMtSWtIEoZkLn1gf
Cancel-Lock sha1:KDocKHp44J/gmZlo/GkQi61opn4=
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.1.1
In-Reply-To <5295D781.8090403@arnowelzel.de>
Xref csiph.com comp.lang.php:11997

Show key headers only | View raw


Am 27.11.2013 12:29, schrieb Arno Welzel:

> Am 27.11.2013 06:22, schrieb jalaf28@gmail.com:
> 
[...]
>> 	$j +=21;
>> 	$k +=21;
>> 		
>> }
> 
> This makes no sense - you first select ALL records which you then don't
> use at all.
> 
> You also assume that every 21th character a new output line of arp

Of course "element", not "character"...

> begins - an very insecure assumption and even more worse you loop
> through the number of records in your mac_add table - so you assume
> there are never more output lines in arp -a than records in your
> database. Therefore if arp will output 15 lines and your table only has
> 10 records you would always miss 5 lines - since the loop only handles
> the 10 records.
> 
> If you want to make sure you get a result for every output line from
> "arp -a" you should split the lines of the output and loop through that
> and not the database records.
> 
> This is just a quick & dirty hack and may contain typos - but you may
> get the idea:
> 
> <?php
> $ln=@mysql_connect("localhost","root","");
> 
> if(!$ln)
> {
>   // TODO: Gracefully error handling - and not just
>   // terminating the script
>   die("Could not Connect to the database");
> }
> 
> echo "<table>";
> 
> // Execute "arp -a" with the output lines in the $output array
> // and the return code of the arp command in $returncode
> exec("arp -a", $output, $returncode);
> 
> // TODO: Check $returncode and handle errors
> 
> // Loop through all output lines from the arp command
> foreach($output as $line)
> {
>   // TODO: Check, if $line contains an IP/Mac address at all
>   $elements = explode(" ", $line);
> 
>   // Build query to look up the entry for a given MAC address
>   $query = "select * from mac_add where mac_id='".
>     mysql_real_escape_string($elements[32])."'";
> 
>   // Execute query
>   $recordset = mysql_query($query);
> 
>   // Fetch result and output it if there is one
>   if($record = mysql_fetch_array($recordset))
>   {
>     echo "<tr>" .
>       "<td>" . htmlspecialchars($elements[21]) . "</td>" .
>       "<td>" . htmlspecialchars($record[0]) . "</td>" .
>       "<td>" . htmlspecialchars($record[1]) . "</td>" .
>       "</tr>";
>   }
> }
> 
> echo "</table>";
> 
> mysql_close();
> ?>


-- 
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Regarding split text  and match from data base jalaf28@gmail.com - 2013-11-22 03:28 -0800
  Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-22 09:24 -0500
  Re: Regarding split text  and match from data base Arno Welzel <usenet@arnowelzel.de> - 2013-11-22 16:34 +0100
    Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-22 10:54 -0500
      Re: Regarding split text  and match from data base Arno Welzel <usenet@arnowelzel.de> - 2013-11-22 17:50 +0100
        Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-22 13:57 -0500
          Re: Regarding split text  and match from data base Arno Welzel <usenet@arnowelzel.de> - 2013-11-23 08:52 +0100
            Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-23 07:05 -0500
              Re: Regarding split text  and match from data base Arno Welzel <usenet@arnowelzel.de> - 2013-11-24 17:17 +0100
                Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-24 11:23 -0500
  Re: Regarding split text  and match from data base jalaf28@gmail.com - 2013-11-24 20:02 -0800
  Re: Regarding split text  and match from data base jalaf28@gmail.com - 2013-11-24 22:09 -0800
  Re: Regarding split text  and match from data base jalaf28@gmail.com - 2013-11-24 22:35 -0800
    Re: Regarding split text  and match from data base Arno Welzel <usenet@arnowelzel.de> - 2013-11-25 08:35 +0100
      Re: Regarding split text  and match from data base Arno Welzel <usenet@arnowelzel.de> - 2013-11-25 08:36 +0100
    Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-25 09:31 -0500
  Re: Regarding split text  and match from data base jalaf28@gmail.com - 2013-11-25 21:32 -0800
  Re: Regarding split text  and match from data base jalaf28@gmail.com - 2013-11-25 21:41 -0800
    Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-26 07:20 -0500
      Re: Regarding split text  and match from data base jalaf28@gmail.com - 2013-11-26 21:22 -0800
        Re: Regarding split text  and match from data base Arno Welzel <usenet@arnowelzel.de> - 2013-11-27 12:29 +0100
          Re: Regarding split text  and match from data base Arno Welzel <usenet@arnowelzel.de> - 2013-11-27 12:31 +0100
        Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-27 09:57 -0500
          Re: Regarding split text  and match from data base Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-11-28 12:27 +0000
            Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-28 11:01 -0500
              Re: Regarding split text  and match from data base Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-11-28 18:51 +0000
                Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-28 19:27 -0500
                Re: Regarding split text  and match from data base Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-11-29 02:34 +0000
                Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-28 22:47 -0500
                Re: Regarding split text  and match from data base Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-11-29 05:01 +0000
                Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-29 07:40 -0500
                Re: Regarding split text  and match from data base Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-11-29 13:58 +0000

csiph-web