php-general Digest 9 Oct 2009 01:48:48 -0000 Issue 6381

Topics (messages 298768 through 298782):

Re: Apache Rewrite Issues
        298768 by: Ashley Sheridan

Re: Insult my code!
        298769 by: Eric Bauman
        298771 by: Eric Bauman

Re: what is php4  popularity?
        298770 by: Eric Bauman
        298775 by: Paul M.

avoid Denial of Service
        298772 by: Gerardo Benitez
        298773 by: Gaurav Kumar
        298774 by: Ashley Sheridan

XML RSS - Unexpected End of File error
        298776 by: Ashley Sheridan
        298777 by: Jonathan Tapicer
        298778 by: Ashley Sheridan
        298779 by: Jim Lucas
        298780 by: Ashley Sheridan

Newbie: Array of objects iteration
        298781 by: MEM

Newb question about getting keys/values from a single array element
        298782 by: Daevid Vincent

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 Wed, 2009-10-07 at 16:49 -0400, Paul M Foster wrote:

> On Wed, Oct 07, 2009 at 11:52:00AM +0100, Russell Seymour wrote:
> 
> > Morning,
> >
> > I am trying to make my URLs more search engine friendly and I have come
> > up against a problem.
> >
> > I want the following URL:
> >
> >     mysite.example.com/articles/Test Story
> >
> > to be proxied to
> >
> >     mysite.example.com/index.php?m=articles&t=Test%20Story
> >
> 
> Aside from the solution to your problem (which I don't have), you might
> want to double-check on the "search engine friendliness" of URLs which
> contain query strings. I know at one time this was the case, but the
> latest I've heard is that URLs like your second one above are completely
> okay with search engines. If someone else knows different, please speak
> up.
> 
> And oh by the way, don't *ever* store a filename with a space in it on
> your computer. It's Evil(tm). I curse the idiot who first came up with
> allowing this in filenames. I have a special voodoo doll just for that
> person, when I find them. As you can see, it causes all manner of odd
> problems, no matter what OS it's on. (My local LUG list is periodically
> hit with messages from people trying to overcome the problems attendant
> to this habit.)
> 
> Paul
> 
> -- 
> Paul M. Foster
> 


I do a lot of research into SEO, and the only evidence I've found that
comes close to this is where a website set up a page containing a
fictional keyword in the URL, then searched for that word a week or two
later.

I don't know how valid the 'SEO friendly URLs' are though. How often
have you searched for the answer to a question online and had the top
few results turn out to be forums with dynamic query-string URLs?!

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



--- End Message ---
--- Begin Message ---
On 8/10/2009 1:20 AM, Andrea Giammarchi wrote:

So far I stopped at the first line, the constructor, where I can spot with what I can 
read SQL injections "everywhere"

I hope here is a proper validation there, 'cause as is, sounds truly dangerous, 
since you are not using bindParams or other PDO related techniques to avoid 
input problems.

About the rest I kinda agree with the proper model controller, rather than just 
a reader.

Regards

To: [email protected]
Date: Wed, 7 Oct 2009 17:34:35 +1100
From: [email protected]
Subject: [PHP] Insult my code!

Hi there,

I'm in the process of trying to wrap my head around MVC, and as part of
that, I'm attempting to implement a super-tiny MVC framework.

I've created some mockups of how the framework might be used based
around a very simple 'bank', but I'm trying to get some feedback before
I go and implement it, to make sure I'm actually on the right track.

Any thoughts would be much appreciated!

Model - http://www.pastebin.cz/23595
Controller - http://www.pastebin.cz/23597
View - http://www.pastebin.cz/23598
Template - http://www.pastebin.cz/23599

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

                                        
_________________________________________________________________
Windows Live: Friends get your Flickr, Yelp, and Digg updates when they e-mail 
you.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_3:092010

The linked code was supposed to be more of a mockup than anything, with the functions a bit of filler to try and show what I'm trying to do.

With regard to the SQL injection, I try not to make the problems with my code quite so blatant. :-)
--- End Message ---
--- Begin Message ---
On 8/10/2009 5:18 PM, Mert Oztekin wrote:
Hi Paul,

As I agree some of your thoughts, I want to add my opinion also.
Yes the code should work. That is why we earn Money. If it doesnt work, then we are on 
fire. But things like OOP or MVC weren't invented for a better running code. They are 
invented so the codes will going to be much more clean, readable, reusable, maintainable. 
"Running codes" is not enough.

Eric asked about how his MVC structure looks. And we are trying to help what we know 
about MVC. He didn't asked if the code is fine for running. So giving an answer "The 
real key is, does it work, and can it be maintained" is not enough and not really 
helpful to him on MVC concept. If you need just a running and maintainable project, you 
don't need to use MVC (MVC is not all about that). We are not criticizing his code(the 
code is really fine(except injection problem :-) ) and very readable)


Eric,

As Martin said, All the business logic should be in Model. Controller should not tell a 
model "Save it to this database, select it from this table, use this 
db_adapter" etc. A controller is like a maestro of the system. It askes the model to 
play piano loud. But it wont say which key of piano, the model should touch.

I suggest you to read this online book about Zend Framework and MVC. Its really 
really very helpful to understand the concept. Also example codes are very 
clean and good.
http://www.survivethedeepend.com/zendframeworkbook/en/1.0


Take Care,

Mert
(sorry for my english)

Thanks for the link, it looks like an interesting read. Hopefully it will help me understand MVC better and hence allow me to improve my code design.
--- End Message ---
--- Begin Message ---
On 8/10/2009 4:28 PM, Paul M. wrote:
Hey guys, does anyone have a good link for an article where php4
popularity trends are examined? The best way for me to know php4 % and
php5 %. I appreciate any good suggestions.

Here's a pretty graph comparing PHP version usage and time: http://www.nexen.net/images/stories/phpversion/200810/evolution.milieu.png

Source (French): http://www.nexen.net/chiffres_cles/phpversion/

--- End Message ---
--- Begin Message ---
Eric Bauman wrote:
On 8/10/2009 4:28 PM, Paul M. wrote:
Hey guys, does anyone have a good link for an article where php4
popularity trends are examined? The best way for me to know php4 % and
php5 %. I appreciate any good suggestions.

Here's a pretty graph comparing PHP version usage and time: http://www.nexen.net/images/stories/phpversion/200810/evolution.milieu.png

Source (French): http://www.nexen.net/chiffres_cles/phpversion/

This research is done on October 2008. Does anyone has newer research?
And thanks Eric!

--- End Message ---
--- Begin Message ---
Hi everybody!


I want to get some tips about how avoid a attack of Denial of service.  May
be somebody can about your experience with Php o some configuration of
apache, o other software that help in these case.


Thanks in advance.


-- 
Gerardo Benitez

--- End Message ---
--- Begin Message ---
Not sure what exactly you are looking for.

Anyways, some common practice are request for API key, username / password
tokens before providing access to a service.

Thanks,

Gaurav Kumar


On Thu, Oct 8, 2009 at 7:06 PM, Gerardo Benitez <[email protected]>wrote:

> Hi everybody!
>
>
> I want to get some tips about how avoid a attack of Denial of service.  May
> be somebody can about your experience with Php o some configuration of
> apache, o other software that help in these case.
>
>
> Thanks in advance.
>
>
> --
> Gerardo Benitez
>

--- End Message ---
--- Begin Message ---
On Thu, 2009-10-08 at 19:40 +0530, Gaurav Kumar wrote:

> Not sure what exactly you are looking for.
> 
> Anyways, some common practice are request for API key, username / password
> tokens before providing access to a service.
> 
> Thanks,
> 
> Gaurav Kumar
> 
> 
> On Thu, Oct 8, 2009 at 7:06 PM, Gerardo Benitez 
> <[email protected]>wrote:
> 
> > Hi everybody!
> >
> >
> > I want to get some tips about how avoid a attack of Denial of service.  May
> > be somebody can about your experience with Php o some configuration of
> > apache, o other software that help in these case.
> >
> >
> > Thanks in advance.
> >
> >
> > --
> > Gerardo Benitez
> >


If you are using Apache there are a bunch of different DoS modules that
you can use:

http://www.google.co.uk/search?q=apache
+dos&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a

Also, if you are in full control of the server, you may be able to
configure firewalls for this sort of thing.

It gets more complex when you're attacked with a DDoS (Distributed
Denial of Service) as there's no real hard-and-fast way to prevent them,
as they could genuinely be legitimate requests to your server and not
attacks. As a distributed attack comes from many sources, you can't
reliably differentiate the valid requests from the malicious ones.

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



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

I've knocked up a quick RSS feed on my site. It works fine in Fx 2 & 3,
in Opera it throws an error "unexpected end of file" but allows the feed
to be added anyway, and Chrome just says there's an XML error, and gives
the second from last line as the one containing the error.

I tried adding a newline to the end of the file, but that just makes the
error message report the next line. Any ideas where I'm going wrong? The
file is using utf-8 character encoding.

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



--- End Message ---
--- Begin Message ---
Can you show the generated XML?

Jonathan

On Thu, Oct 8, 2009 at 3:45 PM, Ashley Sheridan
<[email protected]> wrote:
> Hi guys,
>
> I've knocked up a quick RSS feed on my site. It works fine in Fx 2 & 3,
> in Opera it throws an error "unexpected end of file" but allows the feed
> to be added anyway, and Chrome just says there's an XML error, and gives
> the second from last line as the one containing the error.
>
> I tried adding a newline to the end of the file, but that just makes the
> error message report the next line. Any ideas where I'm going wrong? The
> file is using utf-8 character encoding.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>

--- End Message ---
--- Begin Message ---
On Thu, 2009-10-08 at 15:54 -0300, Jonathan Tapicer wrote:

> Can you show the generated XML?
> 
> Jonathan
> 
> On Thu, Oct 8, 2009 at 3:45 PM, Ashley Sheridan
> <[email protected]> wrote:
> > Hi guys,
> >
> > I've knocked up a quick RSS feed on my site. It works fine in Fx 2 & 3,
> > in Opera it throws an error "unexpected end of file" but allows the feed
> > to be added anyway, and Chrome just says there's an XML error, and gives
> > the second from last line as the one containing the error.
> >
> > I tried adding a newline to the end of the file, but that just makes the
> > error message report the next line. Any ideas where I'm going wrong? The
> > file is using utf-8 character encoding.
> >
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> >
> >
> >
> 

Nevermind, I was having a "moment"! I'd forgotten to close the final
tag, as I mistook the root <rss> tag for an XML declaration instead! I
am a little surprised that Fx allowed it to validate correctly though!

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



--- End Message ---
--- Begin Message ---
Ashley Sheridan wrote:
> On Thu, 2009-10-08 at 15:54 -0300, Jonathan Tapicer wrote:
> 
>> Can you show the generated XML?
>>
>> Jonathan
>>
>> On Thu, Oct 8, 2009 at 3:45 PM, Ashley Sheridan
>> <[email protected]> wrote:
>>> Hi guys,
>>>
>>> I've knocked up a quick RSS feed on my site. It works fine in Fx 2 & 3,
>>> in Opera it throws an error "unexpected end of file" but allows the feed
>>> to be added anyway, and Chrome just says there's an XML error, and gives
>>> the second from last line as the one containing the error.
>>>
>>> I tried adding a newline to the end of the file, but that just makes the
>>> error message report the next line. Any ideas where I'm going wrong? The
>>> file is using utf-8 character encoding.
>>>
>>> Thanks,
>>> Ash
>>> http://www.ashleysheridan.co.uk
>>>
>>>
>>>
> 
> Nevermind, I was having a "moment"! I'd forgotten to close the final
> tag, as I mistook the root <rss> tag for an XML declaration instead! I
> am a little surprised that Fx allowed it to validate correctly though!
> 
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
> 
> 
> 

Well, don't forget, Fx will correct SGML and HTML that is missing tags.

I think Fx would rather simply accept the incorrect format, correct it (since it
wasn't a fatal error), and finally display what it figures you /intended/ to
send it.

I hate it when software tries to assume what I meant to say...  :-(

--- End Message ---
--- Begin Message ---
On Thu, 2009-10-08 at 12:50 -0700, Jim Lucas wrote:

> Ashley Sheridan wrote:
> > On Thu, 2009-10-08 at 15:54 -0300, Jonathan Tapicer wrote:
> > 
> >> Can you show the generated XML?
> >>
> >> Jonathan
> >>
> >> On Thu, Oct 8, 2009 at 3:45 PM, Ashley Sheridan
> >> <[email protected]> wrote:
> >>> Hi guys,
> >>>
> >>> I've knocked up a quick RSS feed on my site. It works fine in Fx 2 & 3,
> >>> in Opera it throws an error "unexpected end of file" but allows the feed
> >>> to be added anyway, and Chrome just says there's an XML error, and gives
> >>> the second from last line as the one containing the error.
> >>>
> >>> I tried adding a newline to the end of the file, but that just makes the
> >>> error message report the next line. Any ideas where I'm going wrong? The
> >>> file is using utf-8 character encoding.
> >>>
> >>> Thanks,
> >>> Ash
> >>> http://www.ashleysheridan.co.uk
> >>>
> >>>
> >>>
> > 
> > Nevermind, I was having a "moment"! I'd forgotten to close the final
> > tag, as I mistook the root <rss> tag for an XML declaration instead! I
> > am a little surprised that Fx allowed it to validate correctly though!
> > 
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> > 
> > 
> > 
> 
> Well, don't forget, Fx will correct SGML and HTML that is missing tags.
> 
> I think Fx would rather simply accept the incorrect format, correct it (since 
> it
> wasn't a fatal error), and finally display what it figures you /intended/ to
> send it.
> 
> I hate it when software tries to assume what I meant to say...  :-(
> 


I'm just used to it letting me know if I was trying to view malformed
XML. It must be a special case for RSS as it recognises the format as
being special!

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



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

I'm grabbing all records from a table using:

$records = $stmt->fetchAll(PDO::FETCH_OBJ);
return $records;


In order to display the values we can do:


foreach ($records as $record)
{                       
                echo $record->id;
                echo $record->name;
}


However, I'd like to grab, also, the *column names*.

I've tried:

foreach ($records as $column=>$value)
{
        echo "$column is $value\n";
}

But I get:
"Catchable fatal error: Object of class stdClass could not be converted to
string"



Can I have your help on how can I properly get the column values?

Regards,
Márcio


--- End Message ---
--- Begin Message ---
I feel like a total newb asking this, but I'm just having a brain fart or
something...

I'm writing a page where I can either get back a list of items:

        Array {
          [1233] => "apple",
          [6342] => "apricot",
          [2345] => "banana",
          ...
        }

where the user then refines it by choosing one single item and a single
element array is returned like this:

        Array {
          [8575] => "peach",
        }

How can I get this $item so I can print it like so:

        echo "The ID is $id and the name is $name";

Normally with an array of items, I do a:

        foreach ($item as $id => $name) echo...

But that seems overkill for this scenario.

The rub is that I don't know the "id", so I can't use $item[0], and I also
don't have something like $item['name'] to use either.

There's got to be an easy way to extract those.  

        list($id, $name) = $operator;

Felt like it would work for a minute (wishful thinking).


(I'm too embarrased to even sign my name on this one)


--- End Message ---

Reply via email to