php-general Digest 28 Apr 2002 13:56:24 -0000 Issue 1313

Topics (messages 94955 through 94983):

Re: tutorial on global variables
        94955 by: Jason Wong

Re: Apache: SERVER_NAME gone?
        94956 by: Jason Wong

class PHP
        94957 by: Peter
        94961 by: John Holmes
        94962 by: SP

does ImageCreateFromJPEG suck up memory?
        94958 by: DrTebi

Question
        94959 by: Gerard Samuel

PGP
        94960 by: Richard Lynch

array question--help
        94963 by: Mark Pelillo
        94970 by: Johan Holst Nielsen

Re: session expires on server side
        94964 by: Padraig Kitterick

Stripping characters.....
        94965 by: CDitty
        94966 by: CC Zona
        94967 by: CC Zona
        94969 by: Justin French

Wrapping Text
        94968 by: Scott Reismanis

Auto refresh when data changed in Mysql
        94971 by: Simonk
        94972 by: The_RadiX

The definitive source for PHP news, tutorials and articles (also, as XML)
        94973 by: Stefen Lars

passing variables to scripts
        94974 by: Mark Gallagher
        94975 by: Yuri Petro

date problem
        94976 by: Nick Wilson
        94978 by: Richard Emery
        94980 by: Yuri Petro
        94981 by: Nick Wilson

failed query results
        94977 by: baldey_uk
        94979 by: Richard Emery

HTML in PHP
        94982 by: Christian Ista
        94983 by: Andrew Brampton

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 ---
On Sunday 28 April 2002 04:39, Henrik Hansen wrote:
> [EMAIL PROTECTED] (John Hughes) wrote:
>  > Can someone point me toward a tutorial on the proper use of global
>  > references under PHP4.

The manual has very good information.

>  >
>  > 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.

That is a perfectly valid declaration, but without knowing your intent one 
cannot say whether it is 'right' or 'wrong'.

The thing you need to remember with PHP is that unlike many other languages, 
by default variables are not global in nature. Thus in order to use a 
variable that is defined outside of a function you need to declare it like 
you have above.

> you can do it that way, but if you want to avoid calling global all
> the time you might consider this approach:
>
> $GLOBALS["foo"] = 123;

  $foo = 123; # No need to use the $GLOBALS array when outside of a function

> function something()
> {
>     echo $GLOBALS["foo"];
> }

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

/*
"...if the church put in half the time on covetousness that it does on lust,
 this would be a better world."  - Garrison Keillor, "Lake Wobegon Days"
*/
--- End Message ---
--- Begin Message ---
On Tuesday 23 January 2001 07:55, The_RadiX wrote:
> Hmm
>
> > because $SERVER_NAME is created IF the php
> > directive register_globals = on.  this setting
> > is off by default as of PHP 4.2.0.  all
> > server predefined variables behave this way,
> > such as $PHP_SELF, etc.
>
> Yes so I've heard... One thing though.. I use PHP4.1.1... not 4.2.x

Read the changelog (or history). A lot of default behaviour has changed 
starting from 4.1.X.

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

/*
Happiness isn't something you experience; it's something you remember.
                -- Oscar Levant
*/
--- End Message ---
--- Begin Message ---
The text of this proposal, test code, and updates live at
petermoulding.com/class. I place it here for discussion of the best
approach before people build code.

Class PHP

An invention for a classier PHP.

This invention uses PHP classes as Web pages. The invention can be
implemented as a wrapper around PHP or as an enhancement to PHP. In
Apache 2, the invention can be implemented as a filter to precede PHP. I
will give a quick outline of the requirement, then sketches of
implementations, then detailed examples prototyped using PHP.

The invention is named class. An Apache implementation could be a module
named class. If you write code to implement this invention, suffix the
project name with your name as in class_John.

To prevent a rapacious company copyrighting this invention using the
excuse that it is a business process or anything else they can
copyright, I declare my copyright on everything in this invention and
any processes derivable from this. Please make your code implementations
GPL, www.gnu.org/copyleft/gpl.html, and mention my page at
petermoulding.com/class.

Invention Requirement
The main requirement is to replace PHP's page input with invented input. 

Here is a file named any_class.class that containing a PHP class named
any_class:
<?php
class any_class
    {
    function any_class()
        {
        /* code to build a Web page. */
        }
    }
?>

Here is a Web page containing a PHP script to build the entire page
using the PHP class any_class:
<?php
include_once("any_class.class");
$any_class = new any_class();
?>

The invention makes PHP initiate any_class.class as if any_class were
included and instantiated by the example Web page.

PHP Wrapper

The invention could be implemented as a module for Apache or another Web
server by writing a wrapper for PHP. The wrapper would accept a call
from Apache then pass the call on to PHP so PHP could perform 100%
unaltered as if PHP were called direct from Apache.

The module would look for class requests with a page of the form *.class
then intercept the URL and prepare to pass invented input to PHP. The
Apache configuration parameters can ensure all requests for class go to
class and only requests for class to class. In a mixed class/PHP
environment, the requested class can go to class and the PHP requests
can go direct to PHP. There could also be a check in class for a class
file so that all requests are directed to class and class processes just
those with a matching class file.

When class finds a valid class request, class builds a PHP Web page that
includes the class file and initiates the class. To make PHP read the
invented Web page, you could trap PHP's Web page read and substitute the
invented page. As PHP has to access files within the constraints of a
Web server, the access technique could vary from release to release and
across Web servers. I will describe two quick implementation
possibilities.

If PHP reads files via Apache's file read functions (or an equivalent on
other web servers), class gets to view all file requests from PHP to
Apache and monitor all replies. Class can then pass the invented page
back to PHP without the request reaching Apache. PHP remains untouched
by class.

Where a Web server does not provide file access functions or PHP chooses
to not use those functions, class would need a modification to PHP to
intercept file reads. The interception depends on the exact compilation
of PHP and would be in the form of a wrapper around a file access
routine in PHP. The wrapper (or interception layer) needs to be at a
level where the code can see file names and subvert the whole file read
process. Interception at this level requires PHP release dependent
coding and is a step toward the PHP enhancement described next.
PHP Enhancement
A PHP enhancement would be an implementation of the invention direct
within PHP's code so that PHP can react to class requests in conjunction
with an external process or without an external process. The ultimate
enhancement would be to incorporate the whole invention within PHP so
there are no additional installation steps required.

A PHP enhancement could use a wrapper as described in PHP Wrapper or the
Apache 2 filter described next but use those devices just to trigger
class processing then perform the whole processing within PHP. This
approach has the advantage that the processing is independent of the
trigger method and the trigger method is free from processing code.

The PHP enhancement could discover the need for class processing by
whatever method suits the web server environment. The enhancement would
then verify the action is valid within constrains specified in php.ini,
verify a class file is available, and invoke the class file as if from
an invented Web page of the same name as the class file.
Apache 2 Filter

To implement this idea as an Apache 2 filter, you need a link to PHP
that lets PHP know your code will provide the Web page input. Your code
then invents a Web page of the same name as the class file and passes
the invented page to PHP. The Apache Notes field looks like a good
vehicle for passing the invented page. 

PHP has to discover the Web page will arrive in the Notes field or via
another mechanism of your invention. That means a modification to PHP
and something in php.ini to prevent accidental use of the modification
in sites not using your code. The least PHP dependent method would be to
invent the page in your code and enhance PHP with a single trigger to
make PHP read the input Web page from your mechanism. The approach
minimises changes to PHP but makes the process Web server dependent. The
PHP enhancement described in a previous page is more PHP dependent but
less Web server dependent.

Allow for other filters using the Apache Notes field. Wrap your invented
page in a simple XML tag that PHP can recognise within the Notes field.

Detailed Example

Here is a file named any_class.class that containing a PHP class named
any_class:
<?php
class any_class
    {
    function any_class()
        {
        /* code to build a Web page. */
        }
    }
?>

This class contains a constructor that builds the whole Web page using
any combination of code, functions and classes valid within PHP classes.
I copied all the Web site construction code from one Web site in to a
class/function wrapper and initiated Web page construction without
error. In other tests there were some global variables that needed
mention in a global statement within the outside function. If the global
communication within an application is a variable named $site, the above
example becomes:
<?php
class any_class
    {
    function any_class()
        {
        global $site;
        /* code to build a Web page. */
        }
    }
?>

As the authors switch to 100% class based coding, global variables
disappear in favour of a structure of variables with the class
structure.

Now for a more detailed look. The following code is a PHP implementation
of a PHP wrapper built by pointing the Web server at pages of type .html
which then contain a script to call the appropriate class from a
parallel file of type .class. In this version there is no code within
the Web server so there has to be two files. Once the example is
translated to C and added to a Web server as a module, the example code
becomes the content of a virtual Web page that is passed to PHP but not
stored on disk.

The first part of the code simply extracts the page name from PHP_SELF
and saves the name in $class_new_page. There are many ways to derive the
page name from server variables. Your technique will vary depending on
the Web server, the release of PHP and the options in php.ini. The
example happens to work on all the variations of PHP and Web servers I
currently use. The example also lets me remove the file type for known
file names while leaving in name parts that happen to contain dots.

The second part of the code prepares variables for use in the
constructor class. I used a class that does not know about URL or form
variables so I copy them in to an array for the class. This code is not
needed if your class knows it will be initiated as the start of a page.
You only need this type of code if you want to use the class as both the
start of a page and as a class within other code.

You could pass URL variables to the class in the order read from the URL
but you do not control the URL order. You could leave all the variables
out and let the class find the variables but the class would have to
know where to look, in the parameters of the constructor function or in
external variables. I use this part of the code to translate external
variables to a form the class understands and will later convert the
class to read direct. A better approach would be to enhance PHP to read
named parameters.

The third part of the code initiates the class. Initiation includes both
class file inclusion and class instantiation. I use include_once() to
prevent multiple inclusions. Your Web server module should use
include_once() for version of PHP that have include_once().

The variables are prefixed $class_new to reduce clashes with existing
code. That means I can mix this code with legacy PHP code on sits during
conversion. In your Web site module the variables are external to PHP so
do not clash with anything within the class or subsequent code.

<?php
// Extract page name:
$class_new_parts_page = explode(".", array_pop(explode("/",
    str_replace("\\", "/", $HTTP_SERVER_VARS["PHP_SELF"]))));
if(in_array($class_new_parts_page[count($class_new_parts_page) - 1],
    array("html", "php")))
    {
    array_pop($class_new_parts_page);
    }
$class_new_page = implode(".", $class_new_parts_page);

// Prepare variables:
$class_new_variables = $HTTP_GET_VARS;
foreach($HTTP_POST_VARS as $class_new_key => $class_new_value)
    {
    $class_new_variables[$class_new_key] = $class_new_value;
    }

// Initiate the class:
include_once("./" . $class_new_page . ".class");
$$class_new_page = new $class_new_page($class_new_variables);
?>

The function initiation can be implemented in a function so all
subsequent classes are initiated in a similar fashion. I use the
following simple function because it works with existing classes on a
development site. Once the existing site and classes are redeveloped,
the "./" prefix and ".class" suffix will be replaced by named constants.
At that point the function will serve little purpose so will be dropped.
in some other sites the function may be expanded to extract dynamic
classes from content databases. A logical extension of this invention is
to add code extraction from an XML database, something I describe in
another document.

// A function to initiate a class:
function class_new($class_new_class, $class_new_variables,
    $class_new_prefix = "./", $class_new_suffix = ".class")
    {
    global $$class_new_class;
    include_once($class_new_prefix . $class_new_class .
$class_new_suffix);
    $$class_new_class = new $class_new_class($class_new_variables);
    }
?>

Implications

By now you realise the class will have the same name as the page so will
not suit sites based on many pages with different names. It is also of
no interest to people to write HTML pages then insert small portions of
PPH code. This invention is for sites using pages generated by PHP code
so suits sites using dynamic content management. It suits sites that
have a small number of pages presenting varied data.

Your site might have one page for registration, another for logging in
then a single page/script that provides a shopping system while another
single page/script provides a search facility. Make the search a class
and use this invention to initiate the class.

Once you develop dynamic content management, your sites end up as a list
of scripts delivering what looks like a series of intelligent pages. The
HTML pages execute PHP scripts and add nothing. This invention removes
HTML layer between your class based scripts and the Web server.
--- End Message ---
--- Begin Message ---
Can someone translate this to English?

> -----Original Message-----
> From: Peter [mailto:[EMAIL PROTECTED]]
> Sent: Saturday, April 27, 2002 7:21 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP] class PHP
> 
> The text of this proposal, test code, and updates live at
> petermoulding.com/class. I place it here for discussion of the best
> approach before people build code.
> 
> Class PHP
> 
> An invention for a classier PHP.
> 
> This invention uses PHP classes as Web pages. The invention can be
> implemented as a wrapper around PHP or as an enhancement to PHP. In
> Apache 2, the invention can be implemented as a filter to precede PHP.
I
> will give a quick outline of the requirement, then sketches of
> implementations, then detailed examples prototyped using PHP.
> 
> The invention is named class. An Apache implementation could be a
module
> named class. If you write code to implement this invention, suffix the
> project name with your name as in class_John.
> 
> To prevent a rapacious company copyrighting this invention using the
> excuse that it is a business process or anything else they can
> copyright, I declare my copyright on everything in this invention and
> any processes derivable from this. Please make your code
implementations
> GPL, www.gnu.org/copyleft/gpl.html, and mention my page at
> petermoulding.com/class.
> 
> Invention Requirement
> The main requirement is to replace PHP's page input with invented
input.
> 
> Here is a file named any_class.class that containing a PHP class named
> any_class:
> <?php
> class any_class
>     {
>     function any_class()
>         {
>         /* code to build a Web page. */
>         }
>     }
> ?>
> 
> Here is a Web page containing a PHP script to build the entire page
> using the PHP class any_class:
> <?php
> include_once("any_class.class");
> $any_class = new any_class();
> ?>
> 
> The invention makes PHP initiate any_class.class as if any_class were
> included and instantiated by the example Web page.
> 
> PHP Wrapper
> 
> The invention could be implemented as a module for Apache or another
Web
> server by writing a wrapper for PHP. The wrapper would accept a call
> from Apache then pass the call on to PHP so PHP could perform 100%
> unaltered as if PHP were called direct from Apache.
> 
> The module would look for class requests with a page of the form
*.class
> then intercept the URL and prepare to pass invented input to PHP. The
> Apache configuration parameters can ensure all requests for class go
to
> class and only requests for class to class. In a mixed class/PHP
> environment, the requested class can go to class and the PHP requests
> can go direct to PHP. There could also be a check in class for a class
> file so that all requests are directed to class and class processes
just
> those with a matching class file.
> 
> When class finds a valid class request, class builds a PHP Web page
that
> includes the class file and initiates the class. To make PHP read the
> invented Web page, you could trap PHP's Web page read and substitute
the
> invented page. As PHP has to access files within the constraints of a
> Web server, the access technique could vary from release to release
and
> across Web servers. I will describe two quick implementation
> possibilities.
> 
> If PHP reads files via Apache's file read functions (or an equivalent
on
> other web servers), class gets to view all file requests from PHP to
> Apache and monitor all replies. Class can then pass the invented page
> back to PHP without the request reaching Apache. PHP remains untouched
> by class.
> 
> Where a Web server does not provide file access functions or PHP
chooses
> to not use those functions, class would need a modification to PHP to
> intercept file reads. The interception depends on the exact
compilation
> of PHP and would be in the form of a wrapper around a file access
> routine in PHP. The wrapper (or interception layer) needs to be at a
> level where the code can see file names and subvert the whole file
read
> process. Interception at this level requires PHP release dependent
> coding and is a step toward the PHP enhancement described next.
> PHP Enhancement
> A PHP enhancement would be an implementation of the invention direct
> within PHP's code so that PHP can react to class requests in
conjunction
> with an external process or without an external process. The ultimate
> enhancement would be to incorporate the whole invention within PHP so
> there are no additional installation steps required.
> 
> A PHP enhancement could use a wrapper as described in PHP Wrapper or
the
> Apache 2 filter described next but use those devices just to trigger
> class processing then perform the whole processing within PHP. This
> approach has the advantage that the processing is independent of the
> trigger method and the trigger method is free from processing code.
> 
> The PHP enhancement could discover the need for class processing by
> whatever method suits the web server environment. The enhancement
would
> then verify the action is valid within constrains specified in
php.ini,
> verify a class file is available, and invoke the class file as if from
> an invented Web page of the same name as the class file.
> Apache 2 Filter
> 
> To implement this idea as an Apache 2 filter, you need a link to PHP
> that lets PHP know your code will provide the Web page input. Your
code
> then invents a Web page of the same name as the class file and passes
> the invented page to PHP. The Apache Notes field looks like a good
> vehicle for passing the invented page.
> 
> PHP has to discover the Web page will arrive in the Notes field or via
> another mechanism of your invention. That means a modification to PHP
> and something in php.ini to prevent accidental use of the modification
> in sites not using your code. The least PHP dependent method would be
to
> invent the page in your code and enhance PHP with a single trigger to
> make PHP read the input Web page from your mechanism. The approach
> minimises changes to PHP but makes the process Web server dependent.
The
> PHP enhancement described in a previous page is more PHP dependent but
> less Web server dependent.
> 
> Allow for other filters using the Apache Notes field. Wrap your
invented
> page in a simple XML tag that PHP can recognise within the Notes
field.
> 
> Detailed Example
> 
> Here is a file named any_class.class that containing a PHP class named
> any_class:
> <?php
> class any_class
>     {
>     function any_class()
>         {
>         /* code to build a Web page. */
>         }
>     }
> ?>
> 
> This class contains a constructor that builds the whole Web page using
> any combination of code, functions and classes valid within PHP
classes.
> I copied all the Web site construction code from one Web site in to a
> class/function wrapper and initiated Web page construction without
> error. In other tests there were some global variables that needed
> mention in a global statement within the outside function. If the
global
> communication within an application is a variable named $site, the
above
> example becomes:
> <?php
> class any_class
>     {
>     function any_class()
>         {
>         global $site;
>         /* code to build a Web page. */
>         }
>     }
> ?>
> 
> As the authors switch to 100% class based coding, global variables
> disappear in favour of a structure of variables with the class
> structure.
> 
> Now for a more detailed look. The following code is a PHP
implementation
> of a PHP wrapper built by pointing the Web server at pages of type
.html
> which then contain a script to call the appropriate class from a
> parallel file of type .class. In this version there is no code within
> the Web server so there has to be two files. Once the example is
> translated to C and added to a Web server as a module, the example
code
> becomes the content of a virtual Web page that is passed to PHP but
not
> stored on disk.
> 
> The first part of the code simply extracts the page name from PHP_SELF
> and saves the name in $class_new_page. There are many ways to derive
the
> page name from server variables. Your technique will vary depending on
> the Web server, the release of PHP and the options in php.ini. The
> example happens to work on all the variations of PHP and Web servers I
> currently use. The example also lets me remove the file type for known
> file names while leaving in name parts that happen to contain dots.
> 
> The second part of the code prepares variables for use in the
> constructor class. I used a class that does not know about URL or form
> variables so I copy them in to an array for the class. This code is
not
> needed if your class knows it will be initiated as the start of a
page.
> You only need this type of code if you want to use the class as both
the
> start of a page and as a class within other code.
> 
> You could pass URL variables to the class in the order read from the
URL
> but you do not control the URL order. You could leave all the
variables
> out and let the class find the variables but the class would have to
> know where to look, in the parameters of the constructor function or
in
> external variables. I use this part of the code to translate external
> variables to a form the class understands and will later convert the
> class to read direct. A better approach would be to enhance PHP to
read
> named parameters.
> 
> The third part of the code initiates the class. Initiation includes
both
> class file inclusion and class instantiation. I use include_once() to
> prevent multiple inclusions. Your Web server module should use
> include_once() for version of PHP that have include_once().
> 
> The variables are prefixed $class_new to reduce clashes with existing
> code. That means I can mix this code with legacy PHP code on sits
during
> conversion. In your Web site module the variables are external to PHP
so
> do not clash with anything within the class or subsequent code.
> 
> <?php
> // Extract page name:
> $class_new_parts_page = explode(".", array_pop(explode("/",
>     str_replace("\\", "/", $HTTP_SERVER_VARS["PHP_SELF"]))));
> if(in_array($class_new_parts_page[count($class_new_parts_page) - 1],
>     array("html", "php")))
>     {
>     array_pop($class_new_parts_page);
>     }
> $class_new_page = implode(".", $class_new_parts_page);
> 
> // Prepare variables:
> $class_new_variables = $HTTP_GET_VARS;
> foreach($HTTP_POST_VARS as $class_new_key => $class_new_value)
>     {
>     $class_new_variables[$class_new_key] = $class_new_value;
>     }
> 
> // Initiate the class:
> include_once("./" . $class_new_page . ".class");
> $$class_new_page = new $class_new_page($class_new_variables);
> ?>
> 
> The function initiation can be implemented in a function so all
> subsequent classes are initiated in a similar fashion. I use the
> following simple function because it works with existing classes on a
> development site. Once the existing site and classes are redeveloped,
> the "./" prefix and ".class" suffix will be replaced by named
constants.
> At that point the function will serve little purpose so will be
dropped.
> in some other sites the function may be expanded to extract dynamic
> classes from content databases. A logical extension of this invention
is
> to add code extraction from an XML database, something I describe in
> another document.
> 
> // A function to initiate a class:
> function class_new($class_new_class, $class_new_variables,
>     $class_new_prefix = "./", $class_new_suffix = ".class")
>     {
>     global $$class_new_class;
>     include_once($class_new_prefix . $class_new_class .
> $class_new_suffix);
>     $$class_new_class = new $class_new_class($class_new_variables);
>     }
> ?>
> 
> Implications
> 
> By now you realise the class will have the same name as the page so
will
> not suit sites based on many pages with different names. It is also of
> no interest to people to write HTML pages then insert small portions
of
> PPH code. This invention is for sites using pages generated by PHP
code
> so suits sites using dynamic content management. It suits sites that
> have a small number of pages presenting varied data.
> 
> Your site might have one page for registration, another for logging in
> then a single page/script that provides a shopping system while
another
> single page/script provides a search facility. Make the search a class
> and use this invention to initiate the class.
> 
> Once you develop dynamic content management, your sites end up as a
list
> of scripts delivering what looks like a series of intelligent pages.
The
> HTML pages execute PHP scripts and add nothing. This invention removes
> HTML layer between your class based scripts and the Web server.
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php


--- End Message ---
--- Begin Message ---
Whatever it says the guy took a lot of time to write it out lol

-----Original Message-----
From: John Holmes [mailto:[EMAIL PROTECTED]]
Sent: April 28, 2002 3:46 AM
To: 'Peter'; [EMAIL PROTECTED]
Subject: RE: [PHP] class PHP


Can someone translate this to English?

> -----Original Message-----
> From: Peter [mailto:[EMAIL PROTECTED]]
> Sent: Saturday, April 27, 2002 7:21 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP] class PHP
> 
> The text of this proposal, test code, and updates live at
> petermoulding.com/class. I place it here for discussion of the best
> approach before people build code.
> 
> Class PHP
> 
> An invention for a classier PHP.
> 
> This invention uses PHP classes as Web pages. The invention can be
> implemented as a wrapper around PHP or as an enhancement to PHP. In
> Apache 2, the invention can be implemented as a filter to precede PHP.
I
> will give a quick outline of the requirement, then sketches of
> implementations, then detailed examples prototyped using PHP.
> 
> The invention is named class. An Apache implementation could be a
module
> named class. If you write code to implement this invention, suffix the
> project name with your name as in class_John.
> 
> To prevent a rapacious company copyrighting this invention using the
> excuse that it is a business process or anything else they can
> copyright, I declare my copyright on everything in this invention and
> any processes derivable from this. Please make your code
implementations
> GPL, www.gnu.org/copyleft/gpl.html, and mention my page at
> petermoulding.com/class.
> 
> Invention Requirement
> The main requirement is to replace PHP's page input with invented
input.
> 
> Here is a file named any_class.class that containing a PHP class named
> any_class:
> <?php
> class any_class
>     {
>     function any_class()
>         {
>         /* code to build a Web page. */
>         }
>     }
> ?>
> 
> Here is a Web page containing a PHP script to build the entire page
> using the PHP class any_class:
> <?php
> include_once("any_class.class");
> $any_class = new any_class();
> ?>
> 
> The invention makes PHP initiate any_class.class as if any_class were
> included and instantiated by the example Web page.
> 
> PHP Wrapper
> 
> The invention could be implemented as a module for Apache or another
Web
> server by writing a wrapper for PHP. The wrapper would accept a call
> from Apache then pass the call on to PHP so PHP could perform 100%
> unaltered as if PHP were called direct from Apache.
> 
> The module would look for class requests with a page of the form
*.class
> then intercept the URL and prepare to pass invented input to PHP. The
> Apache configuration parameters can ensure all requests for class go
to
> class and only requests for class to class. In a mixed class/PHP
> environment, the requested class can go to class and the PHP requests
> can go direct to PHP. There could also be a check in class for a class
> file so that all requests are directed to class and class processes
just
> those with a matching class file.
> 
> When class finds a valid class request, class builds a PHP Web page
that
> includes the class file and initiates the class. To make PHP read the
> invented Web page, you could trap PHP's Web page read and substitute
the
> invented page. As PHP has to access files within the constraints of a
> Web server, the access technique could vary from release to release
and
> across Web servers. I will describe two quick implementation
> possibilities.
> 
> If PHP reads files via Apache's file read functions (or an equivalent
on
> other web servers), class gets to view all file requests from PHP to
> Apache and monitor all replies. Class can then pass the invented page
> back to PHP without the request reaching Apache. PHP remains untouched
> by class.
> 
> Where a Web server does not provide file access functions or PHP
chooses
> to not use those functions, class would need a modification to PHP to
> intercept file reads. The interception depends on the exact
compilation
> of PHP and would be in the form of a wrapper around a file access
> routine in PHP. The wrapper (or interception layer) needs to be at a
> level where the code can see file names and subvert the whole file
read
> process. Interception at this level requires PHP release dependent
> coding and is a step toward the PHP enhancement described next.
> PHP Enhancement
> A PHP enhancement would be an implementation of the invention direct
> within PHP's code so that PHP can react to class requests in
conjunction
> with an external process or without an external process. The ultimate
> enhancement would be to incorporate the whole invention within PHP so
> there are no additional installation steps required.
> 
> A PHP enhancement could use a wrapper as described in PHP Wrapper or
the
> Apache 2 filter described next but use those devices just to trigger
> class processing then perform the whole processing within PHP. This
> approach has the advantage that the processing is independent of the
> trigger method and the trigger method is free from processing code.
> 
> The PHP enhancement could discover the need for class processing by
> whatever method suits the web server environment. The enhancement
would
> then verify the action is valid within constrains specified in
php.ini,
> verify a class file is available, and invoke the class file as if from
> an invented Web page of the same name as the class file.
> Apache 2 Filter
> 
> To implement this idea as an Apache 2 filter, you need a link to PHP
> that lets PHP know your code will provide the Web page input. Your
code
> then invents a Web page of the same name as the class file and passes
> the invented page to PHP. The Apache Notes field looks like a good
> vehicle for passing the invented page.
> 
> PHP has to discover the Web page will arrive in the Notes field or via
> another mechanism of your invention. That means a modification to PHP
> and something in php.ini to prevent accidental use of the modification
> in sites not using your code. The least PHP dependent method would be
to
> invent the page in your code and enhance PHP with a single trigger to
> make PHP read the input Web page from your mechanism. The approach
> minimises changes to PHP but makes the process Web server dependent.
The
> PHP enhancement described in a previous page is more PHP dependent but
> less Web server dependent.
> 
> Allow for other filters using the Apache Notes field. Wrap your
invented
> page in a simple XML tag that PHP can recognise within the Notes
field.
> 
> Detailed Example
> 
> Here is a file named any_class.class that containing a PHP class named
> any_class:
> <?php
> class any_class
>     {
>     function any_class()
>         {
>         /* code to build a Web page. */
>         }
>     }
> ?>
> 
> This class contains a constructor that builds the whole Web page using
> any combination of code, functions and classes valid within PHP
classes.
> I copied all the Web site construction code from one Web site in to a
> class/function wrapper and initiated Web page construction without
> error. In other tests there were some global variables that needed
> mention in a global statement within the outside function. If the
global
> communication within an application is a variable named $site, the
above
> example becomes:
> <?php
> class any_class
>     {
>     function any_class()
>         {
>         global $site;
>         /* code to build a Web page. */
>         }
>     }
> ?>
> 
> As the authors switch to 100% class based coding, global variables
> disappear in favour of a structure of variables with the class
> structure.
> 
> Now for a more detailed look. The following code is a PHP
implementation
> of a PHP wrapper built by pointing the Web server at pages of type
.html
> which then contain a script to call the appropriate class from a
> parallel file of type .class. In this version there is no code within
> the Web server so there has to be two files. Once the example is
> translated to C and added to a Web server as a module, the example
code
> becomes the content of a virtual Web page that is passed to PHP but
not
> stored on disk.
> 
> The first part of the code simply extracts the page name from PHP_SELF
> and saves the name in $class_new_page. There are many ways to derive
the
> page name from server variables. Your technique will vary depending on
> the Web server, the release of PHP and the options in php.ini. The
> example happens to work on all the variations of PHP and Web servers I
> currently use. The example also lets me remove the file type for known
> file names while leaving in name parts that happen to contain dots.
> 
> The second part of the code prepares variables for use in the
> constructor class. I used a class that does not know about URL or form
> variables so I copy them in to an array for the class. This code is
not
> needed if your class knows it will be initiated as the start of a
page.
> You only need this type of code if you want to use the class as both
the
> start of a page and as a class within other code.
> 
> You could pass URL variables to the class in the order read from the
URL
> but you do not control the URL order. You could leave all the
variables
> out and let the class find the variables but the class would have to
> know where to look, in the parameters of the constructor function or
in
> external variables. I use this part of the code to translate external
> variables to a form the class understands and will later convert the
> class to read direct. A better approach would be to enhance PHP to
read
> named parameters.
> 
> The third part of the code initiates the class. Initiation includes
both
> class file inclusion and class instantiation. I use include_once() to
> prevent multiple inclusions. Your Web server module should use
> include_once() for version of PHP that have include_once().
> 
> The variables are prefixed $class_new to reduce clashes with existing
> code. That means I can mix this code with legacy PHP code on sits
during
> conversion. In your Web site module the variables are external to PHP
so
> do not clash with anything within the class or subsequent code.
> 
> <?php
> // Extract page name:
> $class_new_parts_page = explode(".", array_pop(explode("/",
>     str_replace("\\", "/", $HTTP_SERVER_VARS["PHP_SELF"]))));
> if(in_array($class_new_parts_page[count($class_new_parts_page) - 1],
>     array("html", "php")))
>     {
>     array_pop($class_new_parts_page);
>     }
> $class_new_page = implode(".", $class_new_parts_page);
> 
> // Prepare variables:
> $class_new_variables = $HTTP_GET_VARS;
> foreach($HTTP_POST_VARS as $class_new_key => $class_new_value)
>     {
>     $class_new_variables[$class_new_key] = $class_new_value;
>     }
> 
> // Initiate the class:
> include_once("./" . $class_new_page . ".class");
> $$class_new_page = new $class_new_page($class_new_variables);
> ?>
> 
> The function initiation can be implemented in a function so all
> subsequent classes are initiated in a similar fashion. I use the
> following simple function because it works with existing classes on a
> development site. Once the existing site and classes are redeveloped,
> the "./" prefix and ".class" suffix will be replaced by named
constants.
> At that point the function will serve little purpose so will be
dropped.
> in some other sites the function may be expanded to extract dynamic
> classes from content databases. A logical extension of this invention
is
> to add code extraction from an XML database, something I describe in
> another document.
> 
> // A function to initiate a class:
> function class_new($class_new_class, $class_new_variables,
>     $class_new_prefix = "./", $class_new_suffix = ".class")
>     {
>     global $$class_new_class;
>     include_once($class_new_prefix . $class_new_class .
> $class_new_suffix);
>     $$class_new_class = new $class_new_class($class_new_variables);
>     }
> ?>
> 
> Implications
> 
> By now you realise the class will have the same name as the page so
will
> not suit sites based on many pages with different names. It is also of
> no interest to people to write HTML pages then insert small portions
of
> PPH code. This invention is for sites using pages generated by PHP
code
> so suits sites using dynamic content management. It suits sites that
> have a small number of pages presenting varied data.
> 
> Your site might have one page for registration, another for logging in
> then a single page/script that provides a shopping system while
another
> single page/script provides a search facility. Make the search a class
> and use this invention to initiate the class.
> 
> Once you develop dynamic content management, your sites end up as a
list
> of scripts delivering what looks like a series of intelligent pages.
The
> HTML pages execute PHP scripts and add nothing. This invention removes
> HTML layer between your class based scripts and the Web server.
> 
> --
> 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


--- End Message ---
--- Begin Message ---
Hi,
I was using this little check to see if an uploaded image has the correct
type:

if($img && $img_type != 'image/jpeg'){
  $error['img'] = 'image has to be "jpeg"<BR>';
}

but the ImageCreateFromJPEG function in the next script returned:

Warning: imagecreatefromjpeg: '/tmp/1.jpg' is not a valid JPEG file

This seems to happen with images that are kind of corrupted or something, I
am not sure why. Anyhow, I implemented this as an error check instead:

if(!$photo = @ImageCreateFromJPEG($img)){
  $error['img'] = 'image is not a valid jpeg file<BR>';
}

This works, but my question is do I have to use 'ImageDestroy' everytime
after I used the 'ImageCreateFromJPEG' function? Would now any tmp files be
clogging up the /tmp directory? Would it suck up memory?

Thanks,
DrTebi


--- End Message ---
--- Begin Message ---
Is it possible to have PHP find out the ethernet's card MAC address??
I know that one can parse the output of dmesg or equvalent to find it 
out, but that would be OS platform
specific code.
I just want to know if php has a native way of finding out that information.
Thanks

Gerard

--- End Message ---
--- Begin Message ---
Please Cc: me on replies...

I've got to be doing something stupid, because I've succeeded at this 
PGP (gpg, whatever) stuff before (years ago), but...

I'm doing this:

$test = escapeshellarg($cleartext);
exec("cat $test | /usr/bin/pgpe -a -t -f -r '[EMAIL PROTECTED]' 
--pubring=/home/bodyline/.pgp/pubring.pkr 
--secring=/home/bodyline/.pgp/secring.pkr", $result, $error);
echo "TEST<BR>\n";
echo implode("<BR>\n", $result);
if ($error){
        echo "OS Error: $error<BR>\n";
}
echo "END TEST<BR>\n";

I'm getting this output:

-----BEGIN PGP MESSAGE-----
Version: PGPfreeware 5.0i for non-commercial use
MessageID: 3kStB52ChIWntEDMoGnXmy62k/g83h8g
qANQR1DBwk4DyES2iJ7I3h4QC/4t4gfjedwU6InFgKPNFXWg05fDCVT465vays98
5f8uuQbSsecwjSOC8EuG/23yxLu8Cx+0utaz11/DiSym72YhTkxk38XQEAeP3wYT
M4IRnH5T1JE7QvGif/MyqcmU3lOz5RQ7mqZtv+HmAs/gbW8E/sCSmiV4XEz/tv+e
GkBg8/ga+KoL7HguGAg39Rbu5Ex1/sXW4l04+FFZyf2X9Pii1evr66QOxqIuqvsF
ztomPJMiMdqYsn4hsbi9nOjBzf0pnFR4Z96SlnDURDwQ7M9O5Z4QO735UYTv+9gw
4A5jtKfXZsue2rC6gJ4QT+QZuk5KvjAlSh8/Dsrn5c6/gKWOz9Zn70VbhRqb4DT6
YGeCCFBjuGzCwL/RS+luNr5PxANFFfj0qS75SDRsvsEN0cUafRA8U9BbTLK+toEB
y3JkQufZtAdC5aHD/QcWnkGojAaM/fK1ZHxLyp09VHjWpT+2TI76kmTOnfGLuuw3
N9688m9To7Hrn+pRNeyHT5+zm9cL/isNsdbuSW/4XO+W/niTGLpAI/jHt7HkCRpr
LDvyoCDONT64xfqY17i16VBenH4KIdUIc+pz9qrETjBcRFJ7Z7JOeOrOxi/VQecT
jgr6D+xt4Zpl16LXPcd5baGcs6uCl3MD1zyjMKLvlOjiZ5yZ482iyLvYcdplZ5/R
+hP1GrkDwOZq1lsuJtJ6B/Ptz5E03A+bEQ9OAw4PHB214ZJ7apCuscTcBJOu7+wj
47wLLplEUOgMRIB+DZ8wp2Qq10+vYt3VyB8m6ef+Lq7bqT2bUioBoQg/gO4VSQrA
sg/l4SGgc8wW7fvGRI4XmrSHhDJcYrRcRw8rJS9rsQXBKIUIUfIfVZ2v/iynEAlP
qykTt84J8iHdFTYxwO4wwJC8w7Hahdc+AyYwsWANwmsF/QCZqzzWL76uTQ9ocasd
lh9U5u2VJZcwJ20OVKziaAlXu8u0AGNaOaqW7EcTrImEar6pSNJC6PGy3ISSXkbW
QFSHqJdsVUg873d/uMlrB8s0cI85kMkbb+162VCtITH/ckCxqtYiCwFvHVC+6Rq7
p1fD
=6EMp
-----END PGP MESSAGE-----

I plug that into:

/usr/bin/pgpv -f -o output

Everything seems fine... Except output has this in it:

^Kb^Estdin^H^@^@^@

That ain't right.

I've tried it with pasting the PGP MESSAGE and then ^D, and I've 
tried it with the message in a file, and I'm just completely stumped 
at this point.

With and without -t as well.  Pretty much the same thing.

I can do a test from the command line without PHP getting involved, 
and it all works just fine as well...

I've generated a second keypair and tried the second recipient (-r) 
and get the same thing.

I dunno when it happened, but both pgp.com and gpg.org are useless 
now, so I dunno where to turn...  And it *IS* working until PHP gets 
in the picture.

PHP is running as a CGI and exec('whoami') tells me I'm the user who 
owns the keyring, and the output sure *LOOKS* like a PGP message, so, 
like, it's not that PGP isn't doing something with my input.

I've tried it with the whole popen thing, and with the mkfifo thing 
for fake pipes, and I'll be durned if I can get those to do any 
better.  I can make them worse, by making stupid mistakes, but not 
better :-)

What am I doing that's stupid?...
-- 
Got Music? http://l-i-e.com/artists.htm
--- End Message ---
--- Begin Message ---
I am a Newbie at PHP

I am sure I am missing something small but...

I am trying to create a form selection box which an alphabetically sort
list of a unix group file.

The group file has the format groupname::groupnumber:

I have tried to create an array using the array=fgetcsv($fp, 30, ":") 
which does read each line of the file.  I have used this line in a while
loop and also a for loop, but everytime I exit the loop, the array now
has no information.

I found if the change the line to be array[]=fgetcsv($fp, 30, ":") then
I can exit the loops but now how do extract only the group names from
the array and be able to sort them.

Ideally what I would like to do is create an array where the keys =
group number and value = groupname. I need to be able to natsort the
values and display in the selection form box.



Help!?!?!?!?!?!?




--- End Message ---
--- Begin Message ---


Mark Pelillo wrote:

> I am a Newbie at PHP
>
> I am sure I am missing something small but...
>
> I am trying to create a form selection box which an alphabetically sort
> list of a unix group file.
>
> The group file has the format groupname::groupnumber:
>
> I have tried to create an array using the array=fgetcsv($fp, 30, ":")
> which does read each line of the file.  I have used this line in a while
> loop and also a for loop, but everytime I exit the loop, the array now
> has no information.
>
> I found if the change the line to be array[]=fgetcsv($fp, 30, ":") then
> I can exit the loops but now how do extract only the group names from
> the array and be able to sort them.
>
> Ideally what I would like to do is create an array where the keys =
> group number and value = groupname. I need to be able to natsort the
> values and display in the selection form box.

Well lets try....
<?php
$OutputArray = array(); //Create an array to the output
$fp = fopen ("yourgroupfile","r");  //Open the groupfile
while ($d = fgetcsv ($fp, 1000, ":")) { //While loop as long there is some
data
    $OutputArray[$d[2]] = $d[0];  //Set groupid as key, and groupname as
value
} //end of while
fclose ($fp); //close file
print_r($OutputArray); //Print out the array, to check the values!
?>

Please reply if this doesn't work?
By the way... if you got further problems, please tell us which version of
PHP you use.....

Regards,

Johan Holst Nielsen
www.weknowthewayout.com

--- End Message ---
--- Begin Message ---
Aljosa Mohorovic wrote:
> session cookie exists on client side and it is set to last 5 days.
> the problem is that after some time session data expires. cookie
> on client side exists ($PHPSESSID), but session data on server side
> does not exists.
> 
> i think that the answer is something like:
> ini_set("session.cache_expire", "7200");
> but i'm not sure. i need this fast, so thnx
> to anybody with a solution.
> 
>                       Aljosa
> 
> P.S.
> sorry for my bad english, here is the code:
Not too sure. Try messing with session.gc_maxlifetime. According to the 
php manual, this sets the length of time (in secs) before session data 
is cleared with the garbage collection routine.

Padraig


> ------------------------------------------------------------------
> <?php
> $time = (60*60*24*5);
> 
> ini_set("session.cache_expire", "7200");
> 
> $date = gmdate ("D, d M Y H:i:s") . " GMT";
> header ("Date: " . $date);
> header ("Expires: " . $date);
> header ("Last-Modified: " . $date);
> header ("Pragma: no-cache");
> header ("Cache-Control: no-cache");
> 
> session_set_cookie_params($time);
> ?>
> ------------------------------------------------------------------
> 



--- End Message ---
--- Begin Message ---
Hello all,

Does anyone have any snippets of code that will strip several characters 
from a string?  I am trying to figure out how to do this without using 3 
different if statement blocks.  This is what I am looking for.

ie....User email address is "Chris Ditty" 
<[EMAIL PROTECTED]>  or  Chris Ditty <[EMAIL PROTECTED]>

I need to be able to strip the quotes and everything between them and the 
< > signs from the first one and then the name and the < > signs from the 
second.

Does anyone know how to do this quickly and easily?

Thanks

CDitty

--- End Message ---
--- Begin Message ---
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Cditty) wrote:

> ie....User email address is "Chris Ditty" 
> <[EMAIL PROTECTED]>  or  Chris Ditty <[EMAIL PROTECTED]>
> 
> I need to be able to strip the quotes and everything between them and the 
> < > signs from the first one and then the name and the < > signs from the 
> second.
> 
> Does anyone know how to do this quickly and easily?

<http://php.net/preg-replace>.  For example:

preg_replace('/^.*<(.+)>.*$/',"$1",$mailstring);

-- 
CC
--- End Message ---
--- Begin Message ---
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Cc Zona) wrote:

> In article <[EMAIL PROTECTED]>,
>  [EMAIL PROTECTED] (Cditty) wrote:
> 
> > ie....User email address is "Chris Ditty" 
> > <[EMAIL PROTECTED]>  or  Chris Ditty <[EMAIL PROTECTED]>
> > 
> > I need to be able to strip the quotes and everything between them and the 
> > < > signs from the first one and then the name and the < > signs from the 
> > second.
> > 
> > Does anyone know how to do this quickly and easily?
> 
> <http://php.net/preg-replace>.  For example:
> 
> preg_replace('/^.*<(.+)>.*$/',"$1",$mailstring);

Whoops.  Hit send too quickly.  That should be:

$newstring=preg_replace('/^.*<(.+)>.*$/',"$1",$mailstring);

Note that this is *just* an example.  It will break where there are 
multiple addressees, a less-than sign in the addressee's name, etc.

-- 
CC
--- End Message ---
--- Begin Message ---
Clarification:
So really, what you want to achieve is to ONLY have the email address?

I'm POSITIVE there's a better way with ereg_replace(), but I haven't got
time to experiment, and i'm no expert :)

So, what I figured was that you would loop through the $email, and if the
first char wasn't a "<", strip it out:

"Chris Ditty" <[EMAIL PROTECTED]>
Chris Ditty" <[EMAIL PROTECTED]>
hris Ditty" <[EMAIL PROTECTED]>
ris Ditty" <[EMAIL PROTECTED]>
is Ditty" <[EMAIL PROTECTED]>
...
<[EMAIL PROTECTED]>


You're then left with "<something".  Assuming all your address' are wrapped
in < ... >, you'll now have <[EMAIL PROTECTED]>.

Then, you want to strip out the leading < and the trailing > only (this
means weird email address' which have a < or > in them won't break.

You should now have [EMAIL PROTECTED]


UNTESTED code:

<?
$email = '"Chris Ditty" <mail@redh>otsweeps.com>';

while (!eregi('^<', $email))
    {
    $email = substr($email, 1);
    //echo htmlspecialchars($email)."<BR>";
    }
$email = ereg_replace("^<", "", $email);
$email = ereg_replace(">$", "", $email);

echo htmlspecialchars($email)."<BR>";
?>


Like I said, this is probably NOT the best solution, just *a* solution, but
it should work.  It's independent of the "'s you had in there... all it
cares about is $email ending with "<something>", getting rid of the
preceeding it, and then getting rid of the <>'s that wrap it.

You might also like to get rid of anything trailing the >.

Uncomment line 6 to watch the progress of the while loop :)


Justin French
--------------------
Creative Director
http://Indent.com.au
--------------------



on 28/04/02 4:16 PM, CDitty ([EMAIL PROTECTED]) wrote:

> Hello all,
> 
> Does anyone have any snippets of code that will strip several characters
> from a string?  I am trying to figure out how to do this without using 3
> different if statement blocks.  This is what I am looking for.
> 
> ie....User email address is "Chris Ditty"
> <[EMAIL PROTECTED]>  or  Chris Ditty <[EMAIL PROTECTED]>
> 
> I need to be able to strip the quotes and everything between them and the
> < > signs from the first one and then the name and the < > signs from the
> second.
> 
> Does anyone know how to do this quickly and easily?
> 
> Thanks
> 
> CDitty
> 

--- End Message ---
--- Begin Message ---
Hi PHP digest readers.
 
Ok I have a problem and a question which I am certain many share and
even a solution to my problem, however I wish to hear how you dealt with
this issue to see if there is a better method. 
 
Ok for my problem, it is regarding a smilie system. Currently what
happens is if people post :P:P:P:P:P:P etc.. etc.. then the text field
expands to an ugly length. My current solution which I don't really like
is to limit the number of smiles which a person is allowed to use. Can
anyone propose a better solution than this? i.e. wrap them using PHP or
maybe I coded my html poorly which is why my table is expanding?
 
Secondly my question on a similar note whether to convert smilies at
runtime, or when a person submits a post? The beneifits at runtime is
less space used in the DB, and no worring about converting the converted
post back when it is needed to be edited, however with this method the
server has to do more processing in converting smilies each time the
post is viewed and vise versa.
 
Thanks for your time, and I anticipate any light which can be shed on
this issue.
 
Scott
--- End Message ---
--- Begin Message ---
I have made a php + mysql site and hosting in my own IIS server, but in my
school network, The page didnt change when i changed the data in mysql
server. I think is the cache problem, but i cant fix it even i tick the
"Update the page everytime when page load" in IE.
There is no such problem in any home pc. but only in my school's pcs
but when i type in www.xxxx.com/showdata.php????
then the page can be update.
Is there any code or setting can be set to over come this problem?

Thank you!


--- End Message ---
--- Begin Message ---
You could use Headers to tell the browser to expire the page "now"..


header ("Expires: Mon, 1 Jan 1990 05:00:00 GMT");    // Date in the past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
                                                      // always modified
header ("Cache-Control: no-cache, must-revalidate");  // HTTP/1.1
header ("Pragma: no-cache");


something like that should do it..

See if it works now..




----- Original Message -----
From: "Simonk" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, April 28, 2002 7:50 PM
Subject: [PHP] Auto refresh when data changed in Mysql


> I have made a php + mysql site and hosting in my own IIS server, but in my
> school network, The page didnt change when i changed the data in mysql
> server. I think is the cache problem, but i cant fix it even i tick the
> "Update the page everytime when page load" in IE.
> There is no such problem in any home pc. but only in my school's pcs
> but when i type in www.xxxx.com/showdata.php????
> then the page can be update.
> Is there any code or setting can be set to over come this problem?
>
> Thank you!
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

--- End Message ---
--- Begin Message ---
Hello all

I posted a link to Coding The Web (CodingTheWeb.com) a while ago as they had 
a channel dedicated to Google. It seems that they have updated the site a 
bit in the past few days and now have a news channel for PHP too. It is 
pretty cool:

http://www.codingtheweb.com/projects/newslog/portal/1_1.htm

What is really cool is the fact that you can syndicate their content for 
free. Take a look at the bottom of the page. There are two links to XML 
files:

http://www.codingtheweb.com/projects/newslog/portal/1_2.xml (RDF)
http://www.codingtheweb.com/projects/newslog/portal/1_3.xml (RSS)

You can use this content on your own web site for free!

Parsing out the data from an RDF file is pretty easy. Take a look at this 
tutorial to learn more:

http://www.webmasterbase.com/article/560

(or see:
http://www.phpclasses.org/browse.html/package/259.html
http://www.phpclasses.org/browse.html/package/61.html
http://www.phpclasses.org/browse.html/package/80.html  )

I have already added the RDF file to my personal start page. It makes sure 
that I always know about the latest PHP articles, tutorials, news etc.

To the Webmaster of CodingTheWeb.com if you are reading this: Thanks for 
creating this simple news portal. It works well, loads fast and you offer 
your content as XML. Nice. Well done.

Stefen


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.

--- End Message ---
--- Begin Message ---
(yes, newbie - but I *have* tried everything I know, I swear)

I'm trying to write a "comments" system for my site (because I think I 
can).  Basically, the script receives the ID of a particular entry (the 
site is a blog) via "?entry_id=<entry_id>".  It checks to see if there's 
a corresponding text file (<entry_id>.txt) and if so, it prints the 
contents of the text file and invites the user to input a comment.  If 
not, it prints "no comments" and invites the user... yadda yadda.

Now, unless I'm mistaken, passing the arguments are done like so: 
http://www.foo.com/comments.php?entry_id=test
Right?

Unfortunately, it doesn't work.  That is to say, everything about the 
script works, except recognition of the $entry_id variable.  Something 
as simple as: <title>comments for entry "<?php echo("$entry_id"); 
?>"</title> returns "<title>comments for entry ""</title>.

Saving the text file's URL to a variable:
<?php
$filename = http://www.foo.com/$entry_id; .txt;
?>

Doesn't work either.

I had a semi-hunch (brought on by my own inexperience, no doubt) that 
maybe I had to start a session or something on the referring page. Tried 
that (session_start();), didn't have any effect.  Bah.

Can anyone point out what I'm doing wrong?

TIA

-- 
Mark Gallagher

--- End Message ---
--- Begin Message ---
Which version of PHP you're running? May be you need to set register_globals
= On in your php.ini file.

--
Kind regards,
Yuri.

>>>> www.AceHoster.com <<<< Quality web hosting


"Mark Gallagher" <[EMAIL PROTECTED]> сообщил/сообщила в новостях
следующее: [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> (yes, newbie - but I *have* tried everything I know, I swear)
>
> I'm trying to write a "comments" system for my site (because I think I
> can).  Basically, the script receives the ID of a particular entry (the
> site is a blog) via "?entry_id=<entry_id>".  It checks to see if there's
> a corresponding text file (<entry_id>.txt) and if so, it prints the
> contents of the text file and invites the user to input a comment.  If
> not, it prints "no comments" and invites the user... yadda yadda.
>
> Now, unless I'm mistaken, passing the arguments are done like so:
> http://www.foo.com/comments.php?entry_id=test
> Right?
>
> Unfortunately, it doesn't work.  That is to say, everything about the
> script works, except recognition of the $entry_id variable.  Something
> as simple as: <title>comments for entry "<?php echo("$entry_id");
> ?>"</title> returns "<title>comments for entry ""</title>.
>
> Saving the text file's URL to a variable:
> <?php
> $filename = http://www.foo.com/$entry_id; .txt;
> ?>
>
> Doesn't work either.
>
> I had a semi-hunch (brought on by my own inexperience, no doubt) that
> maybe I had to start a session or something on the referring page. Tried
> that (session_start();), didn't have any effect.  Bah.
>
> Can anyone point out what I'm doing wrong?
>
> TIA
>
> --
> Mark Gallagher
>


--- End Message ---
--- Begin Message ---
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi all
I have a field in MySQL db like this: date TIMESTAMP, 
and it looks pretty regular like this: 20020428011911

when I come to use php date("D M Y", $myTimeStamp) though I get 

TUE JAN 2038!

I see something in the manual re this date but I'm afraid I still can't
work it out so some advice/help would be greatly appreciated :-)

- -- 
Nick Wilson     //  www.explodingnet.com



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)

iD4DBQE8y++SHpvrrTa6L5oRAh3xAJ9lfFdB1VW3KUHCWxnnksN+Uw950QCYpfg6
OCdApC0Nh/8hi8MYQY3OTQ==
=FnlM
-----END PGP SIGNATURE-----
--- End Message ---
--- Begin Message ---
First, the timestamp that is retrieved from mysql is NOT the same as is
required for PHP.

Second, do you REALLY wan the Day of the Week (Mon, Tue, Wed) or the date of
the month (1,2,3,4,5,6,...)?

Third, let Mysql do the conversion for you.  For instance if you timestamp
field is named "mydate":
  SELECT DATE_FORMAT(mydate,"%e %b %Y") AS thedate FROM mytable

----- Original Message -----
From: Nick Wilson <[EMAIL PROTECTED]>
To: php-general <[EMAIL PROTECTED]>
Sent: Sunday, April 28, 2002 7:48 AM
Subject: [PHP] date problem


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi all
I have a field in MySQL db like this: date TIMESTAMP,
and it looks pretty regular like this: 20020428011911

when I come to use php date("D M Y", $myTimeStamp) though I get

TUE JAN 2038!

I see something in the manual re this date but I'm afraid I still can't
work it out so some advice/help would be greatly appreciated :-)

- --
Nick Wilson     //  www.explodingnet.com



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)

iD4DBQE8y++SHpvrrTa6L5oRAh3xAJ9lfFdB1VW3KUHCWxnnksN+Uw950QCYpfg6
OCdApC0Nh/8hi8MYQY3OTQ==
=FnlM
-----END PGP SIGNATURE-----

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


--- End Message ---
--- Begin Message ---
You can include date formatting function in your SQL statement:
DATE_FORMAT(date,format)
http://www.mysql.com/doc/D/a/Date_and_time_functions.html

--
Kind regards,
Yuri.

>>>> www.AceHoster.com <<<< Quality web hosting


"Nick Wilson" <[EMAIL PROTECTED]> ???????/???????? ? ???????? ?????????:
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi all
> I have a field in MySQL db like this: date TIMESTAMP,
> and it looks pretty regular like this: 20020428011911
>
> when I come to use php date("D M Y", $myTimeStamp) though I get
>
> TUE JAN 2038!
>
> I see something in the manual re this date but I'm afraid I still can't
> work it out so some advice/help would be greatly appreciated :-)
>
> - --
> Nick Wilson     //  www.explodingnet.com
>
>
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.0.6 (GNU/Linux)
>
> iD4DBQE8y++SHpvrrTa6L5oRAh3xAJ9lfFdB1VW3KUHCWxnnksN+Uw950QCYpfg6
> OCdApC0Nh/8hi8MYQY3OTQ==
> =FnlM
> -----END PGP SIGNATURE-----


--- End Message ---
--- Begin Message ---
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


* and then Richard Emery declared....
> Third, let Mysql do the conversion for you.  For instance if you timestamp
> field is named "mydate":
>   SELECT DATE_FORMAT(mydate,"%e %b %Y") AS thedate FROM mytable

Nice one, cheers Richard.
I didn't know about that mysql function...
- -- 
Nick Wilson     //  www.explodingnet.com



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)

iD8DBQE8y/S9HpvrrTa6L5oRAs9cAJ4jcd8dukhfdaJIla/irYNvnX2ZRwCgoIhU
WjS6nkU1UM44crfOGWlBxRA=
=RYIM
-----END PGP SIGNATURE-----
--- End Message ---
--- Begin Message ---
Hello all, i am trying to query a mysql database to see if a customer all
ready exists in a database and if so then use there customer id to insert
data into another table. Can anyone tell me what valuse mysql returns if the
query returns no value? i have the following code:

$customer_id_check=("SELECT id FROM $customer_table WHERE firstname =
'$firstname' && lastname = '$lastname' && email = '$email'");
                                $result1=mysql_query($customer_id_check);
                                if (!$result1) {
                                   print "theres no such customer!";
                                }

which i thought should echo 'theres no such customer!' if a customer didnt
exist who fitted the query, however it doesnt and if i echo $result1 i get
'Resource id #2 not what i was expecting (was more expecting something along
the lines of NULL).

Thanks for any help in advance!!!

Cheers From

baldey_uk


--- End Message ---
--- Begin Message ---
If no customers are found, then:

if (mysql_num_rows($result1)==0) {
   print "theres no such customer!";
}


----- Original Message -----
From: baldey_uk <[EMAIL PROTECTED]>
To: Php-General <[EMAIL PROTECTED]>
Sent: Sunday, April 28, 2002 7:48 AM
Subject: [PHP] failed query results


Hello all, i am trying to query a mysql database to see if a customer all
ready exists in a database and if so then use there customer id to insert
data into another table. Can anyone tell me what valuse mysql returns if the
query returns no value? i have the following code:

$customer_id_check=("SELECT id FROM $customer_table WHERE firstname =
'$firstname' && lastname = '$lastname' && email = '$email'");
$result1=mysql_query($customer_id_check);
if (!$result1) {
   print "theres no such customer!";
}

which i thought should echo 'theres no such customer!' if a customer didnt
exist who fitted the query, however it doesnt and if i echo $result1 i get
'Resource id #2 not what i was expecting (was more expecting something along
the lines of NULL).

Thanks for any help in advance!!!

Cheers From

baldey_uk



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


--- End Message ---
--- Begin Message ---
Hello,

I have a newbie question for you.

I do a query, I'd like to display the result but I'd like to go to a new
line for each row.

I use this code that's work :
<?php
    for ($i = 0; $i<mysql_num_rows($result); $i++)
  {
   echo mysql_result($result,$i, "NAME");
  }
?>

but this not work

<?php
    for ($i = 0; $i<mysql_num_rows($result); $i++)
  {
   echo mysql_result($result,$i, "NAME");<br>
  }
?>

Could you tell me how I can do to have a <br> after each row.

Thanks for your help :)

Bye





 

--- End Message ---
--- Begin Message ---
echo mysql_result($result,$i, "NAME");<br>
should be:
echo mysql_result($result,$i, "NAME") . '<br>';

Andrew
----- Original Message ----- 
From: "Christian Ista" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, April 28, 2002 2:51 PM
Subject: [PHP] HTML in PHP


> Hello,
> 
> I have a newbie question for you.
> 
> I do a query, I'd like to display the result but I'd like to go to a new
> line for each row.
> 
> I use this code that's work :
> <?php
>     for ($i = 0; $i<mysql_num_rows($result); $i++)
>   {
>    echo mysql_result($result,$i, "NAME");
>   }
> ?>
> 
> but this not work
> 
> <?php
>     for ($i = 0; $i<mysql_num_rows($result); $i++)
>   {
>    echo mysql_result($result,$i, "NAME");<br>
>   }
> ?>
> 
> Could you tell me how I can do to have a <br> after each row.
> 
> Thanks for your help :)
> 
> Bye
> 
> 
> 
> 
> 
>  
> 
> 

--- End Message ---

Reply via email to