SitePoint Sponsor

User Tag List

Results 1 to 12 of 12

Thread: $_GET variable

  1. #1
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $_GET variable

    I'm trying to make a url for my site that looks like this:

    index.php?mod=[mod]&act=[act]&subact=[subact]

    I'm not sure how I can acieve this query string without using a form because I want the page to be autmaticallly generated.

    Does anyone have any ideas or codes that will help me achieve this?

    Thanks in Advance!

    PS: Sorry if I'm being vague! If anyone needs clarification, just ask about it here.

  2. #2
    hi galen's Avatar
    Join Date
    Jan 2006
    Location
    New Haven, CT
    Posts
    1,228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you dont need a form, just put that url in a link

  3. #3
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lets say I had the file:
    Code:
    /site/pages/add.php
    how could I turn that into:
    Code:
    index.php?mod=site&act=pages&subact=add
    Is this possible? Or do I have to use .htaccess?
    lore_lanu

  4. #4
    hi galen's Avatar
    Join Date
    Jan 2006
    Location
    New Haven, CT
    Posts
    1,228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    in index.php you could use subact in the url to include specific pages

  5. #5
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure what that really means...... could you give me an example?

  6. #6
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Can you explain a bit more on what exactly you're trying to accomplish?

  7. #7
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, its for a site I'm making. I have different categories, (eg. cat1, cat2, cat3) each with different pages (eg. page1, page2, page3).

    I wan the url of this site to have a query string at the end of it, stating the category (in this case "mod") and the page.

    I was hoping to set this up with includes. Have the header, sidebar, and footer included on everypage, and the main content is the actual page (page1.php, page2.php, page3.php).

    Hope this sheds some light on the situation! Please ask if you have any more questions.

  8. #8
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    And how do u know a particular file in a particular folder?

    /site/pages/add.php

    And where is this category/page relation mapped? In the db?

    is it like:

    /cat1/subcat/page.php ?

  9. #9
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That was just an idea I had. I was thinking maybe there was a code to take
    the subfolders and insert them into them into the url.

    Code:
    site/pages/add.php = index.php?mod=site&act=pages&subact=add
    I doubt, that is possible though... The trouble is, I'm sure there is a code out there does it, but I'm having trouble finding it.

    Any ideas?

  10. #10
    SitePoint Member
    Join Date
    Feb 2007
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Here is a little guideline that may help

    It is possible.

    Perhaps try something like:
    • use substr() to remove the extension
    • check for a leading slash and remove it if there is one
    • use explode() by the / character
    • write out the URL the way you want it used the exploded parts

  11. #11
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm relatively new to php. Could you show me what that would look like? I'm afraid I don't know how to use the explode function very well...

  12. #12
    hi galen's Avatar
    Join Date
    Jan 2006
    Location
    New Haven, CT
    Posts
    1,228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    im talking about something like this

    url: index.php?page=cat1

    PHP Code:
    $pages = array('cat1''cat2''cat3');
    if (
    in_array($_GET['page'], $pages))
        include(
    $_GET['page'] . '.php'); 


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •