[PHP] [SOLVED] Re: session_id() is not passed to the next page

2011-01-04 Thread Michelle Konzack
Hello Daniel Molina Wegener,

Am 2011-01-04 07:43:46, hacktest Du folgendes herunter:
>   Did you tried working with error_reporting(E_ALL) and looking if you have
> the well known warning "headers already sent"?. Try to work with 
> error_reporting(E_ALL), instead of hiding errors. If you get that warning
> or error means that the cookie for session id was not written, so you can't
> handle the session id on the next page...

Yes, and it is clean

>   Try using session_start() as the very first call or session.auto_start = 1
> in your php.ini (which is not recommended).

I have already found the error.

If my 00_main.inc is read in, I check first some required vars, then for
the existence of  three  config  files  and  then  I  output  errors  if
something is wrong and if all is fine I contine and do session_start().

I have  overseen  that  there  is  an  include  which  was  read  before
session_start() and created the problem...

This is one reason, WHY I rewrite my scripst from the last 10 years.

They where transformed in unreadable spagetti code.

However, now I can use my login script with PAM,  Shadow  Passwords  and
One-Time Passwords which use a 8 letter TAN list.

One-Time Passwords are very handy, if you have to  access  your  website
from unknown computers like in internet cafes or such.

Thanks, Greetings and nice Day/Evening
Michelle Konzack

-- 
# Debian GNU/Linux Consultant ##
   Development of Intranet and Embedded Systems with Debian GNU/Linux

itsyst...@tdnet France EURL   itsyst...@tdnet UG (limited liability)
Owner Michelle KonzackOwner Michelle Konzack

Apt. 917 (homeoffice)
50, rue de Soultz Kinzigstraße 17
67100 Strasbourg/France   77694 Kehl/Germany
Tel: +33-6-61925193 mobil Tel: +49-177-9351947 mobil
Tel: +33-9-52705884 fix

  
 

Jabber linux4miche...@jabber.ccc.de
ICQ#328449886

Linux-User #280138 with the Linux Counter, http://counter.li.org/


signature.pgp
Description: Digital signature


[PHP] Two forms on one page - THE ANSWER

2011-01-04 Thread Ethan Rosenberg

Jim -

Much thanks to you for solving a problem with which I have been 
struggling for the last two weeks.


Here is the code:
===

http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>



Enter your date of birth, in mm/dd/ format: 



FORM;

 break;

 case 'step2':
if ( empty($_POST['dob']) )
die('DOB was not set in session...');
if ( !preg_match('!^\d{2}/\d{2}/\d{4}$!', $_POST['dob'], $m) )
die('DOB was not properly formated, please try again.');
 // calculate timestamp corresponding to date value
$dateTs = strtotime($_POST['dob']);
 // calculate timestamp corresponding to 'today'
$now = strtotime('today'); $dateArr = explode('/', @$_POST['dob']);
 // check that the value entered is a valid date
if ( !checkdate($dateArr[0], $dateArr[1], $dateArr[2]) )
die('ERROR: Please enter a valid date of birth');
  // check that the date entered is earlier than 'today'
if ( $dateTs >= $now )
die('ERROR: Please enter a date of birth earlier 
than today');

  // calculate difference between date of birth and today in days
  // convert to years
  // convert remaining days to months
  // print output
$ageDays = floor(($now - $dateTs) / 86400);
$ageYears = floor($ageDays / 365);
$ageMonths = floor(($ageDays - ($ageYears * 365)) / 30);
echo "You are approximately $ageYears years and $ageMonths 
months old.";


  break;
case 'step1':
default:

echo <<

Enter your kitten's name: 



FORM;

}
?>
=
Ethan

MySQL 5.1  PHP 5.3.3-6  Linux [Debian (sid)] 




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



[PHP] mysqli fetch-fields returns blob for text

2011-01-04 Thread Mari Masuda
Hello,

On http://www.php.net/manual/en/mysqli.constants.php there are some predefined 
constants for MYSQLI_TYPE_TINY_BLOB, MYSQLI_TYPE_MEDIUM_BLOB, 
MYSQLI_TYPE_LONG_BLOB, and MYSQLI_TYPE_BLOB.  Through some experimentation I 
have found that fields in my MySQL database that are declared as 'text' in 
MySQL are categorized by PHP as 'blob' when I compare the above constants to 
the field's type using 
http://www.php.net/manual/en/mysqli-result.fetch-fields.php.

In the MySQL documentation http://dev.mysql.com/doc/refman/5.1/en/blob.html in 
the second paragraph it states: 
---
BLOB values are treated as binary strings (byte strings). They have no 
character set, and sorting and comparison are based on the numeric values of 
the bytes in column values. TEXT values are treated as nonbinary strings 
(character strings). They have a character set, and values are sorted and 
compared based on the collation of the character set.
---

I was wondering if PHP's interpretation of 'text' as 'blob' could cause me any 
trouble down the road and what the workarounds are, if any.  Thank you.

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



[PHP] Unload/reload included class

2011-01-04 Thread Patrik Pomichal

Hi there,

I trying to create CLI php application. It running continuously (server)
and it will has a plugins. I want load, unload and reload plugins on
the fly, without stop the application.

Loading plugin is easy, when my app found new file in plugins dir,
include and register it. But if i change the plugin source i must 
restart the app to reload it.


Have anyone idea, how i can unload included (loaded) class?

Thank you for every response. Best regards.

Patrik Pomichal
PHP developer
Slovakia

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



Re: [PHP] Two forms on one page

2011-01-04 Thread Jim Lucas
On 1/4/2011 12:53 PM, Paul M Foster wrote:
> On Tue, Jan 04, 2011 at 10:08:47AM -0800, Jim Lucas wrote:
> 
> [snip]
>  
>> If this isn't it, I think you should explain (in sudo code) exactly the steps
>> you are expecting things to.
>>
>> Example sudo code
>>
> 
> [snip]
> 
> Normally I wouldn't comment on this (sorry, Jim), but for the foreigners
> on the list, "sudo" is a command under Unix/Linux which allows one to
> function as the root user. I suspect what Jim meant to write was
> "pseudo" (pronounced the same way as "sudo" in English), which means
> "fake" or "pretend". 
> 
> English is one of those languages which is afflicted by lots of
> homonyms-- words which sound the same but are spelled differently and
> mean different things, even though they sound the same.
> 
> Paul
> 

Paul,

Thanks for pointing that out.  I sometimes write too fast...

Jim

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



Re: [PHP] Two forms on one page

2011-01-04 Thread Paul M Foster
On Tue, Jan 04, 2011 at 10:08:47AM -0800, Jim Lucas wrote:

[snip]
 
> If this isn't it, I think you should explain (in sudo code) exactly the steps
> you are expecting things to.
> 
> Example sudo code
> 

[snip]

Normally I wouldn't comment on this (sorry, Jim), but for the foreigners
on the list, "sudo" is a command under Unix/Linux which allows one to
function as the root user. I suspect what Jim meant to write was
"pseudo" (pronounced the same way as "sudo" in English), which means
"fake" or "pretend". 

English is one of those languages which is afflicted by lots of
homonyms-- words which sound the same but are spelled differently and
mean different things, even though they sound the same.

Paul

-- 
Paul M. Foster
http://noferblatz.com


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



[PHP] Re: session_id() is not passed to the next page

2011-01-04 Thread Al



On 1/3/2011 11:46 PM, Michelle Konzack wrote:

Hello,

I am rewriting currently a login script and I encountered a problem with
sessions.  While reading the two pages

 
 

I have not found a solution for my problem:

8<--
function fncLogin($user, $pass, $redirect, $type='pam') {

   if ($user != '' and $pass != '') {

 $TEXT  = "Error\n";
 $TEXT .= "\n";
 $TEXT .= "The username does not exist or the password is wrong.\n";
 $TEXT .= "\n";
 $TEXT .= "Please goback  and 
try it again.\n";

 if ($type == 'pam') {

   if (pam_auth($user, $pass,&$PAM_ERR) === FALSE) {
 fncError('2', $TEXT, $errpage='false');
 exit();
   }

 } elseif ($type == 'shadow') {

   $shadow_file = DIR_HOST . "/.shadow";
   if (is_file($shadow_file)) {

 $SHADOW = exec("grep \"^" . $user . ":\" " . DIR_HOST . "/.shadow |cut -d: 
-f2");
 if (empty($SHADOW)) {
 }

 $SALT=exec("grep \"^$user:\" " . DIR_HOST . "/.shadow |cut -d: -f2 |cut -d$ 
-f1-3");
 $ENCRYPTED=crypt($pass, $SALT);
 if ($SHADOW != $ENCRYPTED) {
   fncError('2', $TEXT, $errpage='false');
   exit();
 }

   } else {
 $TEXT  = "Error\n";
 $TEXT .= "\n";
 $TEXT .= "This is a system error. I can not authenticate du to a missing 
config.\n";
 $TEXT .= "\n";
 $TEXT .= "Please inform thesysadmin  and 
try it later again.\n";
 fncError('1', $TEXT, $errpage='false');
 exit();
   }
 }

 session_register('sess_user');
 session_register('sess_timeout');
 $sess_user= $user;
 $sess_timeout = time() + 900;
 session_write_close();
 header("Location: " . $redirect);
   }
   exit();
}
8<--

which call the following page correctly, but the two vars $sess_user and
$sess_timeout are empty.

Can someone please tell me how to do this?

Thanks, Greetings and nice Day/Evening
 Michelle Konzack



Firefox has a great add-on that lets you see the server/client handshaking 
headers httpFox e.g., Cookie:   PHPSESSID=fc310ca5f2c708988bf456f691cc58c2


Thus you can easily see if PHPSESSID is set and returned to the server.

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



Re: [PHP] Two forms on one page

2011-01-04 Thread Jim Lucas
Sorry for top posting!

FYI: You might want to check the math in your calculations.  It says that I am
41 when my birthday is tomorrow and I will be 36...

On 1/4/2011 10:08 AM, Jim Lucas wrote:
> On 1/4/2011 7:53 AM, Ethan Rosenberg wrote:
>> At 03:45 AM 1/4/2011, you wrote:
>>> Ethan,
>>>
>>> Ok, I would do this with what I would call wizard steps...
>>>
>>> On 1/3/2011 3:17 PM, Ethan Rosenberg wrote:
 Oooops - left out the text that was supposed to be in the quotes.

 Dear List -

 I would like to have two(2) forms in one PHP script. I would like to
 have the forms appear sequentially; ie, that the first form would
 appear, the data would be entered, and then the second form would
 appear, the data would be entered, and the script would exit.

 The code below displays both forms simultaneously. After the data is
 entered for the first form, the second form appears again. After the
 data is entered for the second form, the script displays the statement
 "Enter your date of birth, in mm/dd/ format: " from the first form.

 Would you please help me correct the script so that it will perform as
 required.

 Thanks.

 Here is the code:
 
>>>
> 
> To go back to what I originally wrote.  I found 1 error in the second form.
> Here is the corrected form.
> 
> 
>  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
> 
>  
> switch ( @$_POST['next_step'] )
> {
> case 'step3':
> 
> if ( empty($_SESSION['dob']) )
> die('DOB was not set in session...');
> 
> $dateArr = explode('/', @$_SESSION['dob']);
> 
> // calculate timestamp corresponding to date value
> $dateTs = strtotime($_POST['dob']);
> 
> // calculate timestamp corresponding to 'today'
> $now = strtotime('today');
> 
> // check that the value entered is in the correct format
> if ( sizeof($dateArr) != 3 )
> die('ERROR: Please enter a valid date of birth');
> 
> // check that the value entered is a valid date
> if ( !checkdate($dateArr[0], $dateArr[1], $dateArr[2]) )
> die('ERROR: Please enter a valid date of birth');
> 
> // check that the date entered is earlier than 'today'
> if ( $dateTs >= $now )
> die('ERROR: Please enter a date of birth earlier than today');
> // calculate difference between date of birth and today in days
> // convert to years
> // convert remaining days to months
> // print output
> $ageDays = floor(($now - $dateTs) / 86400);
> $ageYears = floor($ageDays / 365);
> $ageMonths = floor(($ageDays - ($ageYears * 365)) / 30);
> echo "You are approximately $ageYears years and $ageMonths months old.";
> 
> break;
> case 'step2':
> $_SESSION['dob'] = @$_POST['dob'];
> echo << 
> 
> Enter your kitten's name: 
> 
> 
> 
> FORM;
> 
> break;
> case 'step1':
> default:
> 
> echo << 
> 
> Enter your date of birth, in mm/dd/ format: 
> 
> 
> 
> FORM;
> }
> ?>
> 
> 
> If this isn't it, I think you should explain (in sudo code) exactly the steps
> you are expecting things to.
> 
> Example sudo code
> 
> 1.  display form 'A'
> 2.  Person enters dob and presses submit
> 3.  processing script stores dob submitted
> 4.  display form 'B'
> 5.  person enters name of kitten and presses submit
> 6.  processing script retrieves dob previously stored
> 7.  calculate age
> 8.  display age
> ...
> 10. What happen to the kitten???
> 
> Form 'A':
> 
> 
> Enter your date of birth, in mm/dd/ format: 
> 
> 
> 
> 
> Form 'B':
> 
> 
> Enter your kitten's name: 
> 
> 
> 
> 
> 
> Anyways, that is the idea.
> 
> Let us know.
> 
> Jim
> 
>> Please correct my errors.
>>
>> Thanks again.
>>
>> Ethan
>> +++
>>
>>> 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] Two forms on one page

2011-01-04 Thread Jim Lucas
On 1/4/2011 7:53 AM, Ethan Rosenberg wrote:
> At 03:45 AM 1/4/2011, you wrote:
>> Ethan,
>>
>> Ok, I would do this with what I would call wizard steps...
>>
>> On 1/3/2011 3:17 PM, Ethan Rosenberg wrote:
>>> Oooops - left out the text that was supposed to be in the quotes.
>>>
>>> Dear List -
>>>
>>> I would like to have two(2) forms in one PHP script. I would like to
>>> have the forms appear sequentially; ie, that the first form would
>>> appear, the data would be entered, and then the second form would
>>> appear, the data would be entered, and the script would exit.
>>>
>>> The code below displays both forms simultaneously. After the data is
>>> entered for the first form, the second form appears again. After the
>>> data is entered for the second form, the script displays the statement
>>> "Enter your date of birth, in mm/dd/ format: " from the first form.
>>>
>>> Would you please help me correct the script so that it will perform as
>>> required.
>>>
>>> Thanks.
>>>
>>> Here is the code:
>>> 
>>

To go back to what I originally wrote.  I found 1 error in the second form.
Here is the corrected form.


http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>

= $now )
die('ERROR: Please enter a date of birth earlier than today');
// calculate difference between date of birth and today in days
// convert to years
// convert remaining days to months
// print output
$ageDays = floor(($now - $dateTs) / 86400);
$ageYears = floor($ageDays / 365);
$ageMonths = floor(($ageDays - ($ageYears * 365)) / 30);
echo "You are approximately $ageYears years and $ageMonths months old.";

break;
case 'step2':
$_SESSION['dob'] = @$_POST['dob'];
echo <<

Enter your kitten's name: 



FORM;

break;
case 'step1':
default:

echo <<

Enter your date of birth, in mm/dd/ format: 



FORM;
}
?>


If this isn't it, I think you should explain (in sudo code) exactly the steps
you are expecting things to.

Example sudo code

1.  display form 'A'
2.  Person enters dob and presses submit
3.  processing script stores dob submitted
4.  display form 'B'
5.  person enters name of kitten and presses submit
6.  processing script retrieves dob previously stored
7.  calculate age
8.  display age
...
10. What happen to the kitten???

Form 'A':


Enter your date of birth, in mm/dd/ format: 




Form 'B':


Enter your kitten's name: 





Anyways, that is the idea.

Let us know.

Jim

> Please correct my errors.
> 
> Thanks again.
> 
> Ethan
> +++
> 
>> 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] Re: Do you trim() usernames and passwords?

2011-01-04 Thread tedd

At 12:04 PM + 12/31/10, Nathan Rixham wrote:

Tamara Temple wrote:
Sorry, I was mislead by your use of the phrase "Users should not be 
copy-pasting passwords or usernames" above. I'd love to hear what 
you think is an alternative to identifying with web app that keeps 
track of information about someone that is more secure.


client side ssl certificates, they force http+tls (thus encryption 
over the wire and no chance of middleman attacks) and no usernames 
or passwords need to be passed, as you identify people by the public 
key held in their certificate, the TLS process ensures they have the 
private key.


Nat:

I was wondering when you would chime-in.

The certificate example you provided me a few months ago was 
exceptional. I now believe that server-side data can be kept 
reasonably secure regardless of successful attacks on the server.


Cheers,

tedd

--
---
http://sperling.com/

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



Re: [PHP] ErrorDocument 500 and PHP

2011-01-04 Thread David Lidstone

On 03/01/2011 20:26, Ashley Sheridan wrote:

On Mon, 2011-01-03 at 15:11 -0500, Bastien Koert wrote:


On Mon, Jan 3, 2011 at 2:30 PM, David Lidstone  wrote:

On 03/01/2011 18:38, Nilesh Govindarajan wrote:


On 01/03/2011 11:46 PM, David Lidstone wrote:


Hi

First up, I apologise as this must have been posted before, but the
server is so slow I can't search, or even read messages often. I'm
using Thunderbird - any tips on how to access news.php.net faster!?

In Apache, I can set "ErrorDocument 404 /myerrorpage.php" and it
works. Doing the same but with a 500 error for a PHP script, it
doesn't. I just get the PHP error printed on the screen. What I've
seen on the net implies to me that PHP does not fully interact with
Apache when it generates an error, and therefore this approach will
not work. Is this correct?

I just want to redirect to a PHP page on 500 error and run a small
script. Any suggestions?

Many thanks,
David



Basically, it is not a 500 error.
It's an error produced by the php itself.
The file which was run by php had some error, so php outputs that error
to the client. This is actually a successful request when you see from
the apache's eye.



That's what I feared, although my server seems to send 500 headers but my
local xampp install sends 200 headers. Strange.

So what do people do about getting notified about errors? - I have too many
sites to look after to manually sift through logs. I can't refactor every
script with try / catch (which wouldn't catch compile bugs anyway)? How does
Apache know to log the error with "ErrorLog" but not redirect with
"ErrorDocument"? Is there a way I can piggy-back this behaviour instead?
Sorry for so many questions, but the more I look at this the crazier it
seems and most of the stuff on the net is just static!

Perl interacts "fully" with Apache from what I can gather. Anyone know
whether this is planned for the future? When I had to use IIS and ASP it had
this functionality and it was very handy.

Thanks again,
David

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





Check the php.ini file to ensure that error reporting is turned on.
This will allow php to show you where/what the error is.

For a dev box this is acceptable but should be turned off in production
--

Bastien

Cat, the other other white meat




If the same sorts of errors are happening over and over, then you should
look into it, as it could be affecting your users on the website. Try
and unit test whatever parts you can, so that you can see what happens
when a user interacts with your app.

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





Thanks for your reply Ashley

Unfortunately, this isn't really what I was getting at. I'm really just 
looking for something which will notify us every time there is an error 
on any of the very many disparate scripts / 'apps' running on a given 
server. There is no one app although many are built on a framework which 
has a boot-strap file similar to ZF so a set_error_handler solution, 
while far from ideal, may cover some bases if there is one? There are 
possible solutions I can think of such as parsing all the log files 
perhaps, but none of these are as elegant as what is available to 
Apache/Perl and IIS/ASP which is suprising to me as PHP usually covers 
all the bases. I'm hoping I'm just ignorant of  that simple solution?


I'm also interested in the functionality and interaction of PHP with 
Apache - I know little of this, but as noted in my original post, there 
appears on the surface to be some discrepancy about this interaction in 
terms of logging vs error documents. Perhaps I should be posting some of 
this in .internals or one of the other groups?


Many thanks,
David

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



Re: [PHP] Re: Flexible application plugin architecture, is this possible?

2011-01-04 Thread Mike
Hi Colin,

I guess I'm on the right track then, I ended up doing something
similar to your suggestion, instead of using a Factory method in each
class I created a global function that can be used as the instantiator
instead. 

The only advantage I see to doing it this way is that it will work for
classes that don't extend my base "Factory" class, so it requires the
least amount of existing code change as possible. 

//The basis for the plugin system, instantiate all classes through this, 
allowing the class to be overloaded on the fly by a class in the plugin 
directory.
function MyInstantiator( $class_name ) { //Unlimited arguments are supported.
global $config_vars;

//Check if the plugin system is enabled in the config.
if ( isset($config_vars['other']['enable_plugins']) AND 
$config_vars['other']['enable_plugins'] == 1 ) {
$plugin_class_name = $class_name.'Plugin';

if ( class_exists( $plugin_class_name, FALSE ) == FALSE ) {
//Class file needs to be loaded.
$plugin_directory = 'plugins';
$plugin_class_file_name = $plugin_directory . 
DIRECTORY_SEPARATOR . $class_name .'.plugin.php';
if ( file_exists( $plugin_class_file_name ) ) {
@include_once( $plugin_class_file_name );
$class_name = $plugin_class_name;
}
} else {
//Class file is already loaded.
$class_name = $plugin_class_name;
}
}

if ( func_num_args() > 1 ) {
$params = func_get_args();
array_shift( $params ); //Eliminate the class name argument.

$reflection_class = new ReflectionClass($class_name);
return $reflection_class->newInstanceArgs($params);
} else {
return new $class_name();
}
}

$main_class = MyInstantiator('MyClass', 'arg1', 'arg2', 'arg3');
$main_class->doSomething( 'foo' );



On Tue, 04 Jan 2011 11:43:13 +
Colin Guthrie  wrote:

> 'Twas brillig, and Mike at 03/01/11 23:37 did gyre and gimble:
> > I'm trying to design a powerful plugin system that doesn't require any
> > (or extremely little) modification to my existing large code base. Hook
> > based systems unfortunately don't seem to meet this requirement. 
> > 
> > Is something like this possible in PHP?
> > 
> > //Magic function I made up, similar to __call(), 
> > //only it replaces "new $class" with its own return value.
> > function __instantiate( $class, $args ) {
> > $plugin_class = $class.'Plugin';
> > 
> > if ( file_exists( 'plugins/'.$plugin_class.'.php' ) {
> > $obj = new $plugin_class($args);
> > return $obj;
> > } else {
> > return new $class($args);
> > }
> > }
> 
> I'd implement the above as a static "factory" method of your primary
> class: e.g.
> 
> > class MainClass {
> 
> public static function factory($args = null) {
> $plugin_class = __CLASS__ . 'Plugin';
> // Assume autoloading
> if (class_exists($plugin_class))
>   return new $plugin_class($args);
> return new self($args);
> }
> 
> protected function __construct($args) {
> }
> 
> > function doSomething( $args ) {
> > echo "MainClass doSomething() called...\n";
> > }
> > }
> > 
> > class MainClassPlugin extends MainClass {
> > function doSomething( $args ) {
> > echo "MainClassPlugin doSomething() called...\n";
> > 
> > //Modify arguments if necessary
> > echo "MainClassPlugin modifying arguments...\n";
> > 
> > $retval = parent::doSomething( $args );
> > 
> > //Modify function output, or anything else required
> > echo "MainClassPlugin post filter...\n";
> > 
> > return $retval;
> > }
> > }
> > 
> > $main_class = new MainClass();
> 
> And replace this line with:
> $main_class = MainClass::factory();
> 
> 
> > $main_class->doSomething( 'foo' );
> 
> Which, when run, does indeed produce your desired results.
> 
> > Results:
> > MainClassPlugin doSomething() called...
> > MainClassPlugin modifying arguments...
> > MainClass doSomething() called...
> > MainClassPlugin post filter...
> > 
> > I realize PHP doesn't have this magical "__instantiate" function, but
> > does it have any similar mechanism that would work to automatically
> > load alternate classes, or have a class dynamically overload
> > itself during runtime?
> 
> Well difference techniques require different approaches, but certainly a
> factory approach is likely the correct design solution here to get the
> desired results.
> 
> 
> Full code for convenience:
> 
>  
> class MainClass {
> public static function factory($args = null) {
> $plugin_class = __CLASS__ . 'Plugin';
> // Assume autoloading
> if (class_exists($plugin_class))
>   return new $plu

Re: [PHP] Newbie Question

2011-01-04 Thread Steve Staples
On Sun, 2011-01-02 at 21:10 -0500, David McGlone wrote:
> On Sunday, January 02, 2011 08:43:51 pm Larry Garfield wrote:
> > On Sunday, January 02, 2011 4:56:28 pm Adolfo Olivera wrote:
> > > Thanks for the replies. I'll just put a php on all my html containing
> > > php. A little of topic. Wich IDE are you guys using. I'm sort of in a
> > > catch twenty two here. I been alternating vim and dreamweaver. I'm
> > > trying to go 100% open source, but I really find dreamweaver easier to
> > > use so far.
> > 
> > I bounce between NetBeans and Eclipse, depending on which currently sucks
> > less.  I have yet to find a PHP IDE that doesn't suck; it's just degrees of
> > suckage. :-)
> 
> I use Kate. It doesn't suck at all because it doesn't try to do the coding 
> for 
> you :-)
> 
> -- 
> Blessings
> David M.
> 

Personally, for the longest time I used EditPlus++ on windows... used it
for about 4-5 years.  I knew it, I liked it... then i got a job where
they used ZEND (basically Eclipse yes?)  I started to like it once i got
the hang of it... but that job only lasted 3 weeks.  ANYWAY... I now use
Komodo (the free version) on my ubuntu workstation, and I love it... I
dont know how I managed before.

>From my observations and experience, it's all about personal
preferences.  If the one you use works for you, and you like it, then
use it.  I caught flack for some time when I told people I used EditPlus
++ for all my coding, but they just didn't know how to use the features.

Good luck with your coding!  and finding an IDE that works for you! (or
just a standard text editor like VI if you desire)

Steve


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



[PHP] Re: Flexible application plugin architecture, is this possible?

2011-01-04 Thread Colin Guthrie
'Twas brillig, and Mike at 03/01/11 23:37 did gyre and gimble:
> I'm trying to design a powerful plugin system that doesn't require any
> (or extremely little) modification to my existing large code base. Hook
> based systems unfortunately don't seem to meet this requirement. 
> 
> Is something like this possible in PHP?
> 
> //Magic function I made up, similar to __call(), 
> //only it replaces "new $class" with its own return value.
> function __instantiate( $class, $args ) {
> $plugin_class = $class.'Plugin';
> 
> if ( file_exists( 'plugins/'.$plugin_class.'.php' ) {
> $obj = new $plugin_class($args);
> return $obj;
> } else {
> return new $class($args);
> }
> }

I'd implement the above as a static "factory" method of your primary
class: e.g.

> class MainClass {

public static function factory($args = null) {
$plugin_class = __CLASS__ . 'Plugin';
// Assume autoloading
if (class_exists($plugin_class))
  return new $plugin_class($args);
return new self($args);
}

protected function __construct($args) {
}

> function doSomething( $args ) {
> echo "MainClass doSomething() called...\n";
> }
> }
> 
> class MainClassPlugin extends MainClass {
> function doSomething( $args ) {
> echo "MainClassPlugin doSomething() called...\n";
> 
> //Modify arguments if necessary
> echo "MainClassPlugin modifying arguments...\n";
> 
> $retval = parent::doSomething( $args );
> 
> //Modify function output, or anything else required
> echo "MainClassPlugin post filter...\n";
> 
> return $retval;
> }
> }
> 
> $main_class = new MainClass();

And replace this line with:
$main_class = MainClass::factory();


> $main_class->doSomething( 'foo' );

Which, when run, does indeed produce your desired results.

> Results:
> MainClassPlugin doSomething() called...
> MainClassPlugin modifying arguments...
> MainClass doSomething() called...
> MainClassPlugin post filter...
> 
> I realize PHP doesn't have this magical "__instantiate" function, but
> does it have any similar mechanism that would work to automatically
> load alternate classes, or have a class dynamically overload
> itself during runtime?

Well difference techniques require different approaches, but certainly a
factory approach is likely the correct design solution here to get the
desired results.


Full code for convenience:

doSomething( 'foo' );


-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mageia Contributor [http://www.mageia.org/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



Re: [PHP] Flexible application plugin architecture, is this possible?

2011-01-04 Thread Daniel Molina Wegener
On Monday 03 January 2011,
Mike  wrote:

> I'm trying to design a powerful plugin system that doesn't require any
> (or extremely little) modification to my existing large code base. Hook
> based systems unfortunately don't seem to meet this requirement.

  OK, that is a design problem...

> 
> Is something like this possible in PHP?
> 
> //Magic function I made up, similar to __call(),
> //only it replaces "new $class" with its own return value.
> function __instantiate( $class, $args ) {
> $plugin_class = $class.'Plugin';
> 
> if ( file_exists( 'plugins/'.$plugin_class.'.php' ) {
> $obj = new $plugin_class($args);
> return $obj;
> } else {
> return new $class($args);
> }
> }
> 
> class MainClass {
> function doSomething( $args ) {
> echo "MainClass doSomething() called...\n";
> }
> }
> 
> class MainClassPlugin extends MainClass {
> function doSomething( $args ) {
> echo "MainClassPlugin doSomething() called...\n";
> 
> //Modify arguments if necessary
> echo "MainClassPlugin modifying arguments...\n";
> 
> $retval = parent::doSomething( $args );
> 
> //Modify function output, or anything else required
> echo "MainClassPlugin post filter...\n";
> 
> return $retval;
> }
> }
> 
> $main_class = new MainClass();
> $main_class->doSomething( 'foo' );
> 
> Results:
> MainClassPlugin doSomething() called...
> MainClassPlugin modifying arguments...
> MainClass doSomething() called...
> MainClassPlugin post filter...
> 
> I realize PHP doesn't have this magical "__instantiate" function, but
> does it have any similar mechanism that would work to automatically
> load alternate classes, or have a class dynamically overload
> itself during runtime?

  Well, you can do this using abstract classes and interfaces. Also
you must try the autoloader:

  http://php.net/manual/en/language.oop5.autoload.php

  Probably this will help you a lot.

Best regards,
-- 
Daniel Molina Wegener 
System Programmer & Web Developer
Phone: +56 (2) 979-0277 | Blog: http://coder.cl/


signature.asc
Description: This is a digitally signed message part.


Re: [PHP] session_id() is not passed to the next page

2011-01-04 Thread Daniel Molina Wegener
On Tuesday 04 January 2011,
Michelle Konzack  wrote:

> Hello,

  Hello...

> 
> I am rewriting currently a login script and I encountered a problem with
> sessions.  While reading the two pages
> 
> 
> 

  Well, probably this is not a problem of PHP. You must try looking at
your page errors. The PHP session mechanism tries to write some headers
with the session ID (a cookie).

> 
> I have not found a solution for my problem:
> 
> 8<--
> function fncLogin($user, $pass, $redirect, $type='pam') {
> 
>   if ($user != '' and $pass != '') {
> 
> $TEXT  = "Error />\n"; $TEXT .= "\n";
> $TEXT .= "The username does not exist or the password is wrong. />\n"; $TEXT .= "\n";
> $TEXT .= "Please go  "\">back and try it again.\n";
> 
> if ($type == 'pam') {
> 
>   if (pam_auth($user, $pass, &$PAM_ERR) === FALSE) {
> fncError('2', $TEXT, $errpage='false');
> exit();
>   }
> 
> } elseif ($type == 'shadow') {
> 
>   $shadow_file = DIR_HOST . "/.shadow";
>   if (is_file($shadow_file)) {
> 
> $SHADOW = exec("grep \"^" . $user . ":\" " . DIR_HOST . "/.shadow
> |cut -d: -f2"); if (empty($SHADOW)) {
> }
> 
> $SALT=exec("grep \"^$user:\" " . DIR_HOST . "/.shadow |cut -d:
> -f2 |cut -d$ -f1-3"); $ENCRYPTED=crypt($pass, $SALT);
> if ($SHADOW != $ENCRYPTED) {
>   fncError('2', $TEXT, $errpage='false');
>   exit();
> }
> 
>   } else {
> $TEXT  = "Error />\n"; $TEXT .= "\n";
> $TEXT .= "This is a system error. I can not authenticate du to a
> missing config.\n"; $TEXT .= "\n";
> $TEXT .= "Please inform the  "\">sysadmin and try it later again.\n"; fncError('1', $TEXT,
> $errpage='false');
> exit();
>   }
> }
> 
> session_register('sess_user');
> session_register('sess_timeout');
> $sess_user= $user;
> $sess_timeout = time() + 900;
> session_write_close();
> header("Location: " . $redirect);
>   }
>   exit();
> }
> 8<--
> 
> which call the following page correctly, but the two vars $sess_user and
> $sess_timeout are empty.
> 
> Can someone please tell me how to do this?

  Did you tried working with error_reporting(E_ALL) and looking if you have
the well known warning "headers already sent"?. Try to work with 
error_reporting(E_ALL), instead of hiding errors. If you get that warning
or error means that the cookie for session id was not written, so you can't
handle the session id on the next page...

  Try using session_start() as the very first call or session.auto_start = 1
in your php.ini (which is not recommended).

> 
> Thanks, Greetings and nice Day/Evening
> Michelle Konzack


Best regards,
-- 
Daniel Molina Wegener 
System Programmer & Web Developer
Phone: +56 (2) 979-0277 | Blog: http://coder.cl/


signature.asc
Description: This is a digitally signed message part.


Re: [PHP] Two forms on one page

2011-01-04 Thread Jim Lucas

Ethan,

Ok, I would do this with what I would call wizard steps...

On 1/3/2011 3:17 PM, Ethan Rosenberg wrote:

Oooops - left out the text that was supposed to be in the quotes.

Dear List -

I would like to have two(2) forms in one PHP script. I would like to
have the forms appear sequentially; ie, that the first form would
appear, the data would be entered, and then the second form would
appear, the data would be entered, and the script would exit.

The code below displays both forms simultaneously. After the data is
entered for the first form, the second form appears again. After the
data is entered for the second form, the script displays the statement
"Enter your date of birth, in mm/dd/ format: " from the first form.

Would you please help me correct the script so that it will perform as
required.

Thanks.

Here is the code:




http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>

= $now )
die('ERROR: Please enter a date of birth earlier than today');
// calculate difference between date of birth and today in days
// convert to years
// convert remaining days to months
// print output
$ageDays = floor(($now - $dateTs) / 86400);
$ageYears = floor($ageDays / 365);
$ageMonths = floor(($ageDays - ($ageYears * 365)) / 30);
echo "You are approximately $ageYears years and $ageMonths months old.";

break;
case 'step2':

$_SESSION['dob'] = @$_POST['dob'];

echo <<

Enter your kitten's name: 



FORM;

break;
case 'step1':
default:

echo <<

Enter your date of birth, in mm/dd/ format: 




FORM;

}

?>




This is completely untested, typed directly in the email client.  Most 
of the code is cut/paste from your examples.  But, it should give you a 
good starting point for a multi-step form type.


Jim

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