php-general Digest 17 Feb 2008 15:34:09 -0000 Issue 5298

Topics (messages 269421 through 269429):

Check time in between times
        269421 by: Johny Burns
        269423 by: Nathan Nobbe
        269424 by: Emilio Astarita

Re: Hex Strings Appended to Pathnames
        269422 by: Mick

Re: Fwrite Function
        269425 by: Nick Stinemates

Re: Session destruction problem
        269426 by: Nick Stinemates
        269428 by: Adil Drissi

Re: Protected ZIP file with password
        269427 by: Nick Stinemates

regex usage
        269429 by: Valedol

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
I am having fields in my table where I put times like 4:30pm in string 
format

Can  anybody help with function which helps detect.
Is it the current time between those fields?

function checkinzone($time1,$time2):boolean

Has to verify does the current time is in those 2 variables.

Thank you for your help. My ability with time and date funtions in PHP are 
not that great

--- End Message ---
--- Begin Message ---
On Feb 17, 2008 12:53 AM, Johny Burns <[EMAIL PROTECTED]> wrote:

> I am having fields in my table where I put times like 4:30pm in string
> format
>
> Can  anybody help with function which helps detect.
> Is it the current time between those fields?
>
> function checkinzone($time1,$time2):boolean
>
> Has to verify does the current time is in those 2 variables.
>
> Thank you for your help. My ability with time and date funtions in PHP are
> not that great


convert $time1 and $time2 to unix timestamps;
from there its a matter of basic logic; something like this (vaguely)

function isTimeBetween($time1, $time2) {
   if(!($lowerBound = date('U', $time1)) {  return false; }
   if(!($upperBound = date('U', $time2)) { return false; }
    $curTime = mktime();
   if($curTime > $lowerBound && $curTime < $upperBound) {
    return true;
   } else { return false; }
}

note; $time1 and $time2 will have to unix timestamps; this
function will verify that by passing them through the date() function.
http://www.php.net/manual/en/function.date.php

if you want something a little more flexible; check out; strtotime();
http://www.php.net/manual/en/function.strtotime.php

and also, the DateTime class will make for good reading ;)
http://www.php.net/manual/en/function.date-create.php

-nathan

--- End Message ---
--- Begin Message ---
"Johny Burns" <[EMAIL PROTECTED]> writes:



> I am having fields in my table where I put times like 4:30pm in string 
> format

Check this:
http://dev.mysql.com/doc/refman/5.0/en/date-and-time-types.html

Perhaps you could use a data type date for that.

> Can  anybody help with function which helps detect.
> Is it the current time between those fields?
>
> function checkinzone($time1,$time2):boolean
>
> Has to verify does the current time is in those 2 variables.

This may help you:

function strange2min($strange) {
  $h24h = substr($strange,-2);
  list($hour,$minute) = preg_split("/(?i:am|pm|:)/",$strange);
  if ($h24h == 'am' && $hour == 12) {
    $hour = 0;
  } elseif ($h24h == 'pm') {
    $hour = $hour + 12;
  }
  return ($hour * 60) + $minute;
}

function checkinzone($start,$end) {
  $now = (date('G') * 60) + date('i');
  $start = strange2min($start);
  $end = strange2min($end);
  return ( ($start <= $now ) &&($now <= $end));
}
// test
$start = "1:30am";
$end = "9:39am";
echo '<strong>', var_dump(checkinzone($start,$end)),'</strong>';


-- 

Emilio Astarita <[EMAIL PROTECTED]>

--- End Message ---
--- Begin Message ---
Nathan Rixham wrote:
Richard Lynch wrote:
I don't know if it's before/after, but PHP can't change the GET
request to something it wasn't...

So THAT was the URL requested.

You might have some kind of funky mod_rewrite rule messing you up...



On Tue, January 29, 2008 5:22 am, Mick wrote:
Richard Lynch wrote:
On Sun, January 27, 2008 7:57 am, Mick wrote:

Operating System: CentOS 4.6
PHP Version: 4.3.9-3.22.9
Zend Optimizer (free) version: 3.2.6

Hello.

I've got somewhat of a strange problem here involving Squirrelmail.
Basically, what is happening is that one of our customers is logged
out
of his Squirrelmail session at random intervals.  This can occur
when
he  goes to read an email or, after composing an email, when he
clicks
on the Send button.

The following log entries correspond with those times that the
customer
is logged out.

[error] [client X.X.X.X] File does not exist:
/var/www/squirrelmail/src/redirect.php3a5def33
[error] [client X.X.X.X] File does not exist:
/var/www/squirrelmail/src/redirect.php29e09f87
[error] [client X.X.X.X] File does not exist:
/var/www/squirrelmail/src/move_messages.phpf9f96dfb
[error] [client X.X.X.X] File does not exist:
/var/www/squirrelmail/src/redirect.phpdc6cc80a

So what would be the cause of appending those hex strings to those
pathnames?

You'll probably have to ask the squirrelMail guy...

Unless you can reproduce it with other applications, it's not in PHP
itself, probably.

PS
I'm a squirrelMail user, and I get logged out a lot too. :-(


Hi Richard.

Thank you for your reply.

You'll probably have to ask the squirrelMail guy...
I've already asked him, and he referred me to the PHP/Zend guys i.e.
to
here. ;)

Actually, what the access logs show for these events is this for
example:

"GET /squirrelmail/src/compose.php9e99b821 HTTP/1.1" 404
"GET /squirrelmail/src/redirect.php3a5def33 HTTP/1.1" 404

Do you know if logging for the access log is performed before or after
the URL is passed through to php?

Cheers,
Mick.





Hi Richard.

So THAT was the URL requested.
As I had suspected.
You might have some kind of funky mod_rewrite rule messing you up...
There is no rewrite rule.  It's an extremely strange problem.


Cheers,
Mick.

I see this is a strange problem, the puzzle for me though is why is the user getting logged out? surely a 404 can't end a session..

Hi Nathan.

Apologies for the delay. Been hectic here of late.  Anyhow, with regards to:

I see this is a strange problem, the puzzle for me though is why is the user getting logged out? surely a 404 can't end a session..

Ok. What happens is that with *every* operation e.g. Looking in the Inbox, or the Trash folder, Options etc, I can see in the logs that the user is logged out and then logged in again. So there must be cookies involved for this to work.

Cheers,
Mick.

--- End Message ---
--- Begin Message ---
Yuval Schwartz wrote:
> Hello,
>
> Can you please help me, I am writing code where I create a file and write to
> it from a form on a webpage and then read and display this file on the
> webpage.
> I want to change the color of the text that is written to the file.
> Do you know how I can do this?
>
> This is some of my code if you need clarification:
> * $boardFile = "MessageBoard.txt";
> $boardFileHandle = fopen($boardFile,'a') or die("can't open file");
> fwrite($boardFileHandle, $name);
> fwrite($boardFileHandle, $talk);
> fclose($boardFileHandle);
> }
> $boardFile = "MessageBoard.txt";
> $boardFileHandle = fopen($boardFile,"r");
> $talkR = fread($boardFileHandle, filesize($boardFile));
> fclose($boardFileHandle);
> echo $talkR;*
> **
> **
> Thanks
>
>   
First question is -- why aren't you using a database for this
information? I would recommend sqlite (http://www.sqlite.org/)

Now that that's taken care of, if you're trying to color the text on
output, I would do it like this:
_______________________________________________________________________
<?php

$name = "nick"; //added for testing
$talk = "a message"; //added for testing

$NAMEFORMAT = '<font color="red">';
$MESSAGEFORMAT = '<font color="blue">';


$boardFile = "MessageBoard.txt";
$boardFileHandle = fopen($boardFile,'a') or die("can't open file");

/*
 * Here we are going to write to the file, notice I added
        another line that prints a comma. This will be useful
        so that you can easily parse out and potentially
        format the 2 elements at will
 */
fwrite($boardFileHandle, $name);
fwrite($boardFileHandle, ","); // added
fwrite($boardFileHandle, $talk);
fclose($boardFileHandle);

$boardFile = "MessageBoard.txt";

$boardFileHandle = fopen($boardFile,"r");

/* removed
$talkR = fread($boardFileHandle, filesize($boardFile));
*/

while (($data = fgetcsv($boardFileHandle, 1000, ",")) !== FALSE) {
/*
 * put 1000byte buffer to $data, this also goes 1 line at a time.
 */
        echo $NAMEFORMAT . $data[0] . "</font>"; // print the name
        echo $MESSAGEFORMAT . $data[1]; // print the text
}

fclose($boardFileHandle);

?>


If you have any questions regarding the implementation I suggest the
following reading material:

        http://us3.php.net/manual/en/function.fgetcsv.php

Good luck!
==================
Nick Stinemates ([EMAIL PROTECTED])
http://nick.stinemates.org

AIM: Nick Stinemates
MSN: [EMAIL PROTECTED]
Yahoo: [EMAIL PROTECTED]
==================

--- End Message ---
--- Begin Message ---
Adil Drissi wrote:
> Hi everybody,
>
> I need help with sessions.
> I have a simple authentification relying only on
> sessions (i don't use cookies). After the user submits
> his username and password, the script checks if that
> corresponds to a record in a mysql table. If this is
> the case "$_SESSION['sessioname'] = $_POST['login'];".
> the $_SESSION['sessioname'] is checked in subsequent
> pages to see if the user is connected or not.
> The problem is after the user logs out, and after that
> uses the previous button of the browser he becomes
> connected. How can i prevent this please.
>
> Here is my logout.php:
>
> <?php
> session_start();
> unset($_SESSION["sessioname"]);
> session_destroy();
> header("location: index.php");
> ?>
>
> Thank you for advance
>
>
>       
> ____________________________________________________________________________________
> Looking for last minute shopping deals?  
> Find them fast with Yahoo! Search.  
> http://tools.search.yahoo.com/newsearch/category.php?category=shopping
>
>   
Is your session being set in any other place but your login page?

--- End Message ---
--- Begin Message ---
> >   
> Is your session being set in any other place but
> your login page?
> 
No, just in the page just to which the form of login
and password points.


      
____________________________________________________________________________________
Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  
http://tools.search.yahoo.com/newsearch/category.php?category=shopping

--- End Message ---
--- Begin Message ---
Petrus Bastos wrote:
> Hey folks,
>
>     Do you know how can I create a protected zip file with password? Is
> there anyway? I've search on the internet, but without success.
>
> Thank's in advance,
> Petrus Bastos.
>
>   
The easiest way to accomplish this would be to write a wrapper function
using the zip tool provided by (almost every) Linux distribution.

<?php

function zip($directory, $password, $saveAs) {
        return exec("zip -r $saveAs -P $password $directory";
}

print zip("/home/nick", "mypass", "/tmp/homebackup.zip");

?>

Please note: the -P flag can be monitored on the local system so it is
considered insecure.
If you're going to be accepting input, you should also wrap your
variables in escapeshellarg()

http://us3.php.net/zip
http://us.php.net/manual/en/function.exec.php

from the zip manual entry

THIS IS INSECURE!  Many multi-user operating  sys-tems
provide ways for any user to see the current command line of any other
user; even on stand-alone
systems there is always the threat of over-the-shoulder peeking. 
Storing the plaintext  password  as
part of a command line in an automated script is even worse.  Whenever
possible, use the non-echoing,
interactive prompt to enter passwords.  (And where security is truly
important, use strong encryption
such  as  Pretty  Good Privacy instead of the relatively weak encryption
provided by standard zipfile
utilities.)

==================
Nick Stinemates ([EMAIL PROTECTED])
http://nick.stinemates.org

AIM: Nick Stinemates
MSN: [EMAIL PROTECTED]
Yahoo: [EMAIL PROTECTED]
==================

--- End Message ---
--- Begin Message --- Is there a mothod to check string`s length with regex or the only way is using strlen?

I want string consisting of 4 digits
and check string with this code:

if (preg_match("/\d{4}/",$_POST[id]))
{ echo $_POST[id]; }

but preg_match  returns true when string consists of 4 or more digits
--
-

--- End Message ---

Reply via email to