SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    Pragmatic Programmer halfasleeps's Avatar
    Join Date
    Feb 2006
    Location
    Altoona, PA. USA
    Posts
    1,945
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    whats the best way to get GET vars from the refering page?

    I want to show a category banner on the product page, for the category you found the product from. Each product can be found in several categories so I want to use the $_SERVER[’HTTP_REFERER’] and get the category ID from it, to determine which category it came from and show the correct banner. The other thing is, I am using mod_rewrite to make the urls pretty so they dont really look like mypage.php?category=5 but more like some/category/5

    Any advice?

    Thanks!
    Altoona Design
    Freelance Flex developer for hire.
    ActionScript Programmer with 8 Years Experience.

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,508
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Don't use referer for that. Send the category in the query string, or put it in a session variable.

  3. #3
    Pragmatic Programmer halfasleeps's Avatar
    Join Date
    Feb 2006
    Location
    Altoona, PA. USA
    Posts
    1,945
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    Don't use referer for that. Send the category in the query string, or put it in a session variable.
    Session var, good idea, maybe Ill make the category page set the session, the product page read it and remove it, and every other page just remove it. that way if you don't travel directly from the category page to the product page it wont count it.

    Thanks.
    Altoona Design
    Freelance Flex developer for hire.
    ActionScript Programmer with 8 Years Experience.

  4. #4
    SitePoint Evangelist simshaun's Avatar
    Join Date
    Apr 2008
    Location
    North Carolina
    Posts
    438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As a rule of thumb, never rely on HTTP_REFERER. Its not "trustworthy" and is completely optional. The majority of proxies will spoof it and set it to the website being visited. Also, browsers don't have to send it (I know mine doesn't.)

    I agree with guido that you should use a session instead.

  5. #5
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Using session for this is a bad idea. You rely on people following a specific path of events, for your site to function properly, which was never the intent of the web. If people bookmark a page, the session won't be alive anymore, when they come back. And if they open multiple pages (in different tabs, for example), the session-variable will get mixed up between them.

    Send a query-string (GET) parameter in the URL instead.

  6. #6
    Pragmatic Programmer halfasleeps's Avatar
    Join Date
    Feb 2006
    Location
    Altoona, PA. USA
    Posts
    1,945
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kyberfabrikken View Post
    Using session for this is a bad idea. You rely on people following a specific path of events, for your site to function properly, which was never the intent of the web. If people bookmark a page, the session won't be alive anymore, when they come back. And if they open multiple pages (in different tabs, for example), the session-variable will get mixed up between them.

    Send a query-string (GET) parameter in the URL instead.

    Thanks
    Altoona Design
    Freelance Flex developer for hire.
    ActionScript Programmer with 8 Years Experience.

  7. #7
    SitePoint Evangelist simshaun's Avatar
    Join Date
    Apr 2008
    Location
    North Carolina
    Posts
    438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What happens if you unassociate the product from that category?

    Example:
    /products/graphic-design/photoshop/
    /products/multimedia-design/photoshop/

    ..Unassociate photoshop from multimedia-design, and the bookmark is no longer valid...

    Be careful in your planning, and know how you are going to handle situations such as that.
    Are you going to give them a 404, give them a list of categories Photoshop is under, or just let it be and show the multimedia banner anyway?

  8. #8
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Keep in mind sessions don't work too well for this type of stuff when your users open a second browser window.

    For example, user loads product page but gets a slow load, so clicks refresh. Now they won't see any banner because the product page unset the session var.

    Also, user browses to category A page. Opens second window and goes to category B. Then uses the first window(on cat A) to click to a product. They will see Cat B banner. not A.

    Maybe this isn't a big deal if they see the wrong banner, or no banner at all sometimes. It certainly will be uncommon. But be aware it will happen, and make sure it's not going to confuse them.

  9. #9
    Pragmatic Programmer halfasleeps's Avatar
    Join Date
    Feb 2006
    Location
    Altoona, PA. USA
    Posts
    1,945
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You guys have a lot of good points.

    I kinda don't like the query string ides because I think that will have negative effects on SEO if the url is different for the page depending on where you access it from (not positive if this effects SEO or not?).

    Maybe I should set the banner based off of something pertaining to the product, like the product brand; and then always make the banner for that brand, and link to the brand category.

    At least this way it will always be the same, except for items that are generic and don't have a name brand, errr.
    Altoona Design
    Freelance Flex developer for hire.
    ActionScript Programmer with 8 Years Experience.

  10. #10
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by halfasleeps View Post
    I kinda don't like the query string ides because I think that will have negative effects on SEO if the url is different for the page depending on where you access it from (not positive if this effects SEO or not?).
    Possibly. SEO is a bit like black magic; Nobody really knows how things works, so a lot of assumptions are made. I wouldn't let it take too much precendence If your URL's are meaningful, then that should matter more, and will eventually benefit your SEO.

    Quote Originally Posted by halfasleeps View Post
    Maybe I should set the banner based off of something pertaining to the product, like the product brand; and then always make the banner for that brand, and link to the brand category.
    That sounds like a good idea to me.


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
  •