php-general Digest 23 Nov 2007 07:12:11 -0000 Issue 5143

Topics (messages 264965 through 264980):

Re: Code Critique Please :)
        264965 by: Simeon F. Willbanks
        264968 by: Oscar Gosdinski
        264969 by: Robert Cummings

Question about urlencode....
        264966 by: Colin Guthrie
        264978 by: TG

Logic Help please
        264967 by: Mohamed Jama
        264971 by: Richard Heyes

Re: getenv ... i think
        264970 by: Andrés Robinet

Parsing XML with DTD
        264972 by: Skip Evans
        264973 by: Per Jessen
        264974 by: Jochem Maas
        264975 by: Skip Evans
        264976 by: Andrés Robinet

Re: image galleries
        264977 by: Martin Marques

Re: PHP + Amazon to retrieve book data
        264979 by: Dan Joseph

Page not displayed/Forbidden on PHP forms
        264980 by: Jeffrey

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 --- No I did not, thanks! For those that need more information, here is a good tutorial:

http://en.wikibooks.org/wiki/XML_-_Managing_Data_Exchange/Converting_MySQL_to_XML

Simeon

On Nov 22, 2007, at 10:05 AM, [EMAIL PROTECTED] wrote:

You know that mysql has an output option for producing XML ?


/Per Jessen, Zürich

--- End Message ---
--- Begin Message ---
On Nov 21, 2007 2:05 PM, Simeon F. Willbanks <[EMAIL PROTECTED]> wrote:
> 3. Object Oriented principles
I see that you tried to implement Singleton pattern in the DB class,
but you have a mistake. $dbConnection attribute is not a static
member, so every time you call the constructor $dbConnection won't be
initialized, so your code will always initialize this attribute.

There is something that i always wonder about Singleton pattern in
PHP, do you really have a benefit using this pattern in PHP? The idea
behind this pattern is that only one instance of the class is created,
it works great in Java because all requests are processed inside a JVM
and this instance created will really be the only one defined. Because
in PHP every request has its own environment, you will have several
instances of this class per request processed.

> 4. Strategy Design Pattern
>         - Interface used for column attribute parsing
I've checked the code in MySQLToXML.phps and i see a lot of
ParseDatabaseColumnAttributeXXX classes that implements
ParseDatabaseColumnAttribute interface. I think that those classes
should be methods of  a DatabaseColumnAttributeParser instead of
defining so many classes. Also the names of those classes suggest me
that they are methods not objects.

-- 
Saludos
Oscar

--- End Message ---
--- Begin Message ---
On Thu, 2007-11-22 at 12:46 -0500, Oscar Gosdinski wrote:
>
> There is something that i always wonder about Singleton pattern in
> PHP, do you really have a benefit using this pattern in PHP? The idea
> behind this pattern is that only one instance of the class is created,
> it works great in Java because all requests are processed inside a JVM
> and this instance created will really be the only one defined. Because
> in PHP every request has its own environment, you will have several
> instances of this class per request processed.

Doesn't matter... you may have multiple requests for the object within
the same HTTP request. Singleton pattern is very valid in PHP.

Cheers,
Rob.
-- 
...........................................................
SwarmBuy.com - http://www.swarmbuy.com

    Leveraging the buying power of the masses!
...........................................................

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

OK this one is a little embarrasing. I've been doing this for years and
I just wonder if I'm wrong....

Say you have an exit link on your site, e.g. /leave.php, which accepts a
"url" get arg. You use this page to record stats/whatever and then issue
a Location: header to take the user to the correct location.

Fairly standard yeah?

Well I've been doing something like:

$url = 'http://colin.guthr.ie/';
echo '<a href="/leave.php?url='.urlencode($url).'">Click</a>';

The logic in /leave.php does not need to call urldecode as it's done
automatically by PHP.

This has worked well for me in the browsers I've used (IE, FF etc.)

Recently, though, when using google webmaster tools I noticed that I was
getting a lot of 404's and this ultimately stemmed from the double
urlencoding of these url paramaters whereby the % signs used to encode
characters like / as %2F were encoded themselves leading to %252F. PHP
would automatically urldecode this to %2F but that still leaves me with
an encoded variable. Ugg.

So my question is, is the google bot just getting it wrong? Is it
reading the link and seeing a % and encoding it? Or is it finding a page
somewhere randomly on the interweb which has incorrectly double encoded
it and going from there?

It doesn't give you an referrer info which makes tracking down such
errors pretty tricky.... :(

I could just call urldecode manually, but I'm curious as to why I should
need to. Anyone fought with this before?

Col

--- End Message ---
--- Begin Message ---
Unless your URL is more complicated than your example, you shouldn't need to 
use urlencode() at all.   You'd need to use it in a case where your string 
may contain characters that aren't valid in URLs like spaces and such:

$baseurl = "http://www.somesearchsite.com/search=";;
$searchfor = "Grace O'Mally";

$searchurl = $baseurl . urlencode($searchfor);

Since you set your URL explicitly and it's not something entered by a user, 
you shouldn't need it.

Try that and see if it fixes your other problem with double encoding.. or at 
least gives a better clue as to where it's coming from.

Slainte!

-TG

----- Original Message -----
From: Colin Guthrie <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Date: Thu, 22 Nov 2007 16:19:18 +0000
Subject: [PHP]  Question about urlencode....

> Hi,
> 
> OK this one is a little embarrasing. I've been doing this for years and
> I just wonder if I'm wrong....
> 
> Say you have an exit link on your site, e.g. /leave.php, which accepts a
> "url" get arg. You use this page to record stats/whatever and then issue
> a Location: header to take the user to the correct location.
> 
> Fairly standard yeah?
> 
> Well I've been doing something like:
> 
> $url = 'http://colin.guthr.ie/';
> echo '<a href="/leave.php?url='.urlencode($url).'">Click</a>';
> 
> The logic in /leave.php does not need to call urldecode as it's done
> automatically by PHP.
> 
> This has worked well for me in the browsers I've used (IE, FF etc.)
> 
> Recently, though, when using google webmaster tools I noticed that I was
> getting a lot of 404's and this ultimately stemmed from the double
> urlencoding of these url paramaters whereby the % signs used to encode
> characters like / as %2F were encoded themselves leading to %252F. PHP
> would automatically urldecode this to %2F but that still leaves me with
> an encoded variable. Ugg.
> 
> So my question is, is the google bot just getting it wrong? Is it
> reading the link and seeing a % and encoding it? Or is it finding a page
> somewhere randomly on the interweb which has incorrectly double encoded
> it and going from there?
> 
> It doesn't give you an referrer info which makes tracking down such
> errors pretty tricky.... :(
> 
> I could just call urldecode manually, but I'm curious as to why I should
> need to. Anyone fought with this before?
> 
> Col

--- End Message ---
--- Begin Message ---
Hi, I am doing an online calendar for holiday application.

Now I got a table with these fields among many others.

  `req_id` int(11) NOT NULL auto_increment,
  `req_date` date NOT NULL,
  `username` varchar(100) NOT NULL,
  `start_date` date NOT NULL,
  `end_date` date NOT NULL,
  `days_off` int(11) NOT NULL,


With start_date is something like [ 1 - 10 - 2007 ] and end_date  is like [ 20 
- 10 -2007 ].

I am thinking whats the best way to present such data ? and how to show 
overlapping days between users ?


Thanks very much in advance



-----Original Message-----
From: Simeon F. Willbanks [mailto:[EMAIL PROTECTED] 
Sent: 22 November 2007 15:23
To: [EMAIL PROTECTED]
Subject: Re: [PHP] Code Critique Please :)

No I did not, thanks!  For those that need more information, here is a  
good tutorial:

http://en.wikibooks.org/wiki/XML_-_Managing_Data_Exchange/Converting_MySQL_to_XML

Simeon

On Nov 22, 2007, at 10:05 AM, [EMAIL PROTECTED]  
wrote:

> You know that mysql has an output option for producing XML ?
>
>
> /Per Jessen, Zürich

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

--- End Message ---
--- Begin Message ---
Hi, I am doing an online calendar for holiday application.

Now I got a table with these fields among many others.

  `req_id` int(11) NOT NULL auto_increment,
  `req_date` date NOT NULL,
  `username` varchar(100) NOT NULL,
  `start_date` date NOT NULL,
  `end_date` date NOT NULL,
  `days_off` int(11) NOT NULL,


With start_date is something like [ 1 - 10 - 2007 ] and end_date  is like [ 20 
- 10 -2007 ].

I am thinking whats the best way to present such data ? and how to show 
overlapping days between users ?

Something like:

          Jan      Feb
        1 2 3 4  1 2 3 4 ...
       +--------------------
Richard|o o o o  o o o o
   Fred|x x o o  o o o o
Mohamed|o o o x  x o o o

With HTML you could use colours to represent days/weeks off making it more apparent, eg. nothing/white for no holiday booked, and red for one booked. And if you're going to go to the day granularity, an IFRAME might be needed with left/right scrolling.

--
Richard Heyes
+44 (0)800 0213 172
http://www.websupportsolutions.co.uk

Knowledge Base and HelpDesk software
that can cut the cost of online support

--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Per Jessen [mailto:[EMAIL PROTECTED]
> Sent: Thursday, November 22, 2007 8:08 AM
> To: [EMAIL PROTECTED]
> Subject: Re: [PHP] getenv ... i think
> 
> Steven Macintyre wrote:
> 
> > If i take OUT the getenv if then, it works ... so i know that is
> where
> > the problem is.
> 
> I didnt bother with reading all your code, but maybe you should use
> $_SERVER['REMOTE_HOST'] instead of the getenv() call ?
> 
> 
> /Per Jessen, Zürich
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

Maybe this is what you want... take a look (in a syntax highlighting PHP 
editor):

<?php
$hash = $_GET['hash'];
require_once('db.class.php');

$db = new db_class;
$db->connect();

/*
        You should have an escape method in the db class, otherwise take a look 
at mysql_real_escape_string - for MySQL
        Also, beware of magic quotes if they are enabled they can mess things 
up (not in this case,
        but as a general hint).
        I usually put things like these in an .htaccess file.
        Here's a sample, for a site under construction:
                php_flag short_open_tag on
                php_flag register_globals off
                php_flag magic_quotes_gpc off
                php_flag magic_quotes_runtime off
                php_flag magic_quotes_sybase off
                # Switch to off in production stage
                php_flag display_errors on
                php_value error_reporting 2039
                # This setting depends on you requirements
                php_value max_execution_time 300 
*/
$safeHash = $db->escape($hash); 
/*
        If your db class doesn't have an escape method you can do
        $safeHash = mysql_real_escape_string($hash);
*/

$r = $db->select("SELECT duration, label, website FROM hhcu_codonations where 
hash = '$safeHash' AND valid = '1'");

while ($row=$db->get_row($r)) {
        // found record - lets see if we can display the image and which image
        extract ($row);
        $now = time();
        if ($duration >= $now) {
                /*
                        The call on this is as follows;
                        <img 
src="http://mydev.co.za/myscript.php?hash=ARBHASHCODE"; border='0'>
                */
                $referer = $_SERVER['HTTP_REFERER'];
                $params = parse_url($referer);
                // Beware of gotchas if the referer has no "www" in the host 
param
                // We'll add "www." to the host if it's not there
                $host = (substr($params['host'], 0, 4) == 'www.') ? 
$params['host'] : 'www.'.$params['host'];
                // Now $host holds something like "www.subscribersite.com"
                $refererWebsite = $params['scheme'].'://'.$host.'/';
                /*
                        So now, the referer is the expected referer or not
                        You don't need to use MD5 here, you've already checked 
the hash
                        when you queried the DB. You now need to check that the 
referer is right for the supplied hash
                        I'm assuming here you are only hashing the website's 
url. You would only need to check the hash
                        against the request headers if you use a more complex 
hashing strategy like the following
                        
                        define('HASH_SALT', 'a secret string');                 
                        $websiteUrl = 'http://www.subscribersite.com/';
                        $websiteIP = '60.50.40.30';
                        $hashToStoreInDB = 
md5($websiteUrl.$websiteIP.HASH_SALT);
                        
                        But if you use such a method, you wouldn't need to 
check the referer either, you'd build a tentative
                        hash out of the $_SERVER parameters (HTTP_REFERER, 
REMOTE_ADDR) and the HASH_SALT constant,
                        match that tentative hash against the supplied hash 
($_GET['hash']), and then look up that hash
                        in the database if both hashes match... that would be 
all
                */
                if ($refererWebsite == $website) {
                        switch ($label) {
                                // ... code to follow
                        }
                }
        }
}

--- End Message ---
--- Begin Message ---
Hey all,

I've been asked if it's possible to parse XML files given a DTD file that describes the elements within it, so I've been looking through the docs at php.net.

So far I've found this:

http://us.php.net/manual/en/ref.xml.php

Which has some samples on, but nothing that I see will take a DTD file and parse the XML accordingly.

I'm thinking something like this is probably possible.

I'm still looking through the docs, but if anyone can point me in the right direction would be appreciated.

Thanks!
Skip

--
Skip Evans
Big Sky Penguin, LLC
503 S Baldwin St, #1
Madison, WI 53703
608-250-2720
http://bigskypenguin.com
=-=-=-=-=-=-=-=-=-=
Check out PHPenguin, a lightweight and versatile
PHP/MySQL, AJAX & DHTML development framework.
http://phpenguin.bigskypenguin.com/

--- End Message ---
--- Begin Message ---
Skip Evans wrote:

> I've been asked if it's possible to parse XML files given a DTD file
> that describes the elements within it, 

Yes it is. 

> Which has some samples on, but nothing that I see
> will take a DTD file and parse the XML accordingly.
> I'm thinking something like this is probably possible.

You don't actually need to DTD to parse it, but it does help with the
syntax-check of the contents.


/Per Jessen, Zürich

--- End Message ---
--- Begin Message ---
Skip Evans wrote:
> Hey all,
> 
> I've been asked if it's possible to parse XML files given a DTD file
> that describes the elements within it, so I've been looking through the
> docs at php.net.
> 
> So far I've found this:
> 
> http://us.php.net/manual/en/ref.xml.php
> 
> Which has some samples on, but nothing that I see will take a DTD file
> and parse the XML accordingly.

use php5 and the DOM extension (not XML and not DOMXML):

http://us.php.net/manual/en/ref.dom.php

> 
> I'm thinking something like this is probably possible.
> 
> I'm still looking through the docs, but if anyone can point me in the
> right direction would be appreciated.
> 
> Thanks!
> Skip
> 

--- End Message ---
--- Begin Message ---
Hey Jochem & all,

Thanks much for this tip. I will check it out.

A little further reading looks like PEAR provides some XML and DTD capabilities? Anyone have any experience with this?

Also, the reason I asked about the DTD is that these XML files are really extensive, providing lots of varied info about literature, history, a whole ton of topics, so I thought parsing the DTD will be necessary to know what kinds of data I'm really looking at.

I'll check out Jochem's suggestion now, but would also like to hear if anyone has used PEAR, and also about the need for the DTD for big, complicated XML files.

Would it be helpful if I pasted one of the XML files to the list?

Thanks again!
Skip


Jochem Maas wrote:
Skip Evans wrote:
Hey all,

I've been asked if it's possible to parse XML files given a DTD file
that describes the elements within it, so I've been looking through the
docs at php.net.

So far I've found this:

http://us.php.net/manual/en/ref.xml.php

Which has some samples on, but nothing that I see will take a DTD file
and parse the XML accordingly.

use php5 and the DOM extension (not XML and not DOMXML):

http://us.php.net/manual/en/ref.dom.php

I'm thinking something like this is probably possible.

I'm still looking through the docs, but if anyone can point me in the
right direction would be appreciated.

Thanks!
Skip




--
Skip Evans
Big Sky Penguin, LLC
503 S Baldwin St, #1
Madison, WI 53703
608-250-2720
http://bigskypenguin.com
=-=-=-=-=-=-=-=-=-=
Check out PHPenguin, a lightweight and versatile
PHP/MySQL, AJAX & DHTML development framework.
http://phpenguin.bigskypenguin.com/

--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Skip Evans [mailto:[EMAIL PROTECTED]
> Sent: Thursday, November 22, 2007 5:35 PM
> To: Jochem Maas
> Cc: PHP-General
> Subject: Re: [PHP] Parsing XML with DTD
> 
> Hey Jochem & all,
> 
> Thanks much for this tip. I will check it out.
> 
> A little further reading looks like PEAR provides
> some XML and DTD capabilities? Anyone have any
> experience with this?
> 
> Also, the reason I asked about the DTD is that
> these XML files are really extensive, providing
> lots of varied info about literature, history, a
> whole ton of topics, so I thought parsing the DTD
> will be necessary to know what kinds of data I'm
> really looking at.
> 
> I'll check out Jochem's suggestion now, but would
> also like to hear if anyone has used PEAR, and
> also about the need for the DTD for big,
> complicated XML files.
> 
> Would it be helpful if I pasted one of the XML
> files to the list?
> 
> Thanks again!
> Skip
> 
> 
> Jochem Maas wrote:
> > Skip Evans wrote:
> >> Hey all,
> >>
> >> I've been asked if it's possible to parse XML files given a DTD file
> >> that describes the elements within it, so I've been looking through
> the
> >> docs at php.net.
> >>
> >> So far I've found this:
> >>
> >> http://us.php.net/manual/en/ref.xml.php
> >>
> >> Which has some samples on, but nothing that I see will take a DTD
> file
> >> and parse the XML accordingly.
> >
> > use php5 and the DOM extension (not XML and not DOMXML):
> >
> > http://us.php.net/manual/en/ref.dom.php
> >
> >> I'm thinking something like this is probably possible.
> >>
> >> I'm still looking through the docs, but if anyone can point me in
> the
> >> right direction would be appreciated.
> >>
> >> Thanks!
> >> Skip
> >>
> >
> >
> 
> --
> Skip Evans
> Big Sky Penguin, LLC
> 503 S Baldwin St, #1
> Madison, WI 53703
> 608-250-2720
> http://bigskypenguin.com
> =-=-=-=-=-=-=-=-=-=
> Check out PHPenguin, a lightweight and versatile
> PHP/MySQL, AJAX & DHTML development framework.
> http://phpenguin.bigskypenguin.com/
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php


I believe the DTD would only be helpful to you if you are validating the XML
stream yourself... If you only need to know what kind of data you are
looking at, you can just grab the "doctype" property for the DocumentElement
and compare it to a set of (known by you) predefined doctypes... After that,
you can implement a walk through the elements of the XML stream knowing what
you can expect about it. This will simplify your programming logic, unless
there are infinite doctypes for the data source in question.

For validation, you can use this
http://us.php.net/manual/en/function.dom-domdocument-validate.php (only if
you are interested in the document being well formed according to the DTD)

For identifying the DTD, check the DocumentElement "doctype" property and
the "DOMDocumentType" class http://us.php.net/manual/en/ref.dom.php.

Andrés Robinet | Lead Developer | BESTPLACE CORPORATION
5100 Bayview Drive 206, Royal Lauderdale Landings, Fort Lauderdale, FL 33308
| TEL 954-607-4207 | FAX 954-337-2695 | 
Email: [EMAIL PROTECTED]  | MSN Chat: [EMAIL PROTECTED]  |  SKYPE:
bestplace |  Web: bestplace.biz  | Web: seo-diy.com

--- End Message ---
--- Begin Message ---
Lisa A escribió:
> Does anyone know of an image gallery I can use on multiple pages of a 
> website.  I'd like to be able to click on the thumbnails and see a larger 
> image.
> Hopefully something simple and easy to install.

gallery2

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

This should help:

http://hades.phparch.com/ceres/public/article/index.php/art::web_services::php5_soap/2

-Dan Joseph

On Nov 21, 2007 7:39 AM, Scott Wilcox <[EMAIL PROTECTED]> wrote:
> Hey folks,
>
> Does anyone have any resources or links to resources concerning
> obtaining book data via Amazons web services?
>
> Any help/pointers appreciated.
>
> Scott.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



-- 
-Dan Joseph

"Build a man a fire, and he will be warm for the rest of the day.
Light a man on fire, and will be warm for the rest of his life."

--- End Message ---
--- Begin Message --- We are running identical web applications with two different hosts. Both are LAMP.

With one of hosts, we are having reports of users seeing "Page not displayed" or "403 Forbidden" after submitting forms. These forms are always sending data to the same page from which they started and the problem is not consistent. (ie. sometimes the forms work fine, sometimes they deliver the error). The problem only seems to have occurred with users on IE and mostly who are a significant distance from the server.

This does not seem to be occurring at the other host.

The problem host is not being responsive about solving the problem (which will cost them our business). Could this be a PHP time-out issue? Something in the PHP settings or is it likely a server issue or something else.

Your expertise - as always - is much appreciated!

Jeff

--- End Message ---

Reply via email to