SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 31
  1. #1
    SitePoint Enthusiast mahmoud's Avatar
    Join Date
    May 2001
    Location
    Egypt
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using "/" and $HTTP_GET_VARS problem

    I am using "/" instead of "?"
    and $HTTP_GET_VARS does not count the $var ..

    My "/" instead of "?" code:
    PHP Code:
    $url_array explode("/",$PATH_INFO);
    for(
    $i=1;$i<count($url_array);$i++) {
    $data[$url_array[$i]] = $url_array[++$i];
    }
    $extract = @extract($data); 
    An example of a code that doesn't work :
    PHP Code:
    if (($legal == copyright) && ( sizeof ($HTTP_GET_VARS) == 1)) {echo "<b>Copyright</b>";} 
    - This code should bring <b>copyright</b> .. but it does not .. except if I removed the $HTTP_GET_VARS or made it equal = 0

    How can fix this?

    Thanks
    Last edited by mahmoud; Aug 15, 2001 at 14:09.
    Mahmoud

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you use a method like page.php/var1/1/var2/2

    Your $HTTP_GET_VARS array will be empty since that is looking for a format like page.php?var1=1&var2=2

    To fix it take out anything that refers to $HTTP_GET_VARS when using this method.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Enthusiast mahmoud's Avatar
    Join Date
    May 2001
    Location
    Egypt
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    like:
    PHP Code:
    if (isset($legal)) {
    $HTTP_GET_VARS $HTTP_GET_VARS." + 1";

    ??

    but isn't there a much better way?

    To make it work as it works with the "?" and "&". Something to add in the first part of the code :
    PHP Code:
    $url_array explode("/",$PATH_INFO);
    for(
    $i=1;$i<count($url_array);$i++) {
    $data[$url_array[$i]] = $url_array[++$i];
    }
    $extract = @extract($data); 
    Better than adding
    PHP Code:
     $HTTP_GET_VARS $HTTP_GET_VARS." + 1"
    for every $var entered through the GET
    Mahmoud

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry dude, I didn't understand a word of what you just said.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Enthusiast mahmoud's Avatar
    Join Date
    May 2001
    Location
    Egypt
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there a better code than
    PHP Code:
    $HTTP_GET_VARS $HTTP_GET_VARS." + 1"
    I can write

    A code that I can write inside the for(
    PHP Code:
    for($i=1;$i<count($url_array);$i++) {
    $data[$url_array[$i]] = $url_array[++$i];
    // HERE


    Mahmoud

  6. #6
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is this supposed to do?

    PHP Code:
    $HTTP_GET_VARS $HTTP_GET_VARS." + 1"
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  7. #7
    SitePoint Enthusiast mahmoud's Avatar
    Join Date
    May 2001
    Location
    Egypt
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    when I add :
    PHP Code:
    if (isset($legal)) {
    $HTTP_GET_VARS $HTTP_GET_VARS." + 1";

    it lets index.php/legal/copyright works correct
    PHP Code:
    if (($legal == copyright) && ( sizeof ($HTTP_GET_VARS) == 1)) {echo "<b>Copyright</b>";} 
    Mahmoud

  8. #8
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The only reason that works is because you are assigning a value to $HTTP_GET_VARS. Like I said before when using the method of / vs ? $HTTP_GET_VARS array will be empty so why are you even using it?
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  9. #9
    SitePoint Enthusiast mahmoud's Avatar
    Join Date
    May 2001
    Location
    Egypt
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh .. that's code is wrong ..
    Sorry ..
    To fix it take out anything that refers to $HTTP_GET_VARS when using this method.
    Anyway How can I refer to $HTTP_GET_VARS when using this method ?
    Mahmoud

  10. #10
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One more time, $HTTP_GET_VARS is empty when using this method since it is looking for a query string like ?var1=1&var2=2

    YOU CANNOT USE $HTTP_GET_VARS USING THIS METHOD.

    Is there a specific reason why you want to?
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  11. #11
    SitePoint Enthusiast mahmoud's Avatar
    Join Date
    May 2001
    Location
    Egypt
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by mahmoud
    oh .. that's code is wrong ..
    Sorry ..

    Anyway How can I refer to $HTTP_GET_VARS when using this method ?
    I want to use it so I can control the nubmer of vars
    so I can have

    index.php/home/whatever/id/anything
    and also
    index.php/home/whatever
    ..etc
    making different jobs

    because if I wrote : index.php/home/whatever/id/anything and without the $HTTP_GET_VARS

    both the actions in home/whatever and home/whatever/id/anything and also if I have job done using index.php/id/anything only they all be done ..
    Mahmoud

  12. #12
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is it just me, or is your cryptic writing style losing me here? What do you mean by controlling the number of vars. You would control the number of vars the same way as you would with a tradtional query string approach.


    Here there are two vars
    index.php?var1=1&var2=2


    Here there are two vars also
    index.php/var1/1/var2/2
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  13. #13
    SitePoint Enthusiast mahmoud's Avatar
    Join Date
    May 2001
    Location
    Egypt
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry, I will explain more :
    PHP Code:
    if(($home) && ( sizeof ($HTTP_GET_VARS) == 1)) {
        if(!@include(
    "include/".$home.".abk")) { whatever }
    }
    elseif((
    $home) && ($page) && ( sizeof ($HTTP_GET_VARS) == 2)) {
        if(!@include(
    "include/".$home."/".$page.".abk")) { whatever }

    in the above code
    index.php?home=whatever
    is doing a different thing than:
    index.php?home=whatever&page=anything

    - If I am not using $HTTP_GET_VARS and wrote
    index.php?home=whatever&page=anything
    it will include both $home.abk and $home/$page.abk

    That is what I want to prevent while using "/"

    Is there way to do it while using "/" (without using $HTTP_GET_VARS) ?
    Last edited by mahmoud; Aug 15, 2001 at 14:01.
    Mahmoud

  14. #14
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is this what you are after?


    PHP Code:
    if($home && !$page) {
        if (!@include(
    "include/".$home.".abk")) { whatever }
    }
    elseif (
    $home && $page) {
        if(!@include(
    "include/".$home."/".$page.".abk")) { whatever }

    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  15. #15
    SitePoint Enthusiast mahmoud's Avatar
    Join Date
    May 2001
    Location
    Egypt
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah
    Thanks

    but still you only prevented $page

    Is it possible to prevent any $var without writing && $! for each ?

    .. && !$whatever ?
    Mahmoud

  16. #16
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What do you mean by prevent? You an't prevent anyone from adding all the vars in the world on to the end of a url. YOu could comment out the extract() line and you would have an array just like that of $HTTP_GET_VARS; however you would need to access them as $data[page] adn $data[home]


    PHP Code:
    $url_array explode("/",$PATH_INFO);
    for(
    $i=1;$i<count($url_array);$i++) {
    $data[$url_array[$i]] = $url_array[++$i];
    }
    extract($data); 
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  17. #17
    SitePoint Enthusiast mahmoud's Avatar
    Join Date
    May 2001
    Location
    Egypt
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I do not mean prevent the people

    for this code (the one you wrote)
    PHP Code:
    if($home && !$page) {
        if (!@include(
    "include/".$home.".abk")) { whatever }

    this code won't take action if
    index.php/home/whatever/page/2
    but will still take action if
    index.php/home/whatever/page22222/2
    and will still take action if
    index.php/home/whatever/ANYANYANYTHING/2

    I want it to only take action if $home && !$NOTHING
    only if : index.php/home/whatever

    Is this possible?
    Mahmoud

  18. #18
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Using that url_array split code you had in your first post. If you had a url like

    PHP Code:
    index.php/home/whatever/ANYANYANYTHING/
    You would end up with two variables

    PHP Code:
    $home // holds the value of whatever

    and

    $ANYANYANYTHING //holds the value 0f 2 
    Following me so far?

    Now by doing

    PHP Code:
    if($home && !$page) {
        if (!@include(
    "include/".$home.".abk")) { whatever }
    }
    elseif (
    $home && $page) {
        if(!@include(
    "include/".$home."/".$page.".abk")) { whatever }

    The first one is valid since there is a $home but no $page the second one is not valid since there is only a $home.

    I assume you are building these links in your site somewhere, so you can contro lwhich variables go on the end of the url?

    Am I missing something here?


    PHP Code:
    $url_array explode("/",$PATH_INFO);
    for(
    $i=1;$i<count($url_array);$i++) {
    $data[$url_array[$i]] = $url_array[++$i];
    }
    $count count($data);
    extract($data); 
    Now $count will hold the number of variables passed to the script.
    Last edited by freddydoesphp; Aug 15, 2001 at 17:23.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  19. #19
    SitePoint Enthusiast mahmoud's Avatar
    Join Date
    May 2001
    Location
    Egypt
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks alot ...
    U done a great job trying to reach what I really want

    $count is really what I wanted ..

    but you posted
    PHP Code:
    extract($data); 
    and the one I posted at first was
    PHP Code:
    $extract = @extract($data); 
    I do not see a difference between them, but which one is better?
    Mahmoud

  20. #20
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well you don't need to assign the result to a variable since you are simply extracting the contents of an array, and the little @ sign is going to keep you from seeing an error when it happens. Thats the difference.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  21. #21
    SitePoint Enthusiast mahmoud's Avatar
    Join Date
    May 2001
    Location
    Egypt
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks ..
    Mahmoud

  22. #22
    SitePoint Enthusiast mahmoud's Avatar
    Join Date
    May 2001
    Location
    Egypt
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got this error using the extract($data);

    Warning: extract() expects first argument to be an array in on line 19
    Mahmoud

  23. #23
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  24. #24
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes thats correct if $data contains nothing then that error will appear just make it.


    if(count($data) > 0) {
    extract($data);
    }
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  25. #25
    SitePoint Enthusiast mahmoud's Avatar
    Join Date
    May 2001
    Location
    Egypt
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks ..
    but another problem came up

    $count = array(); not working in "/" system

    so index.php/home/whatever/count/1 will take the same action as /home/whatever

    what do you think is the solution?

    so something like:
    index.php/DOCUMENT_ROOT/anything

    to make my $DOCUMENT_ROOT /anything
    Last edited by mahmoud; Aug 15, 2001 at 18:25.
    Mahmoud


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
  •