PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 19th, 2005, 10:37 PM
Souliebaby Souliebaby is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 67 Souliebaby User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 2 h 22 m 42 sec
Reputation Power: 14
$get and include help

I'm sure this is really simple, but I'm trying to set my site to include a php file with text etc.. So when I go to "index.php?aj=main" I'd like it to show my main.php file in the table.. if that makes sense..

I'm using this code:

PHP Code:
<?php 
    $aj 
$GET['aj'];    
    include (
'"php/'.$aj.'.php"');
?>


and this is the error I'm getting

Warning: main("php/.php") [function.main]: failed to open stream: No such file or directory in /home/souliejc/public_html/test.php on line 60

Warning: main() [function.include]: Failed opening '"php/.php"' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php:/home/souliejc/public_html/') in /home/souliejc/public_html/test.php on line 60
main text goes here

Any ideas?

Reply With Quote
  #2  
Old June 20th, 2005, 07:25 AM
Laban Laban is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 40 Laban User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 15 m 32 sec
Reputation Power: 14
I would have used "switch"

The link:
<a href="?whatever=whatever1">

The just use the switch cmd where u like to include your php file:

PHP Code:
switch($_GET['whatever']) {

case 
'whatever1':
include(
"whatever_file1.php");
break;

case 
'whatever2':
include(
"whatever_file2.php");
break;

default:
include(
"whaever_default.php");
break;



As you probably understand...the link above will include whatever_file1.php where you place the switch code....
Comments on this post
ChiefWigs1982 agrees!

Reply With Quote
  #3  
Old June 20th, 2005, 05:11 PM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 785 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 17
This code snippet should give you more information when things go wrong. Keep in mind, this is a quickie and I have not run/tested this at all. Let me know if you have further problems:

PHP Code:
<?php
    
// document root
    
define('INC_DIR'$_SERVER['DOCUMENT_ROOT'].'/php');

    
$aj '';
    if (isset(
$GET['aj'])) {
      
$aj $GET['aj'];
    }

    if (empty(
$aj)) {
      
trigger_error('Page not specified'E_USER_ERROR);
    }

    
$thefile realpath(INC_DIR.'/'.$aj.'.php');

    if (
file_exists($thefile)) {
      include 
$thefile;
    } else {
      
// this would be a good place for a trigger_error call
      // or just do nothing and continue with the script
    
}
?>
Comments on this post
MadCowDzz agrees: Solid solution! I like.
__________________
__________________________________________________ _
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
Are You Listed...? | DigitallySmooth Inc.

Reply With Quote
  #4  
Old June 21st, 2005, 09:58 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,886 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 19 m 35 sec
Reputation Power: 18
I think the easy answer to the original question is the fact that he's missing an underscore... $_GET['aj']

it wouldn't be considered safe to include stuff based on query string variables.
in which case, I think the better solution is Laban's solution...

laidbak's is a pretty solid solution... definately not the first one I would have come up with, but I like it a lot

Reply With Quote
  #5  
Old June 27th, 2005, 01:46 AM
Souliebaby Souliebaby is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 67 Souliebaby User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 2 h 22 m 42 sec
Reputation Power: 14
Thanks for your help! I had a play with the coding and got it working ok

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > $get and include help


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap