[SOLVED] $_GET['ting'] Pages (Safely) With PHP

This is a discussion on "[SOLVED] $_GET['ting'] Pages (Safely) With PHP" within the PHP Forum section. This forum, and the thread "[SOLVED] $_GET['ting'] Pages (Safely) With PHP 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 Nov 4th, 2007, 14:12
AdRock's Avatar
SuperMember

SuperMember
Join Date: Jul 2006
Location: Devon, England
Posts: 565
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to AdRock
[SOLVED] $_GET['ting'] Pages (Safely) With PHP

Having some problems with this article

Quote:
[Sun Nov 04 15:10:56 2007] [error] PHP Parse error: syntax error, unexpected ')' in d:\\Apache\\htdocs\\test\\index.php on line 6
and this is the line in question
PHP: Select all

$page=(preg_match('/(\.\.|\/)/i',)?'home':$page); 

Any ideas?
Reply With Quote

  #2 (permalink)  
Old Nov 4th, 2007, 14:26
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: $_GET['ting'] Pages (Safely) With PHP

Maybe the following?
PHP: Select all


$page
=(preg_match('/(\.\.|\/)/i'),?'home':$page); 
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #3 (permalink)  
Old Nov 4th, 2007, 14:52
AdRock's Avatar
SuperMember

SuperMember
Join Date: Jul 2006
Location: Devon, England
Posts: 565
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to AdRock
Re: $_GET['ting'] Pages (Safely) With PHP

Nope...didn't work

Quote:
[Sun Nov 04 15:50:35 2007] [error] PHP Parse error: syntax error, unexpected ',' in d:\\Apache\\htdocs\\test\\index.php on line 6
what did work however is if i took the comma out it displayed the menu but didn't include the home page (i'm just working with the examples in the article)
Reply With Quote
  #4 (permalink)  
Old Nov 4th, 2007, 15:15
c010depunkk's Avatar
SuperMember

SuperMember
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to c010depunkk
Re: $_GET['ting'] Pages (Safely) With PHP

yep, there's an error there. sorry bout that

It should be:
PHP: Select all

$page=(preg_match('/(\.\.|\/)/i',$page)?'home':$page); 

Reply With Quote
  #5 (permalink)  
Old Nov 4th, 2007, 16:05
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: $_GET['ting'] Pages (Safely) With PHP

I'll change this in a minute guys.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #6 (permalink)  
Old Nov 4th, 2007, 16:29
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: $_GET['ting'] Pages (Safely) With PHP

Fixed! Shame on our tester
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #7 (permalink)  
Old Nov 5th, 2007, 12:34
AdRock's Avatar
SuperMember

SuperMember
Join Date: Jul 2006
Location: Devon, England
Posts: 565
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to AdRock
Re: $_GET['ting'] Pages (Safely) With PHP

Alex....you need to change that bit in the finished code also becuase that still reads the same
Reply With Quote
  #8 (permalink)  
Old Nov 5th, 2007, 15:21
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: $_GET['ting'] Pages (Safely) With PHP

Okay will now.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #9 (permalink)  
Old Nov 5th, 2007, 17:03
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: $_GET['ting'] Pages (Safely) With PHP

Fixed (I think).
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #10 (permalink)  
Old Nov 5th, 2007, 19:59
AdRock's Avatar
SuperMember

SuperMember
Join Date: Jul 2006
Location: Devon, England
Posts: 565
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to AdRock
Re: $_GET['ting'] Pages (Safely) With PHP

Still getting problems

Quote:
[Mon Nov 05 20:59:41 2007] [error] PHP Warning: main(./pageserror.php) [<a href='function.main'>function.main</a>]: failed to open stream: No such file or directory in d:\\Apache\\htdocs\\test\\index.php on line 15
[Mon Nov 05 20:59:41 2007] [error] PHP Warning: main() [<a href='function.include'>function.include</a>]: Failed opening './pageserror.php' for inclusion (include_path='.;d:\\php\\includes;D:\\php\\PEAR') in d:\\Apache\\htdocs\\test\\index.php on line 15
[Mon Nov 05 20:59:41 2007] [error] PHP Notice: Undefined variable: title in d:\\Apache\\htdocs\\test\\index.php on line 19
[Mon Nov 05 20:59:41 2007] [error] PHP Notice: Undefined variable: content in d:\\Apache\\htdocs\\test\\index.php on line 33
I noticed some of the code doesn't match futher up the page than further down the page in the finished bit
Reply With Quote
  #11 (permalink)  
Old Nov 6th, 2007, 05:28
c010depunkk's Avatar
SuperMember

SuperMember
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to c010depunkk
Re: $_GET['ting'] Pages (Safely) With PHP

I think you are missing a slash:
Code: Select all
./pageserror.php
should probably be this:
Code: Select all
./pages/error.php
Reply With Quote
  #12 (permalink)  
Old Nov 6th, 2007, 08:54
AdRock's Avatar
SuperMember

SuperMember
Join Date: Jul 2006
Location: Devon, England
Posts: 565
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to AdRock
Re: $_GET['ting'] Pages (Safely) With PHP

This is what I have

PHP: Select all

<?php
// check the $_GET['page'] variable
$page = ((isset($_GET['page']) && $_GET['page'] != '') ? $_GET['page'] : 'home');
//  prevent file browsing
$page=(preg_match('/(\.\.|\/)/i',$page)?'home':$page);
// replace illegal characters
$page preg_replace('/[^a-zA-Z0-9 \._-]/','',$page);
// check if the requested file exists
$page = (file_exists('./pages'.$page.'.php') ? $page 'error');
// and include the page
include('./pages'.$page.'.php');
?>
<html>
<head>
<title><?php echo($title); ?></title>
<body>
 <div class="menu">
  <ul>
   <li><a href="index.php?page=home">HOME</a></li>
   <li><a href="index.php?page=contact">CONTACT</a></li>
   <li><a href="index.php?page=links">LINKS</a></li>
   <li><a href="index.php?page=products">PRODUCTS</a></li>
  </ul>
 </div>
 <div class="content">
  <?php echo($content); ?>
 </div>
</body>
</html>
Reply With Quote
  #13 (permalink)  
Old Nov 6th, 2007, 09:08
c010depunkk's Avatar
SuperMember

SuperMember
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to c010depunkk
Re: $_GET['ting'] Pages (Safely) With PHP

Yep, you're missing a slash. Corrected:
PHP: Select all

<?php
// check the $_GET['page'] variable
$page = ((isset($_GET['page']) && $_GET['page'] != '') ? $_GET['page'] : 'home');
//  prevent file browsing
$page=(preg_match('/(\.\.|\/)/i',$page)?'home':$page);
// replace illegal characters
$page preg_replace('/[^a-zA-Z0-9 \._-]/','',$page);
// check if the requested file exists
$page = (file_exists('./pages'.$page.'.php') ? $page 'error');
// and include the page
include('./pages/'.$page.'.php');
?>
<html>
<head>
<title><?php echo($title); ?></title>
<body>
 <div class="menu">
  <ul>
   <li><a href="index.php?page=home">HOME</a></li>
   <li><a href="index.php?page=contact">CONTACT</a></li>
   <li><a href="index.php?page=links">LINKS</a></li>
   <li><a href="index.php?page=products">PRODUCTS</a></li>
  </ul>
 </div>
 <div class="content">
  <?php echo($content); ?>
 </div>
</body>
</html>
Reply With Quote
  #14 (permalink)  
Old Nov 6th, 2007, 09:59
AdRock's Avatar
SuperMember

SuperMember
Join Date: Jul 2006
Location: Devon, England
Posts: 565
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to AdRock
Re: $_GET['ting'] Pages (Safely) With PHP

Nearly working!!!!

I created an error page and now i get the menu listed but also the 404 error page instead of the home page.

I did the same example as in the article just for testing purposes.

I have a folder called pages with all the home, contact and 404 error page in so i don't know what the problem is
Reply With Quote
  #15 (permalink)  
Old Nov 6th, 2007, 11:45
c010depunkk's Avatar
SuperMember

SuperMember
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to c010depunkk
Re: $_GET['ting'] Pages (Safely) With PHP

hehe, Missed that error too. You also have to add a slash in the file_exists() function otherwise PHP won't find the page. Corrected again:
PHP: Select all

<?php
// check the $_GET['page'] variable
$page = ((isset($_GET['page']) && $_GET['page'] != '') ? $_GET['page'] : 'home');
//  prevent file browsing
$page=(preg_match('/(\.\.|\/)/i',$page)?'home':$page);
// replace illegal characters
$page preg_replace('/[^a-zA-Z0-9 \._-]/','',$page);
// check if the requested file exists
$page = (file_exists('./pages/'.$page.'.php') ? $page 'error');
// and include the page
include('./pages/'.$page.'.php');
?>
<html>
<head>
<title><?php echo($title); ?></title>
<body>
 <div class="menu">
  <ul>
   <li><a href="index.php?page=home">HOME</a></li>
   <li><a href="index.php?page=contact">CONTACT</a></li>
   <li><a href="index.php?page=links">LINKS</a></li>
   <li><a href="index.php?page=products">PRODUCTS</a></li>
  </ul>
 </div>
 <div class="content">
  <?php echo($content); ?>
 </div>
</body>
</html>
Reply With Quote
  #16 (permalink)  
Old Nov 6th, 2007, 13:18
AdRock's Avatar
SuperMember

SuperMember
Join Date: Jul 2006
Location: Devon, England
Posts: 565
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to AdRock
Re: $_GET['ting'] Pages (Safely) With PHP

Thanks Jan....works a treat now

Alex....you may want to change the code on the newsletter so it works correctly
Reply With Quote
Reply

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
[SOLVED] Browser versions to test pages in djeyewater Starting Out 4 Jan 21st, 2008 08:39
[SOLVED] Links from inside swf to html pages Posie Flash & Multimedia Forum 6 Jan 3rd, 2008 22:02
[SOLVED] Headings H1 &amp; 2 appear too big on my web pages? Oak Web Page Design 2 Dec 26th, 2007 00:11
[SOLVED] Custom Error Pages! mcdanielnc89 Web Page Design 18 Oct 14th, 2007 17:20
I don't _GET it! Donny Bahama PHP Forum 15 Jan 20th, 2007 19:47


All times are GMT. The time now is 02:16.


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