Infinite Loop

This is a discussion on "Infinite Loop" within the PHP Forum section. This forum, and the thread "Infinite Loop are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old May 30th, 2007, 19:44
Junior Member
Join Date: May 2007
Location: United Kindom, London and the South East
Age: 17
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Bradster
Infinite Loop

I recently got a formal warning by my web hosting provider for having bad code and crashing one of thier shared servers :S.

This is why;
Code: Select all
    <?php
    $url = '';
    if (!empty($_GET['category'])) {
        $url .= $_GET['category'] . '/';
    }
    if (!empty($_GET['home'])) {
        $url .= $_GET['home'] . '.php';
    }
    include $url;
    ?>
Anybody know how you actually create a dynamic php include?
Reply With Quote

  #2 (permalink)  
Old May 31st, 2007, 05:56
Reputable Member
Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 293
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Infinite Loop

That is not (inless you refer it to itself) an infinite loop ... and in any case, there's a timeout on such things in PHP so they should not crash the server. It IS a script that is open to injection attacks as malicious site visitors could fillin your "category" box with something starting "http://" or "/" and pick up code from other accounts on the same shared server, or other servers.

You should add code to check your "category" and "home" inputs to ensure that they only contain letters or digits, or validate them against a fixed list of whats's allowed, or something like that.

To get you started
if (! eregi('[a-z0-9]]+$',$_GET['category'])) { .....
will check if the category input is just letters and digits
Reply With Quote
  #3 (permalink)  
Old May 31st, 2007, 08:18
Junior Member
Join Date: May 2007
Location: United Kindom, London and the South East
Age: 17
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Bradster
Re: Infinite Loop

Thanks for that Grahame,
Yeah I relised that that piece of code wasnt the one that crashed it.

I have another problem, the links now work fine except that I get an error when you open up the index.php file itself, and you must click on a link to not get an error, I cant set the inital page.
Reply With Quote
Reply

Tags
infinite, loop, problem, website

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Do a while loop once? Jack Franklin PHP Forum 2 Feb 15th, 2008 11:07
The Loop (Again) Blake121 Free Web Site Critique 16 Sep 7th, 2007 13:57
The Loop V2 Blake121 Free Web Site Critique 8 May 15th, 2007 09:37
The Loop Blake121 Free Web Site Critique 5 May 1st, 2007 14:25
Loop??? tazek0 Classic ASP 0 Jan 27th, 2006 07:38


All times are GMT. The time now is 05:41.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43