[PHP] Storing passwords in session variables

2012-12-11 Thread Paul Halliday
Hi,

I have a form that has username and password fields. While the form
exists and contains various other fields the most common mode of
operation is to have the form auto submit if it has enough arguments
in the URL. So, someone is using an external program that has links
wired as such:

test.php?start=1end=2this=blahthat=arghusername=userpassword=pass

and when they hit that URL it sees it has enough arguments, fires and
returns the result.

Client - Server is encrypted,  can I toss these into session variables?

The user could be coming from multiple frontends and it would be nice
to forgo the user/pass in the url; give the username focus on the
first visit let them drop their creds and then store them into the
session so with each subsequent hit they can just get their results.

Make sense?

Note: I need to pass the credentials to an external app each time a
request is made.

Thanks.

-- 
Paul Halliday
http://www.pintumbler.org/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Storing passwords in session variables

2012-12-11 Thread Paul Halliday
On Tue, Dec 11, 2012 at 9:02 AM, Ashley Sheridan
a...@ashleysheridan.co.ukwrote:

 **
 On Tue, 2012-12-11 at 08:46 -0400, Paul Halliday wrote:

 Hi,

 I have a form that has username and password fields. While the form
 exists and contains various other fields the most common mode of
 operation is to have the form auto submit if it has enough arguments
 in the URL. So, someone is using an external program that has links
 wired as such:

 test.php?start=1end=2this=blahthat=arghusername=userpassword=pass

 and when they hit that URL it sees it has enough arguments, fires and
 returns the result.

 Client - Server is encrypted,  can I toss these into session variables?

 The user could be coming from multiple frontends and it would be nice
 to forgo the user/pass in the url; give the username focus on the
 first visit let them drop their creds and then store them into the
 session so with each subsequent hit they can just get their results.

 Make sense?

 Note: I need to pass the credentials to an external app each time a
 request is made.

 Thanks.

 --
 Paul Hallidayhttp://www.pintumbler.org/


 It looks like you're trying to re-invent authorisation procedures.
 Typically, the first request logs a client in and retrieves a hashed key,
 which is then used in all subsequent requests so that the server can
 correctly verify the client. You can do this the way you suggested with the
 session, but you must ensure that the session id is passed across to your
 script by each of the connecting clients. That will be done either as part
 of the head request, or as an extra parameter in the URL.

   Thanks,
 Ash
 http://www.ashleysheridan.co.uk



I understand that. The username/pass are NOT for authentication to the
form, they are being passed to exec();
So, I guess in this context they are just arguments.

Providing I handle the session properly, does it make sense to toss these
arguments into session variables?


Re: [PHP] Storing passwords in session variables

2012-12-11 Thread Paul Halliday
On Tue, Dec 11, 2012 at 9:12 AM, Ashley Sheridan
a...@ashleysheridan.co.ukwrote:

 **
 On Tue, 2012-12-11 at 08:58 -0400, Paul Halliday wrote:

 On Tue, Dec 11, 2012 at 9:02 AM, Ashley Sheridan a...@ashleysheridan.co.uk
 wrote:

  On Tue, 2012-12-11 at 08:46 -0400, Paul Halliday wrote:

 Hi,

 I have a form that has username and password fields. While the form
 exists and contains various other fields the most common mode of
 operation is to have the form auto submit if it has enough arguments
 in the URL. So, someone is using an external program that has links
 wired as such:

 test.php?start=1end=2this=blahthat=arghusername=userpassword=pass

 and when they hit that URL it sees it has enough arguments, fires and
 returns the result.

 Client - Server is encrypted,  can I toss these into session variables?

 The user could be coming from multiple frontends and it would be nice
 to forgo the user/pass in the url; give the username focus on the
 first visit let them drop their creds and then store them into the
 session so with each subsequent hit they can just get their results.

 Make sense?

 Note: I need to pass the credentials to an external app each time a
 request is made.

 Thanks.

 --
 Paul Hallidayhttp://www.pintumbler.org/



   It looks like you're trying to re-invent authorisation procedures.
 Typically, the first request logs a client in and retrieves a hashed key,
 which is then used in all subsequent requests so that the server can
 correctly verify the client. You can do this the way you suggested with the
 session, but you must ensure that the session id is passed across to your
 script by each of the connecting clients. That will be done either as part
 of the head request, or as an extra parameter in the URL.

   Thanks,
 Ash
 http://www.ashleysheridan.co.uk




 I understand that. The username/pass are NOT for authentication to the
 form, they are being passed to exec();

 I would say this is the username/password being used precisely for
 authentication, otherwise you wouldn't need to pass them across to exec()

  So, I guess in this context they are just arguments.

 Providing I handle the session properly, does it make sense to toss these
 arguments into session variables?

 You can use the session, but the only way your script will know what
 session to use is if the clients are sending the session id as part of
 their request.



   Thanks,
 Ash
 http://www.ashleysheridan.co.uk



Thanks :) I see the flaw in my reasoning. Just needed to talk about it!


Re: [PHP] Array help.

2012-10-24 Thread Paul Halliday
On Wed, Oct 24, 2012 at 2:40 PM, Samuel Lopes Grigolato
samuel.grigol...@gmail.com wrote:
 Could you try changing this:

 if($groupTest != FALSE) {

 to this:

 if($groupTest !== FALSE) {

 ?

Hah. Perfect! Thanks.


 -Mensagem original-
 De: Paul Halliday [mailto:paul.halli...@gmail.com]
 Enviada em: quarta-feira, 24 de outubro de 2012 15:38
 Para: PHP-General
 Assunto: [PHP] Array help.

 I am processing v4IP's and what I want to do is a prefix substitution if the
 3rd octet matches a predefined list $groupMappings. I went down this  path
 and it isn't working as expected. Drawing a blank on this one. Why does 40
 miss the comparison?

 $hostname = Z;
 $ips = array('10.1.40.1','10.1.41.1','10.1.1.1','10.1.40.1','10.9.1.1');

 foreach ($ips as $ip) {

 $groupMappings = array('40' ='A','41' ='B','1' ='C');

 $ocTest = explode(., $ip);
 $groupKeys = array_keys($groupMappings);
 $groupTest = array_search($ocTest[2], $groupKeys);

 if($groupTest != FALSE) {
 $hostGroup = $groupMappings[$groupKeys[$groupTest]];
 echo Hit! $ip : $hostname : $hostGroup\n;
 } else {
 $hostGroup = substr($hostname, 0,2);
 echo Miss! $ip : $hostname : $hostGroup\n;
 }
 }

 Miss! 10.1.40.1 : Z : Z
 Hit! 10.1.41.1 : Z : B
 Hit! 10.1.1.1 : Z : C
 Miss! 10.1.40.1 : Z : Z
 Hit! 10.9.1.1 : Z : C

 Thanks!

 --
 Paul Halliday
 http://www.pintumbler.org/

 --
 PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
 http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Awkward time processing

2012-08-02 Thread Paul Halliday
This is hideous, can anyone think of a more novel approach?

What I have is an array of values and timestamps:

17 15:31
16 15:32
27 15:33
14 15:34
11 15:35

now for a day I should have 1440 entries but there could be spotty
results, no data from say 11:59 - 13:00.
What I need is to sum the values for each hour interval.

Because the results could be spotty I figured I would need to use a
lookup table so that I could zero out any empty hours (this is going
to be graphed)

So I have this:

loop through the set above and do

$hour = explode(:, $row[0]);
$comp[] = $hour[0] . || . $row[1];

$c00 = $c01 = $c02 = $c03 = $c04  = 0;

for ($a = 0; $a  sizeof($comp); ++ $a) {
list($h,$c) = explode(||, $comp[$a]);

switch ($h) {
case 00: $c00 += $c; break;
case 01: $c01+= $c; break;
case 02: $c02 += $c; break;
case 03: $c03 += $c; break;
case 04: $c04 += $c; break;
.
}
}

Works but wow is it ugly..

Thoughts?

-- 
Paul Halliday
http://www.pintumbler.org/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Awkward time processing

2012-08-02 Thread Paul Halliday
On Thu, Aug 2, 2012 at 12:27 PM, Ashley Sheridan
a...@ashleysheridan.co.uk wrote:


 Paul Halliday paul.halli...@gmail.com wrote:

This is hideous, can anyone think of a more novel approach?

What I have is an array of values and timestamps:

17 15:31
16 15:32
27 15:33
14 15:34
11 15:35

now for a day I should have 1440 entries but there could be spotty
results, no data from say 11:59 - 13:00.
What I need is to sum the values for each hour interval.

Because the results could be spotty I figured I would need to use a
lookup table so that I could zero out any empty hours (this is going
to be graphed)

So I have this:

loop through the set above and do

$hour = explode(:, $row[0]);
$comp[] = $hour[0] . || . $row[1];

$c00 = $c01 = $c02 = $c03 = $c04  = 0;

for ($a = 0; $a  sizeof($comp); ++ $a) {
list($h,$c) = explode(||, $comp[$a]);

switch ($h) {
case 00: $c00 += $c; break;
case 01: $c01+= $c; break;
case 02: $c02 += $c; break;
case 03: $c03 += $c; break;
case 04: $c04 += $c; break;
.
}
}

Works but wow is it ugly..

Thoughts?

--
Paul Halliday
http://www.pintumbler.org/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

 Where is the data coming from? I would presume an SQL database? If so, you 
 could use a group by with a
substring to get the counts you need. MySQL happily allows this to be
done on date and datetime fields.

I am actually doing that already on the data coming in:

SELECT COUNT(signature) AS count,
SUBSTRING(CONVERT_TZ(timestamp,'+00:00','-03:00'),12,5) AS time..

as I am doing a minute breakdown as well. The query isn't cheap; about
half a second, so I was hoping to do my hourly consolidation in code
as I already have the data, instead of performing a second query.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Awkward time processing

2012-08-02 Thread Paul Halliday
:)

Perfect! Thank you.

On Thu, Aug 2, 2012 at 1:25 PM, Robert Williams rewilli...@thesba.com wrote:
 On 8/2/12 05:51, Paul Halliday paul.halli...@gmail.com wrote:


What I have is an array of values and timestamps:

17 15:31
16 15:32
27 15:33
14 15:34
11 15:35

now for a day I should have 1440 entries but there could be spotty
results, no data from say 11:59 - 13:00.
What I need is to sum the values for each hour interval.

 I may be misinterpreting what you're asking, but what about something like
 this:

 $times = array(
 17 = '15:31',
 16 = '15:32',
 27 = '15:33',
 14 = '15:34',
 11 = '15:35',
 27 = '16:33',
 14 = '17:34',
 11 = '11:35',
 11 = '11:36',
 );

 $sums = array_fill(0, 24, 0);

 foreach ($times as $value = $time) {
 $sums[substr($time, 0, 2)] += (integer)$value;
 }

 print_r($sums);

 This produces:


 /usr/bin/php /Volumes/Dev/Sites/playground/play4.php
 Array
 (
 [0] = 0
 [1] = 0
 [2] = 0
 [3] = 0
 [4] = 0
 [5] = 0
 [6] = 0
 [7] = 0
 [8] = 0
 [9] = 0
 [10] = 0
 [11] = 11
 [12] = 0
 [13] = 0
 [14] = 0
 [15] = 33
 [16] = 27
 [17] = 14
 [18] = 0
 [19] = 0
 [20] = 0
 [21] = 0
 [22] = 0
 [23] = 0
 )

 Process finished with exit code 0



 --
 Robert E. Williams, Jr.
 Associate Vice President of Software Development
 Newtek Businesss Services, Inc. -- The Small Business Authority
 https://www.newtekreferrals.com/rewjr
 http://www.thesba.com/







 Notice: This communication, including attachments, may contain information 
 that is confidential. It constitutes non-public information intended to be 
 conveyed only to the designated recipient(s). If the reader or recipient of 
 this communication is not the intended recipient, an employee or agent of the 
 intended recipient who is responsible for delivering it to the intended 
 recipient, or if you believe that you have received this communication in 
 error, please notify the sender immediately by return e-mail and promptly 
 delete this e-mail, including attachments without reading or saving them in 
 any manner. The unauthorized use, dissemination, distribution, or 
 reproduction of this e-mail, including attachments, is prohibited and may be 
 unlawful. If you have received this email in error, please notify us 
 immediately by e-mail or telephone and delete the e-mail and the attachments 
 (if any).

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Can I do this in a single match/replace?

2012-06-27 Thread Paul Halliday
I have lines that look like (I added intentional line breaks):

alert tcp $HOME_NET 1 - $EXTERNAL_NET any (msg:ET EXPLOIT NDMP
Notify Connect - Possible Backup Exec Remote Agent Recon;
flow:established,from_server; content:|00 00 05 02|; offset:16;
depth:20; content: |00 00 00 03|; offset: 28;
depth: 32; 
reference:url,www.ndmp.org/download/sdk_v4/draft-skardal-ndmp4-04.txt;
reference:url,doc.emergingthreats.net/bin/view/Main/2002068;
classtype:attempted-recon; sid:2002068; rev:8;)

So within this there are reference urls that I would like to turn into
links so that when they are rendered they can be clicked on.

Using preg_match and this pattern I can get the refs:

$pattern = '\reference:url,([^;]+;)\';

which gives me:

$matches[0] = www.ndmp.org/download/sdk_v4/draft-skardal-ndmp4-04.txt
$matches[1] = doc.emergingthreats.net/bin/view/Main/2002068

now what I would like to do is replace inline adding a href=http://;
. $matches[n] .  . $matches[n] . /a

Can this be done or do I need to say loop through matches (there can
be none or many) and do a str_replace.

Thoughts? Other ideas?

Thanks.

-- 
Paul Halliday
http://www.pintumbler.org/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: php form action breaks script

2012-06-14 Thread Paul Halliday
On Thu, Jun 14, 2012 at 10:17 PM, David Robley robl...@aapt.net.au wrote:
 Tim Dunphy wrote:

 Hello list,

  I was just wondering if I could get some opinions on a snippet of
 code which breaks a php web page.

  First the working code which is basically an html form being echoed by
  php:

 if ($output_form) {

   echo 'br /br /form action=sendemail.php method=post  

form action=sendemail.php

should be:

form action=sendemail.php ...

   label for=subjectSubject of email:/labelbr /
   input id=subject name=subject type=text size=30 /br /
   label for=elvismailBody of email:/labelbr /
    textarea id=elvismail name=elvismail rows=8
 cols=40/textareabr /
    input type=submit name=Submit value=Submit /
   /form';


   }

 However if I change the form action to this, it breaks the page
 resulting in a white screen of death:


   if ($output_form) {

   echo 'br /br /form action=?php echo $_SERVER['PHP_SELF']; ?
 method=post  
   label for=subjectSubject of email:/labelbr /
   input id=subject name=subject type=text size=30 /br /
   label for=elvismailBody of email:/labelbr /
    textarea id=elvismail name=elvismail rows=8
 cols=40/textareabr /
    input type=submit name=Submit value=Submit /
   /form';


   }

 Reverting the one line to this:

 echo 'br /br /form action=sendemail.php method=post  

 gets it working again. Now I don't know if it's an unbalanced quote
 mark or what's going on. But I'd appreciate any advice you may have.


 Best,
 tim

 If you check your apache log you'll probably see an error message. But the
 problem seems to be that your string you are trying to echo is enclosed in
 single quotes, and contains a string in ?php tags. Try something like

 echo 'br /br /form action=' . $_SERVER['PHP_SELF'] . '
 method=post ...etc



 Cheers
 --
 David Robley

 I haven't had any tooth decay yet, said Tom precariously.
 Today is Sweetmorn, the 20th day of Confusion in the YOLD 3178.


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
Paul Halliday
http://www.squertproject.org/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Need Part-time Coder

2011-12-27 Thread Paul Halliday
On Tue, Dec 27, 2011 at 6:55 PM, Fatih P. fatihpirist...@gmail.com wrote:
 On Wed, Dec 28, 2011 at 12:54 AM, Ashley Sheridan
 a...@ashleysheridan.co.ukwrote:

 On Tue, 2011-12-27 at 17:29 -0500, John R. Cornell II wrote:

  Email PHP sample for consideration


 ?php
 echo hello world;
 ?

 Reply to list with a few more details for a more detailed reply ;)


 ?php echo  ;) ; ?

?php
$a = array('he', 'llo', ' ', 'w', 'orld', '!');
for($i = 0, $ln = sizeof($a); $i  $ln; ++$i) { echo $a[$i]; }
?

-- 
Paul Halliday
http://www.squertproject.org/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Why does this script run out of memory?

2011-10-28 Thread Paul Halliday
On Fri, Oct 28, 2011 at 1:38 PM, Jim Long p...@umpquanet.com wrote:
 I'm running PHP 5.3.8 on FreeBSD 8.2 with MySQL 5.1.55.

 The script below is designed to be able to WHILE it's way through
 a MySQL query result set, and process each row.

 However, it runs out of memory a little after a quarter million
 rows.  The schema fields total to about 200 bytes per row, so
 the row size doesn't seem very large.

 Why is this running out of memory?

 Thank you!

 Jim

 ?php

 $test_db_host = localhost;
 $test_db_user = foo;
 $test_db_pwd  = bar;
 $test_db_name = farkle;

 $db_host = $test_db_host;
 $db_user = $test_db_user;
 $db_name = $test_db_name;
 $db_pwd  = $test_db_pwd;

 if (!($db_conn = mysql_connect( $db_host, $db_user, $db_pwd )))
        die( Can't connect to MySQL server\n );

 if (!mysql_select_db( $db_name, $db_conn ))
        die( Can't connect to database $db_name\n );

 $qry = select * from test_table order by contract;

 if ($result = mysql_query( $qry, $db_conn )) {

        $n = 0;
        while ($row = mysql_fetch_assoc( $result )) {
 // process row here
                $n++;
        } // while


Whats the difference between fetch_assoc and fetch_row?

I use:
while ($row = mysql_fetch_row($theQuery)) {
doCartwheel;
}

on just under 300 million rows and nothing craps out. I have
memory_limit set to 4GB though. Although, IIRC I pushed it up for GD
not mysql issues.

Same OS and php ver, MySQL is 5.1.48

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: mysql_fetch_array() vs mysql_fetch_assoc() WAS: Re: [PHP] Why does this script run out of memory?

2011-10-28 Thread Paul Halliday
On Fri, Oct 28, 2011 at 7:19 PM, Daniel Brown danbr...@php.net wrote:
 On Fri, Oct 28, 2011 at 18:13, Paul Halliday paul.halli...@gmail.com wrote:

 Whats the difference between fetch_assoc and fetch_row?

 I use:
 while ($row = mysql_fetch_row($theQuery)) {
    doCartwheel;
 }

 on just under 300 million rows and nothing craps out. I have
 memory_limit set to 4GB though. Although, IIRC I pushed it up for GD
 not mysql issues.

 Same OS and php ver, MySQL is 5.1.48

    Please don't hijack other's threads to ask a question.  I've
 started this as a new thread to address this question.

    mysql_fetch_array() grabs all of the data and places it in a
 simple numerically-keyed array.

    By contrast, mysql_fetch_assoc() grabs it and populates an
 associative array.  This means that the column names (or aliases, et
 cetera) become the keys for the array.  With mysql_fetch_assoc(), you
 can still call an array key by number, but it's not vice-versa with
 mysql_fetch_array().

    The difference in overhead, if you meant that (in which case, my
 apologies for reading it as a question of functional difference), is
 variable: it's based mainly on the difference between the bytes
 representing the integers used as keys in mysql_fetch_array() versus
 the size in bytes of the strings used as keys in mysql_fetch_assoc().

 --
 /Daniel P. Brown
 Network Infrastructure Manager
 http://www.php.net/


Sorry.

I was just throwing it out there with the hope that there might be a
tidbit that would help the OP.

I have a simliar setup and I can query far more than a 1/4 million
rows. What I offered is what I am doing differently.


-- 
Paul Halliday
http://www.squertproject.org/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] What is wrong with this preg_match?

2011-10-27 Thread Paul Halliday
I have the following:

if (isset($argc)) {
if ($argc == 1 || $argc  2 || !preg_match((\d{4}-\d{2}-\d{2}),
$argv[1])) {
echo \nUsage: $argv[0] -mm-dd\n\n;
exit;
} else {
$base_date = $argv[1];
}
} else {
$base_date = date('Y-m-d');
}

When I run it:

 $ ./process_patches.php 201-01-01

Usage: ./process_patches.php -mm-dd

patches@innm2 ~/Code/Oculi $ ./process_patches.php 2011-011-01

Usage: ./process_patches.php -mm-dd

patches@innm2 ~/Code/Oculi $ ./process_patches.php 2011-01-011

Works..

What am I doing wrong?

Thanks!

-- 
Paul Halliday
http://www.squertproject.org/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Any free online tests to test my PHP knowledge?

2011-09-22 Thread Paul Halliday
On Thu, Sep 22, 2011 at 6:44 PM, Paul M Foster pa...@quillandmouse.com wrote:
 On Thu, Sep 22, 2011 at 11:53:54AM -0600, Mike Hansen wrote:

 Does anyone know of a site that has an online test of PHP skills?
 I'd like to review my PHP knowledge.

 I've already run across this site:
 http://vladalexa.com/scripts/php/test/test_php_skill.html

 Thanks,

 Mike

 I've had to take online PHP tests twice for recruiters. My beefs are 1)
 they're not open book, and I code with a tab open to php.net all the
 time. (Who remembers which parameter comes first on which function call:
 needle or haystack?) 2) They never tell you *what* you got wrong. That's
 not very helpful.

 Mind you, these aren't free tests like you're probably talking about.
 They are through a vendor whom the recruiter probably pays to administer
 the test.

 Incidentally, despite having written an awful lot of working PHP code, I
 don't do well on those tests. Helps my confidence a lot, as you can
 imagine.

 Paul


Geez, closed book? I would have a hard time throwing:

?pph

together.

-- 
Paul Halliday
http://www.squertproject.org/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Path question.

2011-07-28 Thread Paul Halliday
I have a few scripts that use ../location/file

Is this interpreted differently on some systems?

Thanks.

-- 
Paul Halliday
http://www.squertproject.org/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Session question

2011-05-17 Thread Paul Halliday
Is it OK to have session_start as an include?

I have something like this:

// Session init
session_start();

function sKill() {
session_destroy();
session_unset();
header (Location: login.php);
exit();
}

function sInt() {
 header (Location: login.php);
 exit();
}

if (!(isset($_SESSION['sLogin'])  $_SESSION['sLogin'] != '')) {
 sKill();
}

// Session variables
if (!isset($_SESSION['sUser']))  { sInt(); }  else { $sUser  =
$_SESSION['sUser'];}
if (!isset($_SESSION['sEmail'])) { sInt(); }  else { $sEmail =
$_SESSION['sEmail'];}
if (!isset($_SESSION['sType']))  { sInt(); }  else { $sType  =
$_SESSION['sType'];}
if (!isset($_SESSION['sTime']))  { sInt(); }  else { $sTime  =
$_SESSION['sTime'];}
if (!isset($_REQUEST['id'])) { $id = 0; } else { $id = $_REQUEST['id'];}

// Kill the session if the ids dont match.
if ($id != $_SESSION['id']) {
sKill();
}

// Kill the session if timeout is exceeded.
if (isset($_SESSION['LAST_ACTIVITY'])  (time() -
$_SESSION['LAST_ACTIVITY']  $sTime)) {
sKill();
}

Can I just call this session.php and include it at the beginning of each file?

-- 
Paul Halliday
http://www.squertproject.org/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Protecting against session hijacking.

2011-03-23 Thread Paul Halliday
I am not sure I am doing this right,

I have login.php which does:

$ua = $_SERVER['HTTP_USER_AGENT'];
$ua .= rand(0,4200);
$ua = md5($ua);

and upon successful auth, I push them to the main program:

header (Location: squert.php?id=$ua);

at the beginning of squert.php I have:

if(!isset($_SESSION['sUser']))  { sKill(); }  else { $sUser  =
$_SESSION['sUser'];}
if(!isset($_SESSION['sEmail'])) { sKill(); }  else { $sEmail =
$_SESSION['sEmail'];}
if(!isset($_SESSION['sType']))  { sKill(); }  else { $sType  =
$_SESSION['sType'];}
if(!isset($_SESSION['sTime']))  { sKill(); }  else { $sTime  =
$_SESSION['sTime'];}
if(!isset($_REQUEST['id'])) { sKill(); }  else { $id = $_REQUEST['id'];}

sKill just does session unset|destroy and redirects to login.php.

Is this right? I am not sure that the id part is.

Thanks.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] 2 submit buttons.

2011-02-14 Thread Paul Halliday
I have 2 buttons on a page:

if (isset($_POST['botton1'])) {dothing1();}
if (isset($_POST['button2'])) {dothing2();}

They both work as intended when I click on them. If however I click
within a text box and hit enter, they both fire.

Is there a way to stop this?

Thanks.

-- 
Paul Halliday
http://www.pintumbler.org

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] 95th percentile of an array.

2011-01-29 Thread Paul Halliday
What is the quickest way to do this? Will stats_stat_percentile work?
If so, does anyone have examples of its operation?

Keep in mind that my math is terrible. Use small words :)

Thanks.

-- 
Paul Halliday
http://www.pintumbler.org

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] 95th percentile of an array.

2011-01-29 Thread Paul Halliday
On Sat, Jan 29, 2011 at 2:28 PM, Adam Richardson simples...@gmail.com wrote:
 For the nearest rank computation, you could use the following:

 $arr =
 array(12,89,65,23,90,99,9,15,56,67,3,52,78,12,10,88,77,77,77,77,77,77,77);
 sort($arr);
 $score_representing_95th_percentile = $arr[round((95/100) * count($arr) -
 .5)];
 echo $score_representing_95th_percentile; // 90


Perfect, exactly what I was looking for.

thank you.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Global or include?

2011-01-05 Thread Paul Halliday
Say you have 10 or so scripts and a single config file. If you have
main.php, functions1.php, functions2.php, functions3.php..

Does is hurt to do an include of the config file in each separate
script, even if you only need a few things from it,  or should you
just specify what you want with a 'global' within each
script/function?

Thanks!

-- 
Paul Halliday
http://www.pintumbler.org

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] timezone math problem.

2010-09-16 Thread Paul Halliday
I have the following:

#!/usr/local/bin/php
?php
$offset = date(Z);
$sDate = '2010-09-16';
$sTime = '00:00:00';
$eDate = '2010-09-17';
$eTime = '00:00:00';
$tmpStart0 = date($sDate $sTime);
$tmpEnd0 = date($eDate $eTime);
$startDate = date(Y-m-d H:i:s,strtotime($tmpStart0 . - . $offset
seconds));
$endDate = date(Y-m-d H:i:s,strtotime($tmpEnd0 . - . $offset seconds));
$when = timestamp BETWEEN \$startDate\ AND \$endDate\;
echo \n$offset\n$when\n\n;
?

Which returns:

machine1 (AST) PHP 5.2.6:
-10800
timestamp BETWEEN 2010-09-16 03:00:00 AND 2010-09-17 03:00:00

machine2 (MST) PHP 5.1.6:
-21600
timestamp BETWEEN 1969-12-31 17:00:00 AND 1969-12-31 17:00:00

Aside from upgrading the second box, is there some other logic that is wrong?

Thanks.
-- 
Paul Halliday
Ideation | Individualization | Learner | Achiever | Analytical
http://www.pintumbler.org

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Reformat array result.

2010-09-08 Thread Paul Halliday
I have been starting at this problem blankly for a couple hours now.
Hopefully someone can help.

I have a query that returns an event count grouped by hour:

timestamp:
Array ( [0] = 2010-09-08 03 [1] = 2010-09-08 04 [2] = 2010-09-08 05
[3] = 2010-09-08 06 [4] = 2010-09-08 07 [5] = 2010-09-08 08 [6] =
2010-09-08 09 [7] = 2010-09-08 10 [8] = 2010-09-08 11 [9] =
2010-09-08 12 [10] = 2010-09-08 13 [11] = 2010-09-08 14 [12] =
2010-09-08 15 [13] = 2010-09-08 16 ) 24

event count:
Array ( [0] = 1731 [1] = 885 [2] = 544 [3] = 668 [4] = 748 [5] =
754 [6] = 933 [7] = 2422 [8] = 6713 [9] = 31925 [10] = 18827 [11]
= 16743 [12] = 16875 [13] = 11775 )

Lets say that coming into this, I knew that the query spanned 36 hours
and started at 01:00. How can I manipulate the resulting array to
contain the missing time stamps and a value of 0.

The effect I am shooting for looks like this:

http://www.pintumbler.org/example.png

So 0  -  23 will be static and I just walk through the array and
populate those. If we hit 23, start a new row and continue. The matrix
will always be the same though.

I think I know what needs to happen, I just cant come up with the logic.

Any push in the right direction would be appreciated.
-- 
Paul Halliday
Ideation | Individualization | Learner | Achiever | Analytical
http://www.pintumbler.org

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] problem retrieving variables.

2010-09-02 Thread Paul Halliday
On Thu, Sep 2, 2010 at 5:43 PM, Jim Lucas li...@cmsws.com wrote:
 Paul Halliday wrote:
 I think I just might be missing the logic here.

 I have a page that is created and within this page, I include an
 iframe like this:

 $qp = urlencode($when $wFilter $aFilter);
 echo \rtrtd id=links colspan=2 style=\display:none; padding-left: 
 12px;\
           \rIFRAME id=\links-frame\ name=\links-frame\
 src=\edv.php?qp=$qp\ width=100% height=1000 frameborder=0
 scrolling=no/IFRAME
           \r/td
           \r/tr;

 When I call edv.php though, I can't $qp = $_REQUEST['qp'];

 What am I missing?

 Thanks.


 Just below your urlencode() call in the parent script place echo $qp; to see 
 if
 the value is what you expect?

 Then within edv.php add this

 var_dump($_REQUEST);

 and see if $_REQUEST['qp'] is there, and what it is.

 Jim




I think I see what I am doing wrong..

...
createlink function up here then...

?php $qp = $_REQUEST['qp'];?
html
body
form id=edv method=post action=edv.php
table width=100% border=0 cellpadding=1 cellspacing=0trtd align=left
input onMouseOver=style.backgroundColor='#ff';
onMouseOut=style.backgroundColor='#DD'; id=links name=links
type=submit value=create link graph style=font-size: 9px; border:
none; border: .5pt solid #00; background:#DD;
/td
?php
echo $qp;
if ($_REQUEST['links']) {
CreateLink($qp);
}
?
/form
/body
/html

I can't do what I am trying to do. Do I need to put it in a hidden
field within the form and then re-request?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Array help.

2010-07-30 Thread Paul Halliday
I have a query that may not always return a result for a value, I need
to reflect this with a 0. I am trying to overcome this by doing this
(the keys are ID's):

while ($row = mysql_fetch_row($statusQuery)) {

$cat = array(0=0,1=0,11=0,12=0,13=0,14=0,15=0,16=0,17=0,19=0);

switch ($row[1]) {
case 0: $cat[0] = $row[0]; break;
case 1: $cat[1] = $row[0]; break;
case 11: $cat[11] = $row[0]; break;
case 12: $cat[12] = $row[0]; break;
case 13: $cat[13] = $row[0]; break;
case 14: $cat[14] = $row[0]; break;
case 15: $cat[15] = $row[0]; break;
case 16: $cat[16] = $row[0]; break;
case 17: $cat[17] = $row[0]; break;
case 19: $cat[19] = $row[0]; break;
}

print_r($cat);
}

Which gives me this:

Array ( [0] = 15547 [1] = 0 [11] = 0 [12] = 0 [13] = 0 [14] = 0
[15] = 0 [16] = 0 [17] = 0 [19] = 0 )
Array ( [0] = 0 [1] = 0 [11] = 0 [12] = 0 [13] = 0 [14] = 0 [15]
= 30 [16] = 0 [17] = 0 [19] = 0 )

The query only return 2 rows:

15 | 30
0 | 15547

What am I doing wrong? Is there a more elegant way to achieve what I want?

Thanks.

-- 
Paul Halliday
Ideation | Individualization | Learner | Achiever | Analytical
http://www.pintumbler.org

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array help.

2010-07-30 Thread Paul Halliday
On Fri, Jul 30, 2010 at 3:44 PM, Joshua Kehn josh.k...@gmail.com wrote:

 On Jul 30, 2010, at 2:36 PM, Paul Halliday wrote:

 I have a query that may not always return a result for a value, I need
 to reflect this with a 0. I am trying to overcome this by doing this
 (the keys are ID's):

 while ($row = mysql_fetch_row($statusQuery)) {

        $cat = 
 array(0=0,1=0,11=0,12=0,13=0,14=0,15=0,16=0,17=0,19=0);

        switch ($row[1]) {
            case 0: $cat[0] = $row[0]; break;
            case 1: $cat[1] = $row[0]; break;
            case 11: $cat[11] = $row[0]; break;
            case 12: $cat[12] = $row[0]; break;
            case 13: $cat[13] = $row[0]; break;
            case 14: $cat[14] = $row[0]; break;
            case 15: $cat[15] = $row[0]; break;
            case 16: $cat[16] = $row[0]; break;
            case 17: $cat[17] = $row[0]; break;
            case 19: $cat[19] = $row[0]; break;
        }

        print_r($cat);
    }

 Which gives me this:

 Array ( [0] = 15547 [1] = 0 [11] = 0 [12] = 0 [13] = 0 [14] = 0
 [15] = 0 [16] = 0 [17] = 0 [19] = 0 )
 Array ( [0] = 0 [1] = 0 [11] = 0 [12] = 0 [13] = 0 [14] = 0 [15]s
 = 30 [16] = 0 [17] = 0 [19] = 0 )

 The query only return 2 rows:

 15 | 30
 0 | 15547

 What am I doing wrong? Is there a more elegant way to achieve what I want?

 Thanks.

 --
 Paul Halliday
 Ideation | Individualization | Learner | Achiever | Analytical
 http://www.pintumbler.org

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


 Paul-

 Why not say:

 $cat = array();
 if(isset($row[1])
 {
    $cat[$row[1]] = $row[0];
 }

 print_r($cat);

 Regards,

 -Josh

I need the results that don't have values assigned though.

ex:

c = 0
h = 9
t = 0
f = 21

Even if the query returned only:

h = 9
f = 21

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] MSSQL failing.

2010-07-09 Thread Paul Halliday

 What am I missing?


 Is the slash before the domain name above just a typo in your e-mail?
 It took a while to get mssql configured to where I could test it here
 since we're using Microsoft's SQL Server Driver for PHP (if you are
 running PHP under Windows, I'd strongly recommend this over the old
 mssql library anyway), but this worked:

 ?php

 $hostname = 'hostname:1433';

 $username = 'DOMAIN\Username';
 $password = 'password';

 $conn = mssql_connect($hostname, $username, $password) or die('Unable
 to connect');

 var_dump($conn);

 ?

 Andrew


It was a typo :) The installation is running on FreeBSD. I am looking
at TDS right now as a possible cause.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] MSSQL failing.

2010-07-09 Thread Paul Halliday
On Fri, Jul 9, 2010 at 7:12 AM, Paul Halliday paul.halli...@gmail.com wrote:

 What am I missing?


 Is the slash before the domain name above just a typo in your e-mail?
 It took a while to get mssql configured to where I could test it here
 since we're using Microsoft's SQL Server Driver for PHP (if you are
 running PHP under Windows, I'd strongly recommend this over the old
 mssql library anyway), but this worked:

 ?php

 $hostname = 'hostname:1433';

 $username = 'DOMAIN\Username';
 $password = 'password';

 $conn = mssql_connect($hostname, $username, $password) or die('Unable
 to connect');

 var_dump($conn);

 ?

 Andrew


 It was a typo :) The installation is running on FreeBSD. I am looking
 at TDS right now as a possible cause.


Got it:

In /usr/local/etc/freetds.conf:

[global]
   host = 10.x.x.x
   port = 1433
   client charset = UTF-8
   tds version = 8.0
   text size = 20971520

Thanks.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] MSSQL failing.

2010-07-08 Thread Paul Halliday
Is there something that needs to be tweaked or added to get this to
work? I am trying to connect to server 2008 w/ MS SQL 2008. I can see
the connections fail in the servers event logs if I take away \domain
from \domain\username (mixed auth is turned off) so the communication
is somewhat working.

What am I missing?

Settings are as follows:

MSSQL Support   enabled
Active Persistent Links 0
Active Links0
Library version FreeTDS

Directive   Local Value Master Value
mssql.allow_persistent  On  On
mssql.batchsize 0   0
mssql.charset   no valueno value
mssql.compatability_modeOff Off
mssql.connect_timeout   5   5
mssql.datetimeconvert   On  On
mssql.max_links Unlimited   Unlimited
mssql.max_persistentUnlimited   Unlimited
mssql.max_procs Unlimited   Unlimited
mssql.min_error_severity10  10
mssql.min_message_severity  10  10
mssql.secure_connection Off Off
mssql.textlimit Server default  Server default
mssql.textsize  Server default  Server default
mssql.timeout   60  60

Thanks

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Pagination?

2010-06-08 Thread Paul Halliday
I just spent the last 1/2 hour looking at many different solutions for
this. Is there a universal favorite?

Thanks.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Array group and sum values.

2010-05-11 Thread Paul Halliday
I have this:

while ($row = mysql_fetch_array($theData[0])) {

$col1[] = $row[0];
$col2[] = lookup($row[1]); // this goes off and gets the country name.

I then loop through col1 and col2 to produce something like this:

52  ARMENIA
215 CANADA
57  CANADA
261 COLOMBIA
53  EGYPT
62  INDIA
50  INDIA

Is there a way I can group these?

Thanks!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array group and sum values.

2010-05-11 Thread Paul Halliday
On Tue, May 11, 2010 at 2:25 PM, Jim Lucas li...@cmsws.com wrote:
 Paul Halliday wrote:
 I have this:

 while ($row = mysql_fetch_array($theData[0])) {

     $col1[] = $row[0];
     $col2[] = lookup($row[1]); // this goes off and gets the country name.

 I then loop through col1 and col2 to produce something like this:

 52    ARMENIA
 215   CANADA
 57    CANADA
 261   COLOMBIA
 53    EGYPT
 62    INDIA
 50    INDIA

 Is there a way I can group these?

 Thanks!


 Group them??

 How about this

 while ($row = mysql_fetch_array($theData[0])) {

    $col1[lookup($row[1])][] = $row[0];

 which, using the data you showed, will give you this


 Array
 (
    [ARMENIA] = Array
        (
            [0] = 52
        )

    [CANADA] = Array
        (
            [0] = 215
            [1] = 57
        )

    [COLOMBIA] = Array
        (
            [0] = 261
        )

    [EGYPT] = Array
        (
            [0] = 53
        )

    [INDIA] = Array
        (
            [0] = 62
            [1] = 50
        )

 )

 --
 Jim Lucas

   Some men are born to greatness, some achieve greatness,
       and some have greatness thrust upon them.

 Twelfth Night, Act II, Scene V
    by William Shakespeare


I was actually hoping to have them arranged like:

$col1[0] = INDIA
$col2[0] = 112
$col1[1] = CANADA
$col2[1] = 272
...

Thanks.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array group and sum values.

2010-05-11 Thread Paul Halliday
On Tue, May 11, 2010 at 4:03 PM, Jim Lucas li...@cmsws.com wrote:
 Paul Halliday wrote:
 On Tue, May 11, 2010 at 2:25 PM, Jim Lucas li...@cmsws.com wrote:
 Paul Halliday wrote:
 I have this:

 while ($row = mysql_fetch_array($theData[0])) {

     $col1[] = $row[0];
     $col2[] = lookup($row[1]); // this goes off and gets the country name.

 I then loop through col1 and col2 to produce something like this:

 52    ARMENIA
 215   CANADA
 57    CANADA
 261   COLOMBIA
 53    EGYPT
 62    INDIA
 50    INDIA

 Is there a way I can group these?

 Thanks!



 Group them??

 How about this

 while ($row = mysql_fetch_array($theData[0])) {

    $col1[lookup($row[1])][] = $row[0];

 which, using the data you showed, will give you this


 Array
 (
    [ARMENIA] = Array
        (
            [0] = 52
        )

    [CANADA] = Array
        (
            [0] = 215
            [1] = 57
        )

    [COLOMBIA] = Array
        (
            [0] = 261
        )

    [EGYPT] = Array
        (
            [0] = 53
        )

    [INDIA] = Array
        (
            [0] = 62
            [1] = 50
        )

 )

 --
 Jim Lucas

   Some men are born to greatness, some achieve greatness,
       and some have greatness thrust upon them.

 Twelfth Night, Act II, Scene V
    by William Shakespeare


 I was actually hoping to have them arranged like:

 $col1[0] = INDIA
 $col2[0] = 112
 $col1[1] = CANADA
 $col2[1] = 272
 ...

 Thanks.


 Well, then take what I gave you and do this:

 $group[lookup($row[1])][] = $row[0];

 foreach ( $group AS $x = $y )
 {
        $col1[] = $x;
        $col2[] = array_sum($y);
 }


 In the end you will end up with this

 plaintext?php

 $data = array(
                array(52,       'ARMENIA'),
                array(215,      'CANADA'),
                array(57,       'CANADA'),
                array(261,      'COLOMBIA'),
                array(53,       'EGYPT'),
                array(62,       'INDIA'),
                array(50,       'INDIA'),
                );

 foreach ( $data AS $row )
 {
        $group[$row[1]][] = $row[0];
 }

 print_r($group);

 foreach ( $group AS $x = $y )
 {
        $col1[] = $x;
        $col2[] = array_sum($y);
 }

 print_r($col1);
 print_r($col2);




Perfect! and a lot simpler than I thought.

Thanks.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] upload directly into a resource?

2010-05-03 Thread Paul Halliday
I have some code that is currently static. It runs via Cron,
generating images which can then be viewed via some other PHP.

What I want to do is allow a user to upload data which I can then pipe
directly into the existing program to produce on the fly images. I am
looking at this:

http://www.php.net/manual/en/features.file-upload.post-method.php

My existing code looks like this:

$theData = aQuery($gType, $gSdate, $gStime, $gEdate, $gEtime, $gFilter, $base);

while ($row = mysql_fetch_array($theData[0])) {

$hit = yes;

$src_ip[] = $row[0];
$dst_ip[] = $row[1];
$sig_desc[] = wordwrap($row[2],20,\\n);

if ($gType == 02) {
$hit_count[] = $row[3];
}

$rec ++;
if ( $rec == $recCount ) {
break;
}

}

// Open Afterglow and feed it our results

$glowCmd = $glowPath -c $glowProps $glowArgs | $dotPath $dotArgs $dotOut;

$dspec = array(
0 = array(pipe, r),
1 = array(pipe, w),
2 = array(file, $glowErr, a)
);

$process = proc_open($glowCmd, $dspec, $pipes, $baseDir);


If you are following the gist, what is the easiest way to put the
uploaded file into $theData?

aQuery just returns the result of a mysql select; so is it just a
matter of using fgetcsv as the action in the stub taken from the file
upload link?

Thanks.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Replace a space with a newline every 2 spaces

2010-04-22 Thread Paul Halliday
Ex:

This is the string and it is this long

This is
the string
and it
is this
long

I found some long functions to achieve this but I couldn't help but
think that it could be done in a couple lines.

Possible?

Thanks.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] A cleaner way to do this?

2010-03-25 Thread Paul Halliday
I am working on a parser for logs from a spam firewall. The format is
predictable until it reaches a certain point. It then varies greatly.

There are 2 things I want to grab from this area; the size of the
message (if it exists) and the subject (if it exists)

The line might look something like this:

- 2 39 some.text.here SZ:1825 SUBJ: A subject here

but it could also look like this:

5 6 421 Error: timeout

or this:

5 6 421 Client disconnected

All I really want is the value for each, not the prefix stuff. Which
means I still need more below, yuck.

I am doing it like this:

$remainder = explode( , $theLine, 18);
$s_size = '/SZ:\d+/';
$s_subject = '/SUBJ:.+/';

preg_match($s_size,$remainder[17],$a);
preg_match($s_subject,$remainder[17],$b);

if (count($a)  0) {
$size = $a[0];
} else {
$size = 0;
}

if (count($b)  0) {
$subject = $b[0];

} else {
$subject = -;
}

Is there any way to clean this up a bit?

thanks.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Help with exec.

2010-03-03 Thread Paul Halliday
I need to pipe some data to an external application.

I have this:

while ($row = mysql_fetch_array($theData[0])) {
$src_ip[] = $row[0];
$dst_ip[] = $row[1];
$sig_desc[] = $row[2];

$rec ++;
if ( $rec == $recCount ) {
break;
}
}

for ($i = 0; $i  sizeof($src_ip); $i++) {
$tmpResult[] = $sig_desc[$i],$src_ip[$i],$dst_ip[$i]\n;
}


The external program is called like:

cat results.csv | theprogram outputfilename

Is there a way mimic this w/o outputting $tmpResult to a file first?

Thanks.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Help with exec.

2010-03-03 Thread Paul Halliday
I work by example :)

I can't find enough of an example to get me going with this.

I have this:

$glow = popen('afterglow.pl -c color.properties -s -e 3 -p 1 -l 2000 |
neato -Tpng -o /usr/local/www/test.png','r');

how do I feed my array to that?

Thanks.

On Wed, Mar 3, 2010 at 9:04 AM, Richard Quadling
rquadl...@googlemail.com wrote:
 On 3 March 2010 13:01, Paul Halliday paul.halli...@gmail.com wrote:
 I need to pipe some data to an external application.

 I have this:

 while ($row = mysql_fetch_array($theData[0])) {
    $src_ip[] = $row[0];
    $dst_ip[] = $row[1];
    $sig_desc[] = $row[2];

    $rec ++;
    if ( $rec == $recCount ) {
            break;
    }
 }

 for ($i = 0; $i  sizeof($src_ip); $i++) {
    $tmpResult[] = $sig_desc[$i],$src_ip[$i],$dst_ip[$i]\n;
 }


 The external program is called like:

 cat results.csv | theprogram outputfilename

 Is there a way mimic this w/o outputting $tmpResult to a file first?

 Thanks.

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



 I believe you can use popen() to open theprogram and pipe to it the
 content and read back the results. All without writing to any files.



 --
 -
 Richard Quadling
 Standing on the shoulders of some very clever giants!
 EE : http://www.experts-exchange.com/M_248814.html
 EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
 Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731
 ZOPA : http://uk.zopa.com/member/RQuadling


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Help with exec.

2010-03-03 Thread Paul Halliday
and its that easy!

it took me a minute to figure out; but all I had to do was:

if (is_resource($process)) {

for ($i = 0; $i  sizeof($src_ip); $i++) {
fwrite($pipes[0], $sig_desc[$i],$src_ip[$i],$dst_ip[$i]\n);
}

fclose($pipes[0]);
fclose($pipes[1]);
proc_close($process);
}

thanks.

On Wed, Mar 3, 2010 at 10:08 AM, Ian php_l...@fishnet.co.uk wrote:
 On 03/03/2010 13:01, Paul Halliday wrote:
 I need to pipe some data to an external application.

 I have this:

 while ($row = mysql_fetch_array($theData[0])) {
     $src_ip[] = $row[0];
     $dst_ip[] = $row[1];
     $sig_desc[] = $row[2];

     $rec ++;
     if ( $rec == $recCount ) {
             break;
     }
 }

 for ($i = 0; $i  sizeof($src_ip); $i++) {
     $tmpResult[] = $sig_desc[$i],$src_ip[$i],$dst_ip[$i]\n;
 }


 The external program is called like:

 cat results.csv | theprogram outputfilename

 Is there a way mimic this w/o outputting $tmpResult to a file first?

 Thanks.


 Hi,

 I have used this code to feed data to gpg and read back the encrypted
 result, Im sure you can adapt it to your needs.

 function Encrypt($data){

        # http://www.theoslogic.com/scripts/php-gpg/

        $gpg_command=/usr/bin/gpg $parameters;

        $errLog = /tmp/errors.log;

        $dspecs = array(
                0=array(pipe, r),
                1=array(pipe, w),
                2=array(file, $errLog, a)
        );

        $encrypted=;
        $procdata=;

        $gpgproc = proc_open($gpg_command, $dspecs, $pipes);

        if (is_resource($gpgproc)) {
                fwrite($pipes[0], $data);
                fclose($pipes[0]);

                while($procdata = fgets($pipes[1], 1024)) {
                        $encrypted .= $procdata;
                }
                fclose($pipes[1]);
        }

        return $encrypted;
 }

 It works really well.

 Regards

 Ian
 --


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] ip-to-country

2009-10-19 Thread Paul Halliday
You might find this useful:

http://sites.google.com/site/interrupt0x13h/code/ip2c

On Sun, Oct 18, 2009 at 4:03 PM, SED s...@sed.is wrote:
 Hi,

 How can I access an index for IP to a country (or a more detailed location)?
 I have not yet found a function for that in PHP nor a free to use website
 that offers a remote search.

 Perhaps, there is another solution - any ideas?

 Regards,
 Summi




 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] What is the best way to process live data?

2009-08-29 Thread Paul Halliday
For those of you that remember (not likely but anyway) I am working on
some code that splits CLF records and feeds them into a database.

What I need to do now is automate it.

So what I have is a program (urlsnarf) that redirects its output
(simple cmd  file.txt) to a file. The script currently processes
this output line by line and does the SQL foo - i.e. script.php
/the/file.txt

Should I:

1) do away with redirecting the output from urlsnarf to a file and
have the script run the process and have some kind of handle on it;
foreach kinda thing?
2) keep outputting the info to a persistent file, reading any new
appends and periodically cull this file. Seems like a waste of I/O if
#1 is possible.
3) other options?

Any help/push in the right direction is appreciated.

Thanks.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Clean break.

2009-07-31 Thread Paul Halliday
Whats the cleanest (I have a really ugly) way to break this:

[21/Jul/2009:00:00:47 -0300]

into:

date=21/jul/2009
time=00:00:47

Caveats:

1) if the day is  10 the beginning of the string will look like [space1/...
2) the -0300 will differ depending on DST or TZ. I don't need it
though, it just happens to be there.

This is what I have (it works unless day  10):

$theParts = split([\], $theCLF);

// IP and date/time
$tmpParts = explode( , $theParts[0]);
$theIP = $tmpParts[0];
$x = explode(:, $tmpParts[3]);
$theDate = str_replace([,, $x[0]);
$theTime = $x[1]:$x[2]:$x[3];

the full text for this part looks like:

10.0.0.1 - - [21/Jul/2009:00:00:47 -0300] ... more stuff here

Anyway, any help would be appreciated.

thanks.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Clean break.

2009-07-31 Thread Paul Halliday
I was trying to stay away from regex as much as possible due to the
overhead? I might be wrong here.

This script will be parsing a lot of requests/sec. Thousands, maybe
more, which it also needs to toss into a DB. I want to try and keep it
as fast as possible. This is tricky when you don't know what you are
doing :). My coding is limited to hammering away at the search box on
php.net until I get a push in the right direction. It's just a hack
from there.

Using phpster's substr suggestion has already sped this up considerably.


2009/7/31 Ollisso olli...@fromru.com:
 On Sat, 01 Aug 2009 00:22:21 +0300, Paul Halliday paul.halli...@gmail.com
 wrote:

 Whats the cleanest (I have a really ugly) way to break this:

 [21/Jul/2009:00:00:47 -0300]

 into:

 date=21/jul/2009
 time=00:00:47

 ...
 Why not just use regexp ?

 For example:

 $string = long text.. multiply lines...
        [21/Jul/2009:00:00:47 -0300]

        [ 1/Jul/2009:00:00:47 -0300]

        [22/Jul/2009:00:00:47 -0300];


 preg_match_all('#\[([ 0-9a-zA-Z/]+):([0-9:]+)
 [^]]+\]#',$string,$matches,PREG_SET_ORDER);

 print_r($matches);

 Output:
 Array
 (
    [0] = Array
        (
            [0] = [21/Jul/2009:00:00:47 -0300]
            [1] = 21/Jul/2009
            [2] = 00:00:47
        )

    [1] = Array
        (
            [0] = [ 1/Jul/2009:00:00:47 -0300]
            [1] =  1/Jul/2009
            [2] = 00:00:47
        )

    [2] = Array
        (
            [0] = [22/Jul/2009:00:00:47 -0300]
            [1] = 22/Jul/2009
            [2] = 00:00:47
        )

 )


 --

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php