[PHP] Classes, global objects, and pointers

2003-02-11 Thread John Hughes
In this example which parallels a problem I am having in my real life
script. I would like to have a global object, in this case $tester. I would
then like to be able to store local references to this global object right
inside the class. These are assigned byref in the classes constructor.

This script should, by my understanding work, only it craps out in test2's
constructor: "$o = &$tester;".

Any help would be greatly appreciated. (Please cc me on your replies)

John Hughes

a = 10;
  }
  function doit() {
$this->a = 20;
  }
}

global $tester;
$tester = new test();

class test2 {
  var $o;
  function test2() {
$o = &$tester;
  }
  function mod() {
$o->doit();
  }
}

echo $tester->a . "\n"; // Should be 10

$newtest = new test2();
$newtest->mod();

echo $tester->a . "\n"; // Should be 20

?>


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




[PHP] alternatives to mail()

2002-04-24 Thread John Hughes

The commercial server where my pages are hosted is having trouble
with the lastest version of PHP and as a result the mail() function
is not working.  E-mailing from PHP is critical for my postcard and
other functions on my site. (I might as well shut four of my sites
without e-mail.)

Is there a fall-back option from PHP to send mail when the mail()
function is not working?

John Hughes

__
Do You Yahoo!?
Yahoo! Games - play chess, backgammon, pool and more
http://games.yahoo.com/

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




Re: [PHP] BBS system

2002-04-26 Thread John Hughes

Visit www.sourceforge.net

--- r <[EMAIL PROTECTED]> wrote:
> Hey all,
> 
> Just a small q,
> does anybody know of any particular good BBS system that is free? 
> (I aint
> rich :-(   ) Been to hotscripts.com can you recomend any?
> 
> (Actually if i were rich I would not care a damn for
> PHP-MySql-Apache-Java-ASP-JSP hell, i wouldnt even touch a
> computer,
> would be happy being computer illiterate, would have been partying
> with a
> lot of babes instead...hehhehe maybe thats why i aint
> rich...have too
> wicked a mind? )
> 
> Ohh well
> Cheers,
> -Ryan.
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


__
Do You Yahoo!?
Yahoo! Games - play chess, backgammon, pool and more
http://games.yahoo.com/

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




[PHP] tutorial on global variables

2002-04-27 Thread John Hughes

Can someone point me toward a tutorial on the proper use of global
references under PHP4. 

I have been declaring 

function something()
{
global $foo, $bar; 

/* some actions */

}

in functions and I understand that this is not the way I'm supposed
to be doing this. Or there is a new way that is preferred.

John Hughes

__
Do You Yahoo!?
Yahoo! Health - your guide to health and wellness
http://health.yahoo.com

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




[PHP] mail() errors and alternatives

2002-04-30 Thread John Hughes

For the second time in less than a week, the commercial Web service
provider where I have four domains hosted has managed to break PHP.
In particular, I get this message:

Warning: mail() is not supported in this PHP build 

I'm not interested in what causes the PHP mail() function to become
unavailable. My problem is that the mail() function -- or, more to
the point, the ability to send e-mail -- is "mission critical." No
mail; no work. No work; unhappy boss. You get the idea.

I'm looking for ideas on how I can defend against mail() failures.
One idea I had would be to test 

if(mail($to, $subj, $body, $headers)
{
  /* report ok send */
} ELSE {
  /* do alternative send */
} 

Any ideas of how that alternative send could work?  

I do have an alternative service provider where I have access to PHP
that works. Any ideas on the best way to redirect the $to, $subj,
$body, $headers to a PHP script at the other domain and return some
notification that the send did not report errors?

TIA,

John Hughes
http://jomari.com




__
Do You Yahoo!?
Yahoo! Health - your guide to health and wellness
http://health.yahoo.com

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




Re: [PHP] Re: tutorial on global variables

2002-05-02 Thread John Hughes

Thank you for this explanation. 

I have several scripts that take it for granted PHP will assign
variables to the information in the URL as in your example $a from
example.com/foo.php?a=apple

Will these scripts fail when my commercial Web host upgrades from PHP
4.1.x to 4.2?

If so, can I 'upgrade' my scripts now (again, PHP 4.1.x) to use $food
= $_GET['a'] or $food = $_POST['a'] and prevent everything from
crashing when PHP 4.2 is installed?

(I don't expect to get any warning when the upgrade occurs. This is
the same provider that has twice in one week disabled mail() in the
PHP build.)

John Hughes



--- Philip Olson <[EMAIL PROTECTED]> wrote:
> An issue/confusion of register_globals, global, and
> variable scope exists out there; here are some thoughts:
> 
>  a) As of PHP 4.2.0, register_globals defaults to off.
> 
> This is a major change to consider.
> register_globals is a PHP directive that lives in
> php.ini, the configuration file that controls PHP.
> 
> http://www.php.net/release_4_2_0.php
> http://uk.php.net/manual/en/security.registerglobals.php
> 
> Different server setups have different settings,
> so not relying on register_globals = on will make
> your scripts more portable.
> 
>  b) register_globals looks/sounds like global when
> really they are very different topics.
> 
>
> http://us.php.net/manual/en/configuration.php#ini.register-globals
> http://www.php.net/manual/en/language.variables.scope.php
> 
> register_globals will create $a from
> example.com/foo.php?a=apple
> while when register_globals = off, $a will NOT exist.
> One can always use $HTTP_GET_VARS or $_GET for this like so:
> 
>   print $_GET['a'];
> 
> Use of import_request_variables() or extract() to act in a
> similar fashion as register_globals is possible too.
> 
> http://fr2.php.net/import_request_variables
> http://ca.php.net/extract
> 
>  c) As of PHP 4.1.0, super/auto global arrays became available.
> 
> The new predefined PHP variables such as $_POST, $_GET,
> $_SERVER are identical to their existing counterparts of
> $HTTP_POST_VARS, $HTTP_GET_VARS, etc. except that:
> 
> 1) The new autoglobal arrays are automagically global
>while their sibling arrays ($HTTP_*_VARS) are not.
>  http://www.php.net/manual/en/reserved.variables.php
> 2) Shorter is better :)
> 3) They are different variables, $_GET is not a reference
>to $HTTP_GET_VARS but rather they are two seperate
>copies, same information.
>  http://fr2.php.net/release_4_1_0.php
> 
> The manual discusses all the superglobals, others are 
> $_REQUEST, $_FILES and $_SESSION.
> 
> Being that this is all relativly new, PHP is in sort
> of a mild transitional state.  The above announcements
> explain why.  People just starting out with PHP have
> slightly more homework to do than before.  But, these
> same people have less chance for security mistakes now.
> 
> And it's worth noting, register_globals does affect
> predefined SERVER variables too.  So when off the
> variables $DOCUMENT_ROOT, $PHP_SELF, etc. will NOT
> exist.  Go through $_SERVER or $HTTP_SERVER_VARS instead.
> This is something to consider when writing "portable"
> scripts (or hacking non-portable scripts to work).  A 
> possible usage is:
> 
>   // if register_globals is off, create server vars
>   if (!ini_get('register_globals')) {
> extract($HTTP_SERVER_VARS);
> print 'we just created $REMOTE_ADDR because register_globals is
> off';
> print "\nREMOTE_ADDR: $REMOTE_ADDR";
>   } else {
> print 'register_globals is on so $DOCUMENT_ROOT et al already
> exists';
> print "\nDOCUMENT_ROOT: $DOCUMENT_ROOT";
>   }
> 
> Phew, hope that helps :)
> 
> Regards,
> Philip Olson
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


__
Do You Yahoo!?
Yahoo! Health - your guide to health and wellness
http://health.yahoo.com

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




Re: [PHP] Re: tutorial on global variables

2002-05-02 Thread John Hughes

After reviewing
http://www.php.net/manual/en/function.import-request-variables.php I
was wondering if simply including this line at the top of all scripts

import_request_variables("gP", "");

would eliminate the potential problem I would have if
register_globals gets turned off unexpectedly?

Other than the security reasons, is there any disadvantage to adding
this line?

John Hughes

--- Philip Olson <[EMAIL PROTECTED]> wrote:
> > I have several scripts that take it for granted PHP will assign
> > variables to the information in the URL as in your example $a
> from
> > example.com/foo.php?a=apple
> 
> Okay, so they depend on the behavior that register_globals 
> provides.
> 
> > Will these scripts fail when my commercial Web host upgrades 
> > from PHP 4.1.x to 4.2?
> 
> It's not a matter of PHP versions, it's a matter of a 
> simple PHP directive.  PHP 4.2.0 defaults to 
> register_globals = off, this does not mean a host 
> has to go by this default.  Ask them if it will be 
> changing, odds are it will not without a warning.
> 
> > If so, can I 'upgrade' my scripts now (again, PHP 4.1.x) to use 
> > $food = $_GET['a'] or $food = $_POST['a'] and prevent everything 
> > from crashing when PHP 4.2 is installed?
> 
> Yes you can.  I eluded to import_request_variables() and 
> extract(), two functions that will allow you to do such 
> things.  Please look them up in the manual (links below).
> Also consider $_REQUEST, see the manual for details.
> 
> Also note that if you really want register_globals = on 
> and the host has it off, you _may_ (depending on the hosts 
> configurations) be able to use .htaccess (or equivalent) 
> with something like:
> 
>   php_flag register_globals on
>   
> Yes there are a lot of options, variety is the spice of life.
> 
> Regards,
> Philip Olson
> 
> 


__
Do You Yahoo!?
Yahoo! Health - your guide to health and wellness
http://health.yahoo.com

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




[PHP] escaping quotes in forms and redisplaying variables in form fields

2002-05-06 Thread John Hughes

I'm stumbling over how to allow people to put single or double quotes
in a form text field. 

I am passing the form to itself ($PHP_SELF) and on the second time
through previewing what the form data will look like and also
re-creating the form with the data already filled in.

Here's an example of one text field:

$display_line .="";

(I have stripslashes() the $signature variable to create
$noslash_signature.)

If someone signs their name O'Brien, the preview shows O'Brien, but
all that shows in the form field is O. However, Joe "Bruiser" Jones
displays correctly in preview and the form.

If I change the code like this (adding the \" around the variable): 

$display_line .="";

O'Brien will display OK, but Joe "Bruiser" Jones shows just Joe in
the form field.

One solution is to change the text form to textarea, but I'd prefer
to be able to redisplay at text form field if possible.

TIA,
John Hughes

__
Do You Yahoo!?
Yahoo! Health - your guide to health and wellness
http://health.yahoo.com

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




[PHP] adjusting time() to correct for time zones

2002-05-24 Thread John Hughes

My server is located on the East Coast, but all of the users of my
site live on the West Coast. I have an application that makes several
calls to time() and as a result all of the times displayed are East
Coast.

Rather than changing every time() to time()-10800, I was wondering if
there is a way to make one global change, perhaps with .htacess. 
Since this site is hosted on a commercial service I do not have
access to the PHP.ini or other server-level files.

TIA

John Hughes

__
Do You Yahoo!?
LAUNCH - Your Yahoo! Music Experience
http://launch.yahoo.com

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




Re: [PHP] adjusting time() to correct for time zones

2002-05-24 Thread John Hughes


--- Miguel Cruz <[EMAIL PROTECTED]> wrote:
> On Fri, 24 May 2002, John Hughes wrote:
> > My server is located on the East Coast, but all of the users of
> my
> > site live on the West Coast. I have an application that makes
> several
> > calls to time() and as a result all of the times displayed are
> East
> > Coast.
> > 
> > Rather than changing every time() to time()-10800, I was
> wondering if
> > there is a way to make one global change, perhaps with .htacess. 
> > Since this site is hosted on a commercial service I do not have
> > access to the PHP.ini or other server-level files.
> 
> How about writing a wrapper function called l_time() that does the 
> calculation for you? Stick it in an include file, do a little 
> searchin'-and-replacin', and you're set. One day when you get
> ambitious 
> you can enhance the l_time() function to look for a cookie that
> identifies 
> the current user's time zone and calculates accordingly.
> 
> miguel


Creating my own l_time() function would work, but it would require
that every installed app on the this site be customized.  Since the
site makes extensive use of OpenSource projects, every time an app is
upgraded it would need to be re-hacked.

If there is no other choice, there is no other choice. But in a
perfect world, there would be a way to locally correct the server
time on a global basis and thus correct ALL applications -- present
and future -- that need to know the "local" time.

John Hughes

__
Do You Yahoo!?
LAUNCH - Your Yahoo! Music Experience
http://launch.yahoo.com

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




[PHP] Counting months between two dates

2002-04-02 Thread John Hughes

I want to determine the number of months between two dates. Is there a
function in PHP or a way to make strtotime do the job?

For instance, how many months between 2001-08-27 and 2002-06-05.



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