SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Wizard mPeror's Avatar
    Join Date
    Mar 2005
    Location
    Saudi Arabia
    Posts
    1,725
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question GET variables and links

    I ran into this serious problem while developing a site.

    say i use 3 GET variables in my URL when people navigate through my site's pages : 1) section 2) postsperpage 3) page

    and almost each section has multiple pages of links with page numbers to click on (PHP paging). Also , the 'section' and the 'postsperpage' variable might be both set or not. Or maybe just one of them is set.

    Now how do i form the links for pages numbers according to which variables are set? For example , the same link could be :
    Code:
    http://.../script.php?page=1
    or
    Code:
    http://.../script.php?section=1&page=1
    or
    Code:
    http://.../script.php?section&=1&postsperpage=10
    and so on


    how shall i do it?


    Thanks for your time

  2. #2
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Several "if (isset($_GET['var1'])){" type things?

    Make sure also, to validate your get input.

  3. #3
    SitePoint Enthusiast subduck's Avatar
    Join Date
    Sep 2003
    Location
    USA
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dylannn
    Make sure also, to validate your get input.
    That's very important, check to make sure if the variables are set and then check if they are valid.

  4. #4
    SitePoint Wizard mPeror's Avatar
    Join Date
    Mar 2005
    Location
    Saudi Arabia
    Posts
    1,725
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so shall i do something like this? :

    PHP Code:
    <?php
    $link 
    "script.php?";

    if(isset(
    $_GET['section']))
    {
       
    // validate then ..
       
    $link .= 'section=' $_GET['section'] . '&';
    }

    if(isset(
    $_GET['postperpage']))
    {
       
    // validate then ..
       
    $link .= 'postperpage=' $_GET['postperpage'] . '&';
    }

    echo 
    '<a href="'$link .'" >click me</a>';

    ?>
    or is there something better than using many IF statements?

  5. #5
    SitePoint Guru mwolfe's Avatar
    Join Date
    Mar 2005
    Posts
    912
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well its not good to clutter a users system with cookies but sometimes it helped simplify the logic on my site quite a bit to store the results per page in a cookie so i wouldnt have to keep appending it in the querystring..

    as to your previous post.. it looks fine.. you could also do a switch i believe for that but i'm not sure how to run a switch on a get array, or something like that..

  6. #6
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What you'll need to do is create an array for each get variable with the values you want to accept.

    So like
    PHP Code:
    $sections = array('section1''section2''section3');
    if (isset(
    $_GET['sections']))
    {
    if (
    in_array(&_GET['sections'], $sections))
    {
    // do stuff
    }
    else
    {
    die(
    'Hacking attempt!');
    }} 
    Something along those lines.

  7. #7
    SitePoint Wizard mPeror's Avatar
    Join Date
    Mar 2005
    Location
    Saudi Arabia
    Posts
    1,725
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok that cleared things up. Thanks alot guys

  8. #8
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No problem.


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
  •