Submit Your Article Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > PHP

Reply
 
LinkBack Thread Tools
Old May 30th, 2007, 03:44 PM   #1
New Member
 

Join Date: May 2007
Location: United Kindom, London and the South East
Age: 19
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 Bradster is on a distinguished road
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:
    <?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?
Bradster is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 31st, 2007, 01:56 AM   #2
Reputable Member
 

Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 293
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 grahame is a jewel in the rough grahame is a jewel in the rough grahame is a jewel in the rough
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
grahame is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 31st, 2007, 04:18 AM   #3
New Member
 

Join Date: May 2007
Location: United Kindom, London and the South East
Age: 19
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 Bradster is on a distinguished road
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.
Bradster is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks

Tags
infinite , loop , problem , website


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 2 February 15th, 2008 07:07 AM
The Loop (Again) Blake121 Full Website Reviews 16 September 7th, 2007 09:57 AM
The Loop V2 Blake121 Full Website Reviews 8 May 15th, 2007 05:37 AM
The Loop Blake121 Full Website Reviews 5 May 1st, 2007 10:25 AM
Loop??? tazek0 Classic ASP 0 January 27th, 2006 03:38 AM


Search Engine Optimization by vBSEO 3.2.0 RC8