SitePoint Sponsor

User Tag List

Results 1 to 12 of 12

Thread: $_GET question

Hybrid View

  1. #1
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $_GET question

    hi!
    if i have....
    <a href="file.php?a=1&b=2&c=3">
    and my page link is
    <a href="file.php?a=1&b=2">
    how to come to this page with first link and separate the &c=3, couse i need it for another trigger...
    practiclay i want one link for 2 things...
    is that possible?
    anyy suggestion?
    thanx in advance!!!

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    anyone???

  3. #3
    Non-Member jmweb's Avatar
    Join Date
    Jan 2004
    Location
    Canada
    Posts
    1,481
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try setting up 2 if statements

  4. #4
    SitePoint Zealot Koobi's Avatar
    Join Date
    Nov 2003
    Location
    Sri Lanka
    Posts
    156
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Will you know exactly how many GET arguments you will have? If you do, then you can use a foreach loop to split the GET arguments by key and value and manipulate it like that.

    example:
    PHP Code:
    foreach($_GET as $key => $value)
    {
         echo 
    'Key: ' $key '<br />';
         echo 
    'Value: ' $value '<hr />';

    That would print your GET index and the corresponding values

  5. #5
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanx a lot i solved.....
    the problem was that i was tired
    take a look at this $_GET game
    PHP Code:
    function News_console() {
    $page = $_GET["page"];
    $act = $_GET["act"];
    $_SESSION["p"] = $page;
    $_SESSION["a"] = $act;
    $p = $_SESSION["p"];
    $a = $_SESSION["a"];

    if($_GET["co"] == 'open') {
    $_SESSION["open"] = 1;


    if($_GET["co"] == 'close') {
    $_SESSION["open"] = 0;


    if($_GET["ord"] == 'category') {
    $_SESSION["cat"] = 1;
    $_SESSION["user"] = 0;
    $_SESSION["date"] = 0;


    if($_GET["c"] == 'user') {
    $_SESSION["cat"] = 0;
    $_SESSION["user"] = 1;
    $_SESSION["date"] = 0;


    if($_GET["ord"] == 'date' OR 
    $_GET["co"] == 'close') {
    $_SESSION["cat"] = 0;
    $_SESSION["user"] = 0;
    $_SESSION["date"] = 1;


    if($_GET["open"] == '1') {
    $_SESSION["o"] = 1;
    $o = $_SESSION["o"];
    } else {
    $_SESSION["o"] = 0;
    }
    ?>
    <table width="480" border="0" cellspacing="0" cellpadding="0" style="border:1px solid #cccccc;">
    <tr><td class="consoleTitle" style="background-color:#eeeeee;padding-left:5px;"><?php
    if($_SESSION["open"] OR 
    $_GET["page"] == $page && 
    $_GET["act"] == $act && 
    $_GET["d"] == 'cons' OR 
    !empty(
    $_POST["goUser"]) OR 
    !empty(
    $_POST["goCat"]) OR 
    $_GET["ord"] == 'category' OR 
    $_GET["c"] == 'user' OR 
    $_GET["ord"] == 'date') {
    ?><a href="news.php?page=<?php echo $p?>&act=<?php echo $act?>&open=<?php echo $o?>&co=close">Hide News Console...</a></td><?php
    } else {
    ?><a href="news.php?d=cons&page=<?php echo $p?>&act=<?php echo $a?>&co=open">Show News Console...</a></td><?php
    }

    if(
    $_SESSION["open"] OR 
    $_GET["d"] == 'cons' OR 
    !empty(
    $_POST["goUser"]) OR 
    !empty(
    $_POST["goCat"]) OR 
    $_GET["ord"] == 'date' OR 
    $_GET["ord"] == 'category') {
    ?><td  class="consoleTitle" style="border-left:1px solid #cccccc;padding-left:5px;">
    Order by <?php

    if($_GET["d"] == 'cons' OR 
    $_GET["ord"] == 'category' OR 
    $_GET["c"] == 'user' OR 
    !empty(
    $_POST["goUser"]) OR 
    !empty(
    $_POST["goCat"]) OR
    !
    $_SESSION["date"] && 
    $_GET["act"] == $act && 
    $_GET["page"] == $page && 
    $_GET["open"] == '1' OR
    $_SESSION["cat"] OR
    $_SESSION["user"]) {
    ?><a href="news.php?ord=date&page=<?php echo $p?>&act=<?php echo $a?>">DATE</a>,&nbsp;<?php 
    } else if($_GET["page"] == $page) {
    ?><a href="#" style="color:red; text-decoration:underline;">DATE</a>,&nbsp;<?php 
    }

    if(
    $_GET["ord"] == 'date' OR 
    $_GET["c"] == 'user' OR 
    $_GET["d"] == 'cons' && 
    $_GET["ord"] != 'category' OR 
    !empty(
    $_POST["goUser"]) OR 
    !
    $_SESSION["cat"] &&
    $_GET["act"] == $act && 
    $_GET["page"] == $page && 
    $_GET["open"] == '1' OR
    $_SESSION["user"] &&
    $_GET["page"] == $page OR
    $_SESSION["date"]) {
    ?><a href="news.php?d=cons&ord=category&page=<?php echo $p?>&act=<?php echo $a?>">CATEGORY</a>,&nbsp;<?php
    } else {
    ?><a href="#" style="color:red; text-decoration:underline;">CATEGORY</a>,&nbsp;<?php
    }

    if(
    $_GET["ord"] == 'category' OR 
    $_GET["ord"] == 'date' OR 
    $_GET["d"] == 'cons' && 
    $_GET["c"] != 'user' OR 
    !empty(
    $_POST["goCat"]) OR 
    !
    $_SESSION["user"] &&
    $_GET["act"] == $act && 
    $_GET["page"] == $page && 
    $_GET["open"] == '1' OR
    $_SESSION["cat"] &&
    $_GET["page"] == $page OR
    $_SESSION["date"]) {
    ?><a href="news.php?d=cons&c=user&page=<?php echo $p?>&act=<?php echo $a?>">USER</a> ...</td></tr><?php
    } else {
    ?><a href="#" style="color:red; text-decoration:underline;">USER</a> ...</td></tr><?php
    }

    if(
    $_GET["d"] == 'cons' && 
    $_GET["c"] == 'user' OR 
    !empty(
    $_POST["goUser"]) OR 
    $_GET["act"] == $act && 
    $_GET["page"] == $page && 
    $_SESSION["user"]) { 
    ?><tr><td colspan="2" class="consoleFoot" valign="top" style="padding-left:5px;border-top:1px solid #cccccc;">
    <form name="form1" method="post" action="news.php" style="margin:0px;"><fieldset style="padding:5px;border:1px solid #cccccc;"><legend>Choose user</legend>
    <select  class="consoleForm" name="select" size="3" multiple>
    <option selected>1</option><option>2</option><option>3</option><option>4</option><option>5</option><!-- test -->
    </select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input class="newsUserSubmit" type="submit" name="goUser" value="Go"></fieldset>
    </form><?php
    } else {
    echo 
    "";
    }

    if(
    $_GET["d"] == 'cons' && 
    $_GET["ord"] == 'category' OR 
    !empty(
    $_POST["goCat"]) OR 
    $_GET["act"] == $act && 
    $_GET["page"] == $page && 
    $_SESSION["cat"]) { 
    ?><tr><td colspan="2" class="consoleFoot" valign="top" style="padding-left:5px;border-top:1px solid #cccccc;">
    <form name="form1" method="post" action="news.php" style="margin:0px;"><fieldset style="padding:5px;border:1px solid #cccccc;"><legend>Choose category</legend>
    <select  class="consoleForm" name="select" size="3" multiple>
    <option selected>1</option><option>2</option><option>3</option><option>4</option><option>5</option><!-- test -->
    </select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input class="newsUserSubmit" type="submit" name="goCat" value="Go"></fieldset>
    </form><?php
    } else {
    echo 
    "";
    }

    } else {
    echo 
    "";
    }
    ?></td></tr></table><br>
    <?php
    }
    cheers

  6. #6
    Are You There? KDesigns's Avatar
    Join Date
    Oct 2003
    Location
    Your Monitor
    Posts
    1,147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Rather than using all of those if's you could probably clean up the code by slapping them in switch structures. I guess it's a matter of personal taste, I just think using switch() makes the code much cleaner to read.

    I used to be an if / elseif fan myself... of course I used to be a 'tables' pusher too!
    ChooseDaily.com - Follow on Twitter
    Top Resources for Web Designers and Developers Every Day!

  7. #7
    SitePoint Zealot Koobi's Avatar
    Join Date
    Nov 2003
    Location
    Sri Lanka
    Posts
    156
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by KDesigns
    Rather than using all of those if's you could probably clean up the code by slapping them in switch structures. I guess it's a matter of personal taste, I just think using switch() makes the code much cleaner to read.

    I used to be an if / elseif fan myself... of course I used to be a 'tables' pusher too!
    Yeah I have to agree that switches are better, especially because it's faster.

  8. #8
    SitePoint Zealot
    Join Date
    Oct 2004
    Location
    Sydney, Australia
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    koobi,

    instead of using

    PHP Code:
    foreach($_GET as $key => $value
    Try using this instead

    PHP Code:
    echo '<pre>';
    print_r($_GET); 

  9. #9
    SitePoint Zealot Koobi's Avatar
    Join Date
    Nov 2003
    Location
    Sri Lanka
    Posts
    156
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Bling
    koobi,

    instead of using

    PHP Code:
    foreach($_GET as $key => $value
    Try using this instead

    PHP Code:
    echo '<pre>';
     
    print_r($_GET); 
    Yeah I use that when I want to see what a variable contains, I also use var_dump() to view the types as well but you can't manipulate a string using print_r()



    reminder, I just quickly skimmed through your code...it's best that you first strip_tags() and then trim() any variables that can be manipulated by the user such as $_GET, $_POST (and $_REQUEST if you use that instead). Just don't ever trust user input.



    Example:
    PHP Code:
     if(empty($_GET) === FALSE)
     {
         foreach(
    $_GET as $key => $value)
         {
             
    $_GET[$key] = trim(strip_tags($value));
         }
     } 
    So if you entered a URL like index.php?page=<script>someScriptHere</script>

    After you run it through that snippet, $_GET['page'] would only contain 'someScriptHere' without the script tags.

  10. #10
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Philippines
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    I'm new with PHP. When do I use $_GET and $_POST and what is the difference between the two?

    Thank you in advance,

    JOzin

  11. #11
    Knowledge is key 2 progression Tryst's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Jozin - this thread has been solved, and what your trying to ask is something completely different.

    You need to ask you question in a new thread, that way people can see what your trying to ask.

    Thanks

    Tryst


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
  •