OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
php-general Digest 27 May 2008 05:41:08 -0000 Issue 5481

php-general-digest-helplists.php.net
Date: Tue May 27 2008 - 00:41:08 CDT


php-general Digest 27 May 2008 05:41:08 -0000 Issue 5481

Topics (messages 274703 through 274717):

Re: How would you rewrite this snippet without using eval?
        274703 by: n3or
        274704 by: n3or
        274705 by: Luigi Perroti

Very simple session question
        274706 by: John Allsopp
        274707 by: Thiago Pojda
        274709 by: tedd
        274714 by: Chetan Rane
        274716 by: John Allsopp
        274717 by: Ted Wood

Re: visibility + unserialization
        274708 by: Chris
        274715 by: Chetan Rane

mail warning!!
        274710 by: Emiliano Boragina
        274711 by: Ted Wood

Downloading movies / forcing download
        274712 by: Ryan S
        274713 by: Ryan S

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscribelists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscribelists.php.net

To post to the list, e-mail:
        php-generallists.php.net

----------------------------------------------------------------------

attached mail follows:


Like this:

<?php

echo Logic::getFirstValue(); // Output: first value

class Logic {
        public static function getFirstValue() {
                return Data::getData('firstArray','firstKey'); // without $
        }
}

class Data {
        private static $firstArray = array ('firstKey'=>'first value');
        private static $secondArray = array ('secondKey'=>'second value');
        public static function getData($array, $key) {
                return self::${$array}[$key];
        }
}

?>

Greetings
n3or

Luigi Perroti schrieb:
> Hi all,
>
> I'm rewriting a script trying to avoid using functions that might pose
> a security threat if used incorrectly.
> I have a portion of code that looks like the one pasted below.
> I don't seem to be able to avoid using eval without introducing too
> many changes, losing in simplicity.
>
> Here's the code:
>
> <?php
>
> echo Logic::getFirstValue(); // Output: first value
>
> class Logic {
> public static function getFirstValue() {
> return Data::getData('$firstArray','firstKey');
> }
> }
>
> class Data {
> private static $firstArray = array ('firstKey'=>'first value');
> private static $secondArray = array ('secondKey'=>'second value');
> public static function getData($array, $key) {
> $string = 'return self::'.$array.'[\''.$key.'\'];';
> return eval ($string);
> }
> }
>
> ?>
>
>
> How would you rewrite the snippet without using eval and still keeping
> things very straightforward?
>
> Thanks for your attention!
>
>

attached mail follows:


Sorry, I forgot, if you have to use the $ in the getData Parameter, use:
$array = substr($array, 1);
before the return statement.

Greetings
n3or

n3or schrieb:
> Like this:
>
> <?php
>
> echo Logic::getFirstValue(); // Output: first value
>
> class Logic {
> public static function getFirstValue() {
> return Data::getData('firstArray','firstKey'); // without $
> }
> }
>
> class Data {
> private static $firstArray = array ('firstKey'=>'first value');
> private static $secondArray = array ('secondKey'=>'second value');
> public static function getData($array, $key) {
> return self::${$array}[$key];
> }
> }
>
> ?>
>
>
> Greetings
> n3or
>
>
> Luigi Perroti schrieb:
>> Hi all,
>>
>> I'm rewriting a script trying to avoid using functions that might pose
>> a security threat if used incorrectly.
>> I have a portion of code that looks like the one pasted below.
>> I don't seem to be able to avoid using eval without introducing too
>> many changes, losing in simplicity.
>>
>> Here's the code:
>>
>> <?php
>>
>> echo Logic::getFirstValue(); // Output: first value
>>
>> class Logic {
>> public static function getFirstValue() {
>> return Data::getData('$firstArray','firstKey');
>> }
>> }
>>
>> class Data {
>> private static $firstArray = array ('firstKey'=>'first value');
>> private static $secondArray = array ('secondKey'=>'second value');
>> public static function getData($array, $key) {
>> $string = 'return self::'.$array.'[\''.$key.'\'];';
>> return eval ($string);
>> }
>> }
>>
>> ?>
>>
>>
>> How would you rewrite the snippet without using eval and still keeping
>> things very straightforward?
>>
>> Thanks for your attention!
>>
>>
>
>

attached mail follows:


On 5/26/08, n3or wrote:
> Sorry, I forgot, if you have to use the $ in the getData Parameter, use:
> $array = substr($array, 1);
> before the return statement.

Thanks a lot!
You've been very helpful.

Regards,
-Luigi

> Greetings
> n3or

attached mail follows:


Hi

I've gone bozzeyed, so I've a simple question for you.

I open session_start() as the first thing, on each page.

I set a session variable using, for instance,
$_SESSION['ACCOUNTemail'] = $email;

The next program, when I var_dump($_SESSION), it shows an empty array.

That program does run session_start() too.

What's obviously wrong, or what's my most likely cause?

Cheers
J

attached mail follows:


Hi John,

What do you mean about "another program"? Is it something like...

a.php:
<?php
session_start();
$_SESSION["index"]= "value";

echo "call b <a href=\"b.php\">here</a>";
?>

b.php:
<?php
session_start();
var_dump($_SESSION);
?>

... or something else?

Try the example above, if this does not work then you should start looking
at your php.ini for session support, check if it's disabled or something.

Or maybe try using session_write_close() at the end of the scripts, they
might work (if session support is enabled).

Atenciosamente,
www.softpartech.com.br
Thiago Henrique Pojda
Desenvolvimento Web
+55 41 3033-7676
thiago.pojdasoftpartech.com.br
Excelência em Softwares Financeiros

-----Mensagem original-----
De: John Allsopp [mailto:johnjohnallsopp.co.uk]
Enviada em: segunda-feira, 26 de maio de 2008 18:17
Para: php-generallists.php.net
Assunto: [PHP] Very simple session question

Hi

I've gone bozzeyed, so I've a simple question for you.

I open session_start() as the first thing, on each page.

I set a session variable using, for instance,
$_SESSION['ACCOUNTemail'] = $email;

The next program, when I var_dump($_SESSION), it shows an empty array.

That program does run session_start() too.

What's obviously wrong, or what's my most likely cause?

Cheers
J

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

attached mail follows:


At 10:16 PM +0100 5/26/08, John Allsopp wrote:
>Hi
>
>I've gone bozzeyed, so I've a simple question for you.
>
>I open session_start() as the first thing, on each page.
>
>I set a session variable using, for instance,
>$_SESSION['ACCOUNTemail'] = $email;
>
>The next program, when I var_dump($_SESSION), it shows an empty array.
>
>That program does run session_start() too.
>
>What's obviously wrong, or what's my most likely cause?
>
>Cheers
>J

J:

That should work. Are you sure you're using

<?php session_start();

I forgot the () one time and it had me going for a while.

Also, try this (it should work):

======= Page 1

<?php session_start(); // page1.php
$num = isset($_SESSION ['num']) ? $_SESSION ['num'] : 0;
$num = 1;
$_SESSION ['num'] = $num;
echo($num);

?>

<form action="page1.php">
<input type="submit" value="Goto the next page">
</form>

======= Page 2

<?php session_start(); // page2.php
$num = isset($_SESSION ['num']) ? $_SESSION ['num'] : 0;
echo($num);

?>

<form action="page1.php">
<input type="submit" value="Goto the last page">
</form>

Cheers,

tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com

attached mail follows:


Hi

Please check if your cookies are disabled on your browser if they are
disabled then the Session wont work.

Chetan Dattaram Rane
Software Engineer
 
 

-----Original Message-----
From: tedd [mailto:tedd.sperlinggmail.com]
Sent: Tuesday, May 27, 2008 7:19 AM
To: php-generallists.php.net
Subject: Re: [PHP] Very simple session question

At 10:16 PM +0100 5/26/08, John Allsopp wrote:
>Hi
>
>I've gone bozzeyed, so I've a simple question for you.
>
>I open session_start() as the first thing, on each page.
>
>I set a session variable using, for instance,
>$_SESSION['ACCOUNTemail'] = $email;
>
>The next program, when I var_dump($_SESSION), it shows an empty array.
>
>That program does run session_start() too.
>
>What's obviously wrong, or what's my most likely cause?
>
>Cheers
>J

J:

That should work. Are you sure you're using

<?php session_start();

I forgot the () one time and it had me going for a while.

Also, try this (it should work):

======= Page 1

<?php session_start(); // page1.php
$num = isset($_SESSION ['num']) ? $_SESSION ['num'] : 0;
$num = 1;
$_SESSION ['num'] = $num;
echo($num);

?>

<form action="page1.php">
<input type="submit" value="Goto the next page">
</form>

======= Page 2

<?php session_start(); // page2.php
$num = isset($_SESSION ['num']) ? $_SESSION ['num'] : 0;
echo($num);

?>

<form action="page1.php">
<input type="submit" value="Goto the last page">
</form>

Cheers,

tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com

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

attached mail follows:


Thanks all, yes, it's like that, and a & b work.

The difference? I was doing

$_SESSION['index']= $myString;

instead of

$_SESSION["index"]= $myString;

Now with "s it works.

Why?

And, worryingly, I set three variables, then dump $_SESSION and it
contains three variables. I think it should still contain

$_SESSION["index"]= "value";

from the a/b test.

I'm fairly certain I'm not using any session functions to clear the
session .. best guess for the cause of the loss of that variable?

Cheers
J

Thiago Pojda wrote:
> Hi John,
>
> What do you mean about "another program"? Is it something like...
>
> a.php:
> <?php
> session_start();
> $_SESSION["index"]= "value";
>
> echo "call b <a href=\"b.php\">here</a>";
> ?>
>
> b.php:
> <?php
> session_start();
> var_dump($_SESSION);
> ?>
>
> ... or something else?
>
> Try the example above, if this does not work then you should start looking
> at your php.ini for session support, check if it's disabled or something.
>
> Or maybe try using session_write_close() at the end of the scripts, they
> might work (if session support is enabled).
>
>
>
> Atenciosamente,
> www.softpartech.com.br
> Thiago Henrique Pojda
> Desenvolvimento Web
> +55 41 3033-7676
> thiago.pojdasoftpartech.com.br
> Excelência em Softwares Financeiros
>
>
> -----Mensagem original-----
> De: John Allsopp [mailto:johnjohnallsopp.co.uk]
> Enviada em: segunda-feira, 26 de maio de 2008 18:17
> Para: php-generallists.php.net
> Assunto: [PHP] Very simple session question
>
> Hi
>
> I've gone bozzeyed, so I've a simple question for you.
>
> I open session_start() as the first thing, on each page.
>
> I set a session variable using, for instance,
> $_SESSION['ACCOUNTemail'] = $email;
>
> The next program, when I var_dump($_SESSION), it shows an empty array.
>
> That program does run session_start() too.
>
> What's obviously wrong, or what's my most likely cause?
>
> Cheers
> J
>
>

attached mail follows:


Using double-quotes instead of single-quotes in the code you provided
should be *no* difference at all. I'm curious if there's something
else going on for you. Can you provide more complete code?

Back to your original example, calling session_start() will restart a
session, so only call that function once during a request, or make
sure to write out the session using session_write() before calling it
again.

~Ted

On 26-May-08, at 10:32 PM, John Allsopp wrote:

> Thanks all, yes, it's like that, and a & b work.
>
> The difference? I was doing
>
> $_SESSION['index']= $myString;
>
> instead of
>
> $_SESSION["index"]= $myString;
>
> Now with "s it works.
>
> Why?
>
> And, worryingly, I set three variables, then dump $_SESSION and it
> contains three variables. I think it should still contain
>
> $_SESSION["index"]= "value";
>
> from the a/b test.
>
> I'm fairly certain I'm not using any session functions to clear the
> session .. best guess for the cause of the loss of that variable?
>
> Cheers
> J
>
> Thiago Pojda wrote:
>> Hi John,
>>
>> What do you mean about "another program"? Is it something like...
>>
>> a.php:
>> <?php
>> session_start();
>> $_SESSION["index"]= "value";
>>
>> echo "call b <a href=\"b.php\">here</a>";
>> ?>
>>
>> b.php:
>> <?php
>> session_start();
>> var_dump($_SESSION);
>> ?>
>>
>> ... or something else?
>>
>> Try the example above, if this does not work then you should start
>> looking
>> at your php.ini for session support, check if it's disabled or
>> something.
>>
>> Or maybe try using session_write_close() at the end of the scripts,
>> they
>> might work (if session support is enabled).
>>
>>
>>
>> Atenciosamente,
>> www.softpartech.com.br
>> Thiago Henrique Pojda
>> Desenvolvimento Web
>> +55 41 3033-7676
>> thiago.pojdasoftpartech.com.br
>> Excelência em Softwares Financeiros
>>
>>
>> -----Mensagem original-----
>> De: John Allsopp [mailto:johnjohnallsopp.co.uk] Enviada em:
>> segunda-feira, 26 de maio de 2008 18:17
>> Para: php-generallists.php.net
>> Assunto: [PHP] Very simple session question
>>
>> Hi
>>
>> I've gone bozzeyed, so I've a simple question for you.
>>
>> I open session_start() as the first thing, on each page.
>>
>> I set a session variable using, for instance,
>> $_SESSION['ACCOUNTemail'] = $email;
>>
>> The next program, when I var_dump($_SESSION), it shows an empty
>> array.
>>
>> That program does run session_start() too.
>>
>> What's obviously wrong, or what's my most likely cause?
>>
>> Cheers
>> J
>>
>>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

attached mail follows:


Ted Wood wrote:
>
> I have a 4 year old framework that serializes objects and stores them in
> the database. It is now going PHP 5-only, so I began to add visibility
> to the class definitions of the serialized objects. However, then things
> didn't work properly after objects stored [before the visibility was
> added] were unserialized. For example, each protected field ended up
> creating two fields, with one followed by ":protected".

I don't see two fields, I only see one:

$ php -a
Interactive mode enabled

<?php

class abc {
 protected $x = '21345';
 function __construct() {}
}

$x = new abc();
echo serialize($x);
O:3:"abc":1:{s:4:"*x";s:5:"21345";}

$y = serialize($x);
print_r(unserialize($y));
abc Object
(
    [x:protected] => 21345
)

As for why they come out like that, no idea - I couldn't find any
comments on php.net about it either.

--
Postgresql & php tutorials
http://www.designmagick.com/

attached mail follows:


Can you please example code because I simulated the similar thing and it works fine here

<?php
class A {
        protected $x = '12345';
        protected $y = '12345';
        function __construct() {
                
        }
        
        public function Hello(){
                echo Hello2;
        }
        
}
echo "<pre>";
$a = new A();
echo serialize($a);
print_r($a);
print_r(unserialize(serialize($a)));

?>

O/P :
O:1:"A":2:{s:4:"�*�x";s:5:"12345";s:4:"�*�y";s:5:"12345";}A Object
(
    [x:protected] => 12345
    [y:protected] => 12345
)
A Object
(
    [x:protected] => 12345
    [y:protected] => 12345
)

I think that’s perfectly fine.
Chetan Dattaram Rane
Software Engineer
 
 

-----Original Message-----
From: Ted Wood [mailto:ted-talkscodeoflife.ca]
Sent: Monday, May 26, 2008 8:56 PM
To: php-generallists.php.net
Subject: [PHP] visibility + unserialization

I have a 4 year old framework that serializes objects and stores them
in the database. It is now going PHP 5-only, so I began to add
visibility to the class definitions of the serialized objects.
However, then things didn't work properly after objects stored [before
the visibility was added] were unserialized. For example, each
protected field ended up creating two fields, with one followed by
":protected".

Expected Result:
----------------------

object(Foo) {
  ["bar"]=>
  string(0) "banana"
}

Actual Result:
----------------------

object(Foo) {
  ["bar:protected"]=>
  string(0) ""
  ["bar"]=>
   string(6) "banana"
}

Anybody run into this, or can explain why this might be and how I can
avoid it?

Thanks,

~Ted

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

attached mail follows:


I dont understand.. in my server I can run the form perfectly… but in the
client server not… appears this message:

 

Warning: mail() [ <http://www.consultapsico.com.ar/demo/function.mail>
function.mail]: "sendmail_from" not set in php.ini or custom "From:" header
missing in D:\Service\Sites\Consultapsico\www\demo\form.php on line 10

Whats that?

Thanks…

 

+ _
   // Emiliano Boragina _

   // Diseño & Comunicación //////////////////
+ _

   // emiliano.boraginagmail.com /
   // 15 40 58 60 02 ///////////////////////////
+ _

 

attached mail follows:


The mail() function doesn't have a specific parameter to set the
sending address of your outgoing email... aka. the "From" address. You
can set this using the $additional_headers parameter, however.

Read this page for a solution:
http://php.net/mail

~Ted

On 26-May-08, at 8:34 PM, Emiliano Boragina wrote:

> I dont understand.. in my server I can run the form perfectly
but
> in the
> client server not
appears this message:
>
>
>
> Warning: mail() [ <http://www.consultapsico.com.ar/demo/function.mail>
> function.mail]: "sendmail_from" not set in php.ini or custom "From:"
> header
> missing in D:\Service\Sites\Consultapsico\www\demo\form.php on line 10
>
>
>
> Whats that?
>
> Thanks

>
>
>
> +
> _
> // Emiliano Boragina _
>
> // Diseño & Comunicación //////////////////
> +
> _
>
> // emiliano.boraginagmail.com /
> // 15 40 58 60 02 ///////////////////////////
> +
> _
>
>
>

attached mail follows:


Hey!

Heres my requirment, the movie clips are below the root and after the member pays for access the client want to let the user download the flick and add the sitename to the flicks filename (for example if the filename is a.avi it should download as test-a.avi)

heres the code i haev come up with so far... the download box pops up in FF but in IE it gives me the website cannot be found error

======================= code =========================
<?php

$directory_path ="C:\\xampp2\\htdocs\\";
$file_name="Fitna[English].avi";

$file_to_download=$directory_path.$file_name;
$user_agent = strtolower ($_SERVER["HTTP_USER_AGENT"]);
header( "Content-type: application/force-download" );
if ((is_integer (strpos($user_agent, "msie"))) && (is_integer (strpos($user_agent, "win"))))
{header( "Content-Disposition: filename="."test-".$file_name);
}else{header( "Content-Disposition: attachment; filename="."test-".$file_name);
    }
header( "Content-Description: File Transfert");
readfile($file_to_download);

?>done!
========================================================

Any suggestions as to how i can improve the code and also how to get the above to work?

Thanks in advance!
R

 ------
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)

      

attached mail follows:


Hi again,
forgot to mention, in FF when i try to save the file... it does not save it... although it shows the filename in the download folder.. the file is just 4k for some reason where as the original file is something like 40mb

Thanks,
Ryan

================================================

Hey!

Heres my requirment, the movie clips are below the root and after the member pays for access the client want to let the user download the flick and add the sitename to the flicks filename (for example if the filename is a.avi it should download as test-a.avi)

heres the code i haev come up with so far... the download box pops up in FF but in IE it gives me the website cannot be found error

======================= code =========================
<?php

$directory_path ="C:\\xampp2\\htdocs\\";
$file_name="Fitna[English].avi";

$file_to_download=$directory_path.$file_name;
$user_agent = strtolower ($_SERVER["HTTP_USER_AGENT"]);
header( "Content-type: application/force-download" );
if ((is_integer (strpos($user_agent, "msie"))) && (is_integer (strpos($user_agent, "win"))))
{header( "Content-Disposition: filename="."test-".$file_name);
}else{header( "Content-Disposition: attachment; filename="."test-".$file_name);
    }
header( "Content-Description: File Transfert");
readfile($file_to_download);

?>done!
========================================================

Any suggestions as to how i can improve the code and also how to get the above to work?

Thanks in advance!
R

------
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)