php-general Digest 26 Nov 2004 15:42:47 -0000 Issue 3135

Topics (messages 202874 through 202898):

Odd Behaviour: DIE function
        202874 by: Andre Dubuc
        202875 by: Jon-Eirik Pettersen

remember me cookie
        202876 by: Justin French
        202877 by: John Nichel

Re: Getting static member for a class which name is stored in a variable
        202878 by: Jake Press
        202880 by: Greg Beaver
        202883 by: Simas Toleikis
        202898 by: Daniel Schierbeck

Re: intalling pear:db
        202879 by: Greg Beaver
        202881 by: Ryan King

Re: NH05 to 5, NH07 to 7
        202882 by: Hidayet Dogan
        202887 by: Ford, Mike

fedora core 3 mail() not working from web
        202884 by: Minuk Choi
        202888 by: Angelo Zanetti

Problem with recursion and FTP transfer
        202885 by: kioto.slacky.it
        202889 by: Raditha Dissanayake

test
        202886 by: franco bevilacqua

Sending text file to users
        202890 by: Rosen

rounding down
        202891 by: Brad Ciszewski
        202892 by: John Nichel
        202893 by: David Bevan
        202894 by: Marek Kilimajer

Script Name
        202895 by: Jerry Swanson
        202896 by: John Nichel
        202897 by: Robert Cummings

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've noticed some strange behaviour with respect to validation of user input. 
Normally, using Linux, the die function in user input validation works as 
expected. However, the same code in IE, the DIE function does not work as 
expected.

I've noticed that fields, that should die and barf an error message, seem to 
allow no input. Often, I notice that the user has entered a different 
spelling as well. I'm puzzled by this (Furthermore, I wasn't aware the user 
could change the contents of a dropdown select list [I cannot duplicate it in 
Linux). Since one of the affected fields receives its input from an included 
file (provcountry.dpn), perhaps this ius an IE issue??

provcountry.dpn

<td><b>Country &nbsp;</b></td>
<td><SELECT NAME=rcountry>
 <option selected>Choose from List
 <OPTION>USA
 /* list of countries follows */


snippet code in validation page:

<?php
...

if ($_POST['rcountry'] == "Choose from List") die ("<h5><br><br>Please choose
your  Country from the drop-down list<br><br><br>Click 'Back' on your
 browser to enter this information</h5>");

...
?>

Any pointers of what I'm missing here would be appreciated.

Tia,
Andre

--- End Message ---
--- Begin Message --- Andre Dubuc wrote:
I've noticed some strange behaviour with respect to validation of user input. Normally, using Linux, the die function in user input validation works as expected. However, the same code in IE, the DIE function does not work as expected.

I've noticed that fields, that should die and barf an error message, seem to allow no input. Often, I notice that the user has entered a different spelling as well. I'm puzzled by this (Furthermore, I wasn't aware the user could change the contents of a dropdown select list [I cannot duplicate it in Linux). Since one of the affected fields receives its input from an included file (provcountry.dpn), perhaps this ius an IE issue??

provcountry.dpn

<td><b>Country &nbsp;</b></td>
<td><SELECT NAME=rcountry>
 <option selected>Choose from List
 <OPTION>USA
 /* list of countries follows */


snippet code in validation page:

<?php
...

if ($_POST['rcountry'] == "Choose from List") die ("<h5><br><br>Please choose
your  Country from the drop-down list<br><br><br>Click 'Back' on your
 browser to enter this information</h5>");

...
?>

Any pointers of what I'm missing here would be appreciated.

Tia,
Andre

the <option>-element needs an ending-element. <option>value</option> Some browsers may include a space at the end of the string.

I think this is the most "correct" syntax:
<option value="something">Text to show</option>
where "something" is what is sent as value when posting.

--- End Message ---
--- Begin Message --- I've done these plenty of times, but today i've decided to take a serious look at how I do it, and do it the right way. My current method is just to store the username and an md5 of the password in a couple of cookies.

Is there anything else I should be doing, or an article I should be reading, etc???

Shiflett???  :)

Thanks,

Justin
--- End Message ---
--- Begin Message --- Justin French wrote:
I've done these plenty of times, but today i've decided to take a serious look at how I do it, and do it the right way. My current method is just to store the username and an md5 of the password in a couple of cookies.

Is there anything else I should be doing, or an article I should be reading, etc???

Shiflett??? :)

I don't know if this is a better way, but I don't store the password (encrypted or not) in the cookie. I store the userid and randomly generated encrypted hash (that I also store in the db), along with the timestamp. If a user comes back more than 24 hours after I set the cookie, I regenerate the encrypted hash, and update the cookie and db. I have a custom function I use for this...nothing special, but...


function encryptCookieAccess() {
        global $config;
        $enc = base64_encode ( $config['security']['randomWord'] );
        $enc = crypt ( $enc, $config['security']['cryptSalt'] );
        $enc = md5 ( $enc );
        return $enc;
}

The random word is set in the 'config' array from a list of about 1000 words and phrases, each time a page is loaded.

--
By-Tor.com
...it's all about the Rush
http://www.by-tor.com

--- End Message ---
--- Begin Message ---
Hi Francisco,

Your not alone, a number of other users have enountered this bug.
:(

I have submitted a bug report, here: http://bugs.php.net/bug.php?id=30716
It would be appreciated if you show your support for this bug by commenting/voting etc :)


I also have a `thread` on the php.generals mailing list you may want to read, here: http://news.php.net/php.general/201458

Just quickly here is a dodgy workaround to get you moving
   echo eval('return '. $ClassName .'::$Data;');

:)

Best Regards
Jake Press

--- End Message ---
--- Begin Message --- Francisco M. Marzoa Alonso wrote:
I've code like follows:

<?php

class TestClass {
   public static $Data = 'This is the data';
}

$Obj = new TestClass ();
$ClassName = get_class ($Obj);
echo $ClassName::$Data;

?>

http://www.php.net/manual/en/language.oop5.reflection.php

<?php

class TestClass {
   public static $Data = 'This is the data';
}
$obj = new TestClass;
$a = new ReflectionClass('TestClass');
echo $a->getProperty('Data')->getValue($obj);
?>

in PHP 5.1 this should work

<?php

class TestClass {
   public static $Data = 'This is the data';
}
$a = new ReflectionClass('TestClass');
echo $a->getProperty('Data')->getValue(null);
?>

Greg
--- End Message ---
--- Begin Message ---
Jake Press wrote:

Hi Francisco,

Your not alone, a number of other users have enountered this bug.

string get_class ( object obj )

Its not a bug...
You are getting class name as a string for output purposes etc..
Doing something like "TestClass"::some_static is ofcourse illegal wih strings.

--- End Message ---
--- Begin Message --- Daniel Schierbeck wrote:
public static function getData ()

Ooops, the method shouldn't have been static :)

--
Daniel Schierbeck

Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/register&r=6584
--- End Message ---
--- Begin Message ---
Merlin wrote:

that did not help. The pear manual says that this can be installed via
command line, plus "pear list" tells me that the package is installed.
However if I call phpinfo() there is no mentioning about pear in any way?!
Do I have to enable it first anyhow?`

I assume you have very little PHP experience, so I'll try not to skip any steps.


Forget pear for now.

in PHP, if you have this file:

<?php
include_once 'blah.php';
?>

then php.exe (on windows) or /usr/bin/php (in unix - path may vary) will read a special configuration variable called "include_path" that looks something like this:

.;C:\php4

in windows or

.:/usr/local/lib/php

in unix

PHP will pretend your script is:

<?php
include_once './blah.php';
?>

and if ./blah.php does not exist, it will try

<?php
include_once '/usr/local/lib/php/blah.php';
?>

See? So, if blah.php is actually located in /usr/lib/php/blah.php, php will not find it and cause an error. So, you have to change the include_path

<?php
set_include_path('/usr/lib/php' . PATH_SEPARATOR . get_include_path());
include_once 'blah.php';
?>

PEAR only installs files, it does not change include_path because this is impossible to do automatically. What you need to do is find the location of DB.php, and make sure the absolute path that leads to DB.php is in your include_path (/usr/local/lib/php/DB.php, perhaps, or C:\php4\pear\DB.php)

Having said this, the error you are experiencing sounds like a bug in the code. There are two possibilities

1) there is a file named "DB.php" located in the "." directory, that is being included *before* pear's db would be included
2) there is an ancient version of DB.php that is being included before pear's DB.php


the get_included_files() function can help you lots on this one
http://us2.php.net/manual/en/function.get-included-files.php

Greg
--- End Message ---
--- Begin Message ---
On Nov 25, 2004, at 1:56 AM, Merlin wrote:

Hi,

that did not help. The pear manual says that this can be installed via command line, plus "pear list" tells me that the package is installed. However if I call phpinfo() there is no mentioning about pear in any way?! Do I have to enable it first anyhow?`


How about trying a var_dump() on your DB object? For me, this is always the first step in trying to solve a mystery like this. Chances are, your DB object is really a PEAR_Error object because your failed to connect to your database.


-ryan
--- End Message ---
--- Begin Message ---
echo str_replace("NH", "", "NH13");

                                             Hidayet Dogan
                              [EMAIL PROTECTED]

Pleksus Bilisim Teknolojileri D.T.O. A.S.
----------------------------------------------------------
caldiran sok. 14/6 06420 kolej ankara * www.pleksus.com.tr
tel : +90 312 4355343 * faks: +90 312 4354006

On Thu, 25 Nov 2004, Wiberg wrote:

> hi there!
>
> i guess you know a simple solution to convert the string
>
> NH01 into 1
> NH02 into 2
> ..
> ...
> NH13 into 13
>
> and so on
>
> /Gustav Wiberg
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.799 / Virus Database: 543 - Release Date: 2004-11-19
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

--- End Message ---
--- Begin Message ---
To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm



On 25 November 2004 22:11, Wiberg wrote:

> i guess you know a simple solution to convert the string
> 
> NH01 into 1

I can think of several.



Oh, you want one?  How about:

   $x = "NH01";
   $n = (int)substr($x, 2);

Cheers!

Mike

---------------------------------------------------------------------
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211 

--- End Message ---
--- Begin Message ---
hey gang, 

I have a fedora core 3, with standard PHP and MySQL included with the 
distribution.

I'm having a rather odd problem.

the following script(mailTest.php)

<?PHP
$result = mail('[EMAIL PROTECTED]', 'test subject', 'test message');

if (!$result)
    echo "FAILURE";
else
    echo "SUCCESS";
?>

does NOT work if I access it from the web 

BUT
 
if I were to execute it as root on the Command prompt

php mailTest.php

It executes correctly and I get mail.

This feels like the apache user is lacking access over sendmail or something... 
since as root I can execute the script from the CLI without a problem, but from 
the web, I get a failure.

Can anyone shed a light as to what settings I need to tweak PHP so mail() can 
work? 

Thanks

-Minuk

--- End Message ---
--- Begin Message ---
Hi, 

It could have something to do with your PHP.ini file??
Can you post the error message, as it will give us a better idea of
what could be wrong.

Angelo

>>> "Minuk Choi" <[EMAIL PROTECTED]> 11/26/2004 10:31:59 AM >>>
hey gang, 

I have a fedora core 3, with standard PHP and MySQL included with the
distribution.

I'm having a rather odd problem.

the following script(mailTest.php)

<?PHP
$result = mail('[EMAIL PROTECTED]', 'test subject', 'test message');

if (!$result)
    echo "FAILURE";
else
    echo "SUCCESS";
?>

does NOT work if I access it from the web 

BUT
 
if I were to execute it as root on the Command prompt

php mailTest.php

It executes correctly and I get mail.

This feels like the apache user is lacking access over sendmail or
something... since as root I can execute the script from the CLI without
a problem, but from the web, I get a failure.

Can anyone shed a light as to what settings I need to tweak PHP so
mail() can work? 

Thanks

-Minuk
--------------------------------------------------------------------
Disclaimer 
This e-mail transmission contains confidential information,
which is the property of the sender.
The information in this e-mail or attachments thereto is 
intended for the attention and use only of the addressee. 
Should you have received this e-mail in error, please delete 
and destroy it and any attachments thereto immediately. 
Under no circumstances will the Cape Technikon or the sender 
of this e-mail be liable to any party for any direct, indirect, 
special or other consequential damages for any use of this e-mail.
For the detailed e-mail disclaimer please refer to 
http://www.ctech.ac.za/polic or call +27 (0)21 460 3911

--- End Message ---
--- Begin Message --- Hi all
I have create a script for FTP function.
When i have testing the script with little file and directory it's ok
The script read data in all folder with recursive function and the same path of data
like C:\backup\folder1\file.txt is the same on remolte folder /httpdcos/folder1/file.txt
The problem is that when i testing the script with MB of files
the recursion is much more speed of transfer of a single file and a
file is copied to a path that is not the same of local folder.
How to fix the problem ?
Sorry for my bad language


<?php

#Mode transfer data
$mode = FTP_ASCII;
#The base path of remote directory
$remote_folder = "/httpdocs";
#Include data for the connection to the FTP server
include_once("./config.php");

function ftp_connection() {

  global $user, $pasw, $ftp_server;

  $conn = @ftp_connect($ftp_server);
  $login = @ftp_login($conn, $user, $pasw);

  if((!$conn)||(!$login)) {
     die("Cannot open connect with $ftp_server\n");
  }
  else {
     return $conn;
  }
}

$conn = ftp_connection();
if(!(@ftp_chdir($conn, $remote_folder)))
        die("Cannot to change data folder\n");

function recursive_dir($dir){


#Get ID connect ftp_mode and global $mode, $conn, $remote_folder; #Open resource to read data if (!($handle = @opendir($dir))) die("Cannot open datadir\n"); #Read data from local folder $default_dir while(false !==($item = @readdir($handle))){

        if (is_dir($dir."/".$item)) {
            #Erase al "." and ".." to content of $item
            if ($item != "." && $item != ".."){
               #Make directory on remote Server
               if (!(@ftp_mkdir($conn, $item)))
                        die("Cannot possible mkdir $item\n");
               #Get current directory for current session
               $pwd = @ftp_pwd($conn);
               if(!$pwd) die("Cannot get current Work Directory\n");

if(!(@ftp_chdir($conn, $pwd."/".$item)))
die("Cannot change directory:".$pwd."/".$item."\n");



#Call recursive dir to
recursive_dir($dir."/".$item);
if(!(@ftp_chdir($conn, $remote_folder)))
die("Cannot change directory to $remote_folder");
}
}//End for first check of $item: if is_dir($item)
else {
$fp = @fopen($dir."/".$item, "r");
$pwd = @ftp_pwd($conn);
//echo $pwd."\n";
if(@ftp_fput($conn, $item, $fp, $mode)){
//$count++;
//print $dir."\\".$item."\n";
}//End for if uploaded file
fclose($fp);
}
}//End for else


   closedir($handle);
}//End for recursive function

#Called to recursive function
recursive_dir($default_dir);
#Close the connect to FTP Data
ftp_close($conn);
?>

--- End Message ---
--- Begin Message ---
[EMAIL PROTECTED] wrote:

Hi all
I have create a script for FTP function.
When i have testing the script with little file and directory it's ok
The script read data in all folder with recursive function and the same path of data
like C:\backup\folder1\file.txt is the same on remolte folder /httpdcos/folder1/file.txt
The problem is that when i testing the script with MB of files
the recursion is much more speed of transfer of a single file and a
file is copied to a path that is not the same of local folder.
How to fix the problem ?
Sorry for my bad language

Though i don't generally bother with long code samples i decided to make an excemption:
i believe calling @ftp_chdir($conn, $remote_folder) in your recursive function is wrong instead you should do a CDUP (call the corresponding function for that).


btw: get rid of the @ symbols and configure your php.ini so that all errors are written to the log file, you will then find it a lot easier to debug.


--
Raditha Dissanayake.
------------------------------------------------------------------
http://www.radinks.com/print/card-designer/ | Card Designer Applet
http://www.radinks.com/upload/ | Drag and Drop Upload

--- End Message ---
--- Begin Message --- éàélàél
--- End Message ---
--- Begin Message ---
Hi,
How can I send 3 text files to user generated from PHP script?
Should I must to generate them first and then to send them to user?
Is there a way to send 3 text files to user in just one PHP script ?

Thanks in advance !

--- End Message ---
--- Begin Message ---
hi everyone, i am looking for a snipplet to round down a number. i was 
wondering if you could put a negative number in the round() statement to do 
this, i want it to round down even if its at something.9, as long as its not a 
whole number, if needs to be rounded down. can anyone help me?

--- End Message ---
--- Begin Message --- Brad Ciszewski wrote:
hi everyone, i am looking for a snipplet to round down a number. i was wondering if you could put a negative number in the round() statement to do this, i want it to round down even if its at something.9, as long as its not a whole number, if needs to be rounded down. can anyone help me?

http://us4.php.net/floor

--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
[EMAIL PROTECTED]

--- End Message ---
--- Begin Message ---
On November 26, 2004 08:58, Brad Ciszewski wrote:
> hi everyone, i am looking for a snipplet to round down a number. i was
> wondering if you could put a negative number in the round() statement to do
> this, i want it to round down even if its at something.9, as long as its
> not a whole number, if needs to be rounded down. can anyone help me?

Searching on the php.net site in the manual is/can be your friend.

You want the floor() function.

Take a look at:
http://ca3.php.net/manual/en/function.floor.php

-- 
Regards,
David Bevan

We could learn a lot from crayons: 
some are sharp, some are pretty, some are dull, some have weird names, 
and all are different colors....but they all exist very nicely in the same 
box. 

http://www.getanyideas.com

--- End Message ---
--- Begin Message --- Brad Ciszewski wrote:
hi everyone, i am looking for a snipplet to round down a number. i was wondering if you could put a negative number in the round() statement to do this, i want it to round down even if its at something.9, as long as its not a whole number, if needs to be rounded down. can anyone help me?

floor()

--- End Message ---
--- Begin Message ---
What variable(parameter) in PHP stores file name?

TH

--- End Message ---
--- Begin Message --- Jerry Swanson wrote:
What variable(parameter) in PHP stores file name?

TH

Stores what filename? The name of the file being executed?

$_SERVER['SCRIPT_NAME']

--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
[EMAIL PROTECTED]

--- End Message ---
--- Begin Message ---
On Fri, 2004-11-26 at 09:46, John Nichel wrote:
> Jerry Swanson wrote:
> > What variable(parameter) in PHP stores file name?
> > 
> > TH
> 
> Stores what filename?  The name of the file being executed?
> 
> $_SERVER['SCRIPT_NAME']

Or if you want the name of the file included or whatnot...

__FILE__

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

--- End Message ---

Reply via email to