content switching issue

Discussion in 'PHP' started by dzdrazil, May 7, 2008.

  1. #1
    I'm having an odd issue. I'm using wampserver2.0 and have vhost set up. all worked well testing on localhost; once i opened up the port and tried it over the LAN, i noticed a curious issue.
    Here's the code that i'm using:
    <?php
    $pass = array('p1','p2','p3','p4','p5','p6');
    	if (in_array($_GET['id'], $pass)) {
    			include ($_SERVER['DOCUMENT_ROOT'] . '/inc/' . $_GET['id'] . '.php'); 
    		} 
    		elseif (!isset($_GET['id'])) {
    			include ($_SERVER['DOCUMENT_ROOT'] . '/inc/p1.php'); 
    		}
    		else {
    					header("HTTP/1.0 404 Not Found");
    					include ($_SERVER['DOCUMENT_ROOT'] . '/inc/error.php');
    		}
    ?>
    Code (markup):
    where the array is used to set a class elsewhere in the page.

    Since I'm building and testing the website on my desktop, I can't view it from the same computer with this code. I get the error

    Warning: include(C:/wamp/www/inc/p1.php) [function.include]: failed to open stream: No such file or directory in C:\wamp\www\sigmapiminnesota\pledge1.php on line 38

    now, if i were to change the include line from /inc to sigmapiminnesota/inc , it would work fine on this computer... but the rest of the people on the network would get the same error message as above, except the directory would read
    Warning: (C:/wamp/www/sigmapiminnesota/sigmapiminnesota/inc/p1.php) instead.

    I don't have a live URL yet as the domain name isn't up yet, so I hope i included enough of the code above.

    Basically, is this a wampserver2.0 issue, a vhost issue, both, or code issue? all of the above? i'm a bit lost, i'm afraid.
     
    dzdrazil, May 7, 2008 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    i think its a wamp2.0, sometimes ive got this problem when i open my wamp through LAN css wouldnt work..
    i just dont know how to do it.. but when i deployed it into my host it works perfectly fine together when i run it into my pc..

    maybe the higher ranks here have an idea.. zce engineers we need a light here ^^,
     
    bartolay13, May 7, 2008 IP
  3. dzdrazil

    dzdrazil Peon

    Messages:
    64
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    at first i thought only part of the css file was getting across, but then i realized it was an IE problem with classes. hopefully it's not a wamp problem as that makes things incredibly inconvenient, since WAMP is practically meant to run vhost anyway (at least that's how the guides are written)
     
    dzdrazil, May 7, 2008 IP
  4. LogicFlux

    LogicFlux Peon

    Messages:
    2,925
    Likes Received:
    102
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Did you set the DocumentRoot in your virtual host setup?
     
    LogicFlux, May 7, 2008 IP
  5. dzdrazil

    dzdrazil Peon

    Messages:
    64
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    yup. if you're on my LAN, typing in the Ip for my computer brings up index.php inside the domain folder. going to the page with the code above and the folder name is added into the line- so localhost/sigmapiminnesota/inc/pp?id=p1.php shows up in the address bar, and displays properly. but when I try to see it from the computer it's being hosted on (testing different code or whatever) the above line is also displayed in the address bar, but instead of p1.php being loaded into the content area, i get the Warning: ... (c:/wamp/www/inc/p1.php)

    Is there a way to do something like SERVER_ROOT instead of DOCUMENT_ROOT in the include line? i feel like that would force both computers to look in the same directory... but i'm new enough to php that i don't even know if that's valid at all.

    EDIT: another question... can i use joomla for this sort of thing? i'd hate to take up the extra space, but if it would work better than this, i might just give up.
     
    dzdrazil, May 8, 2008 IP
  6. LogicFlux

    LogicFlux Peon

    Messages:
    2,925
    Likes Received:
    102
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You could just set the path manually in your script as a constant or something. Like at the top of the script or in a php file that gets included everywhere do something like this.

    
    
    define('MY_DOCUMENT_ROOT', 'C:/wamp/www/sigmapiminnesota/');
    
    PHP:
    
    
    include (MY_DOCUMENT_ROOT . '/inc/' . $_GET['id'] . '.php');
    
    PHP:
     
    LogicFlux, May 8, 2008 IP
  7. dzdrazil

    dzdrazil Peon

    Messages:
    64
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    i'm pleased to report that that works. you're a lifesaver! now if only i could figure out why my nav menu looks different on IE than FF, but that's a story for another day. Thanks for your time!
     
    dzdrazil, May 8, 2008 IP
  8. LogicFlux

    LogicFlux Peon

    Messages:
    2,925
    Likes Received:
    102
    Best Answers:
    0
    Trophy Points:
    0
    #8
    This is just a bandaid but it'll work I guess. :) I'd still be willing to bet that you could fix the problem in httpd.conf but I'm not as proficient with it as I should be.
     
    LogicFlux, May 8, 2008 IP
  9. dzdrazil

    dzdrazil Peon

    Messages:
    64
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Well, DocumentRoot in httpd.conf is set at c:/wamp/www/ but wouldn't changing that defeat the purpose of setting up the vhost stuff? I don't really plan on radically changing the structure of the site anymore so i dont think i'm getting myself into *too* much trouble here ;)
    ah well.

    good news! fixed the nav menu problems in both ie7 *and* ie6! woo! ... now to figure out a multi-field searchable database!
     
    dzdrazil, May 9, 2008 IP