1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP troubles

Discussion in 'Black Hat SEO' started by theprovider777, Sep 27, 2007.

  1. theprovider777

    theprovider777 Registered Member

    Joined:
    Sep 3, 2007
    Messages:
    93
    Likes Received:
    7
    Occupation:
    To Provide and Serve.
    Location:
    Land of many provisions.
    Home Page:
    I'm not quite sure where to post this, but if anyone with some PHP knowledge could help me out, I'd appreciate it.

    I have mod_rewrite set to redirect in this manner:

    domain.com/page/action => domain.com/index.php?page=$1&action=$2

    I also added an extra rule to handle a request with no $action
    ie. domain.com/page => domain.com/index.php?page=$1
    (not sure if this was necessary..I've tried it both ways..)

    Now, whenever I try to request a $page without an $action, it appears that the variables aren't even set.

    To be clearer:

    <?php
    $page = $_GET['page'];
    $action = $_GET['action'];
    ?>

    When I access a page with both a page and an action, ie. domain.com/page/action/, everything works fine and both variables get the proper values. Without an action, the varibles are set as follows:

    $page is empty
    $action is index.php

    What I want is for $page to be set, and $action to be empty.

    I'm pulling my hair out over this. Can someone help me?
     
    • Thanks Thanks x 1
  2. theprovider777

    theprovider777 Registered Member

    Joined:
    Sep 3, 2007
    Messages:
    93
    Likes Received:
    7
    Occupation:
    To Provide and Serve.
    Location:
    Land of many provisions.
    Home Page:
    Woot! I figured it out. Sorry to bother you guys.

    Admins, you may delete this if you want.
     
  3. brittany46

    brittany46 Junior Member

    Joined:
    Oct 16, 2006
    Messages:
    145
    Likes Received:
    25
    Rather than delete, please share your fix. It may help others.
     
    • Thanks Thanks x 1
  4. theprovider777

    theprovider777 Registered Member

    Joined:
    Sep 3, 2007
    Messages:
    93
    Likes Received:
    7
    Occupation:
    To Provide and Serve.
    Location:
    Land of many provisions.
    Home Page:
    Good point. I had actually thought about that, then I got lazy. :eek:

    Originally, I had the following rewrite rules in my .htaccess:

    RewriteRule ^([^/]*)/$ /index.php?page=$1
    RewriteRule ^([^/]*)/([^/]*)/$ /index.php?page=$1&action=$2 [L]

    For some reason, it wouldn't work like that, but if I simply did them in descending order (2-1), it worked:

    RewriteRule ^([^/]*)/([^/]*)/$ /index.php?page=$1&action=$2
    RewriteRule ^([^/]*)/$ /index.php?page=$1 [L]

    I don't know enough about mod_rewrite to say WHY it's like this, but perhaps it will help someone. (Thanks for spurring me into action, brittany46 :p )

    PS. An admin might also think of renaming this to mod_rewrite troubles .. ?
     
  5. milligan

    milligan Junior Member

    Joined:
    Mar 19, 2007
    Messages:
    170
    Likes Received:
    63
    thanks theprovider777 for posting your solution. every little bit helps towards understanding this game.
     
  6. brittany46

    brittany46 Junior Member

    Joined:
    Oct 16, 2006
    Messages:
    145
    Likes Received:
    25
    Yes, Thank You. Rep added.