Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    Regular Coder
    Join Date
    Nov 2005
    Location
    North Canton, Ohio
    Posts
    118
    Thanks
    11
    Thanked 4 Times in 4 Posts

    manually setting $_GET array

    I'm in need of some help here. I need to manually set my $_GET array. If you want to know why, you can see the source of what I'm working on at http://blahertech.org/www.zip, but pretty much it's because my new template's content is all in the database and it works off the error page that will search for the correct content based on the uri. Since it's a error page or something I guess it's ignoring $_GET values, I'm not quiet sure why.

    Base off the following value of $getdat, I need to use it to set my $_GET values.
    PHP Code:
    <?php
        $location
    =$_SERVER["REQUEST_URI"];
        if (
    strchr($location'?'))
        {
            
    $getdat=substr($locationstrpos($location'?')+1strlen($location));
            
    $location=substr($location0strpos($location'?'));
        }
    ?>
    Now I could have only one $_GET value or maybe even up to 1,000(far-fetched) it has to be compatible with whatever is thrown at it.

    I'd think of a way myself how to do it, and it's probably a real easy snippet, but I've been working all day and I currently have a brain fart.
    I'd be thankful for anyone who is up to the task of showing me code on how to do this.
    Last edited by Blaher; 02-23-2008 at 10:10 PM. Reason: php tags instead of code tags

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Why are you parsing the URL when you can just use the $_GET array?

  • #3
    Regular Coder
    Join Date
    Nov 2005
    Location
    North Canton, Ohio
    Posts
    118
    Thanks
    11
    Thanked 4 Times in 4 Posts
    I just explained myself already of why it's not setting it, but I made a test page to show you.
    I added the page "/test" to the database and it'll var_dump($_GET) for you. Go ahead, try setting any $_GET value you want, nothing will show for some reason, it's an error page.

    http://blahertech.org/test/?page=home
    http://blahertech.org/test?something=cheese

    Try both of those or anything you want, nothing ever gets set in the $_GET var. This is why I need to set all of the $_GET values manually.
    Last edited by Blaher; 02-24-2008 at 03:44 PM.

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    The $_GET var has to be overwritten somewhere in your script, or you are using a version of PHP older than 4.1.0.
    var_dump($_GET[])
    You mean:
    PHP Code:
    var_dump($_GET); 

  • #5
    Regular Coder
    Join Date
    Nov 2005
    Location
    North Canton, Ohio
    Posts
    118
    Thanks
    11
    Thanked 4 Times in 4 Posts
    No, my host comes with Php 5. That's what I'm saying anyways, I know I can just set $_GET["page"]=2; manually, but I want to take the data I said above and make it set all the get values. As I said, it could be none, one or many. I guess I'll just have to make the snippet on my own today.

  • #6
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    My point is that you shouldn't need to. The arguments passed in the URL after the question mark are automatically populated into the $_GET array. So, the only reason for them not being there is that your script is overwriting the $_GET array before you try to use it.

    If what you want to do is take the existing $_GET array, possible modify the values, and generate a new query string to place in links you can use something like this:
    PHP Code:
    $temp = array();
    foreach(
    $_GET as $k => $v)
        
    $temp[] = $k '=' $v;
    $queryString implode('&'$temp); 
    Unless you're sending the data to another website it would probably be easier, and cleaner, to use the $_SESSION array instead.

  • #7
    Regular Coder
    Join Date
    Nov 2005
    Location
    North Canton, Ohio
    Posts
    118
    Thanks
    11
    Thanked 4 Times in 4 Posts
    Ok, I'll say it again. Go to http://blahertech.org/test . ALL of my pages are error pages that pull the content from a database. I'm not overwriting my $_GET variable anywhere, I'm not even touching it for now. But if you look, no matter what you send, the $_GET variable won't be passed because I'm guessing it's going to the error page.

    Do you understand what I'm saying now?

  • #8
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Are you using mod_rewrite at all?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #9
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Inigoesdr View Post
    My point is that you shouldn't need to. The arguments passed in the URL after the question mark are automatically populated into the $_GET array. So, the only reason for them not being there is that your script is overwriting the $_GET array before you try to use it.
    agreed with Inigoesdr.
    first of all, your page is a 404, that is not normal.

    Code:
    HTTP/1.1 404 Not Found
    Date: Sun, 24 Feb 2008 16:19:07 GMT
    Server: Apache/2.2.8 (Unix) mod_ssl/2.2.8 OpenSSL/0.9.8g DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635
    X-Powered-By: PHP/5.2.5
    Connection: close
    Content-Type: text/html; charset=iso-8859-1
    this is for the http://blahertech.org/test/?page=home

    in my opinion you must solve this before changing $_GET, because this affects more than that. Look into your server logs both access and error, enable loging for mod_rewrite and look inside.

    best regards

  • #10
    Regular Coder
    Join Date
    Nov 2005
    Location
    North Canton, Ohio
    Posts
    118
    Thanks
    11
    Thanked 4 Times in 4 Posts
    No, I've heard of mod_rewrite but I'm not using it.

    Ok, I'm going to tell you how my new template works for the last time.
    1. There's only ONE accessible file in my whole site and that's /index.php.
    2. I have my 404 error page set up to go to /index.php
    3. When you go to let's say http://blahertech.org/news?page=2, it's not found and goes to /index.php and keeps the uri intact.
    4. It chops off the uri past '?' and stores it in $getdat and what ever is before that is stored in $location which is what I use for the uri.
    5. My 404 error page looks for a match in the database of what the uri is.
    6. If there's a match it will display the content based on what's in the database.
    So yes, I told you I don't know how many times. ALL of the pages for this site are error pages. Nothing exist, it's just one error page pulling the content from a database. I'm making a easy to use CMS, this way the user doesn't have thousand of files laying around and every page will be edited through the DB.

    Now I'll explain again. My $_GET values arn't getting passed for the reason EVERYTHING is a 404 error page. That's why I need a way to manually set any $_GET values that are in the uri.

    Give me a moment and I'll put a updated source on http://blahertech.org/www.zip and I'll set up a DB account so you can see what's in the DB. That way you can understand what's going on.
    Last edited by Blaher; 02-24-2008 at 04:44 PM.

  • #11
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Blaher View Post
    No, I've heard of mod_rewrite but I'm not using it.
    what is below prove that you are using even you don't do it explicit.

    Ok, I'm going to tell you how my new template works for the last time.
    1. There's only ONE accessible file in my whole site and that's /index.php.
    2. I have my 404 error page set up to go to /index.php
    1. that is redirection! I guess this way you cut off the query string, so no $_GET available.

    2. When you go to let's say http://blahertech.org/news?page=2, it's not found and goes to /index.php and keeps the uri intact.
    3. It chops off the uri past '?' and stores it in $getdat and what ever is before that is stored in $location which is what I use for the uri.
    check the $getdat before change it in any way

  • My 404 error page looks for a match in the database of what the uri is.
  • If there's a match it will display the content based on what's in the database.
  • So yes, I told you I don't know how many times. ALL of the pages for this site are error pages. Nothing exist, it's just one error page pulling the content from a database. I'm making a easy to use CMS, this way the user doesn't have thousand of files laying around and every page will be edited through the DB.

    Now I'll explain again. My $_GET values arn't getting passed for the reason EVERYTHING is a 404 error page. That's why I need a way to manually set any $_GET values that are in the uri.
    sorry but this is a very improper way to use http. Any valid request to the server must return the proper result, if the page is valid a 200.
    This is not a funcy thing you can do what you want with it, the error code is used by server and user agents to comunicate.

    best regards

  • #12
    Regular Coder
    Join Date
    Nov 2005
    Location
    North Canton, Ohio
    Posts
    118
    Thanks
    11
    Thanked 4 Times in 4 Posts
    Ok, then if a match is found I'll just have it header("HTTP/1.0 200 OK"); other wise it'll set the content to /error and keep it 404. But that doesn't solve my problem yet. I need a way to set what's in $getdat (ie. "page=2&ie=sucks&css3=old") to be placed inside the $_GET incase the user puts a php script that needs to use the $_GET. I'm out of my brain fart now, and as soon as I finish something else and this isn't solved, I solve it and post it.

    EDIT: This is all I wanted
    PHP Code:
    <?php
        $location
    =$_SERVER["REQUEST_URI"];
        if (
    strchr($location'?'))
        {
            
    $getdat=substr($locationstrpos($location'?')+1strlen($location));
            
    $location=substr($location0strpos($location'?'));
        }
        if (isset(
    $getdat))
        {
            while (
    strchr($getdat'&'))
            {
                
    $prefdat=substr($getdat0strpos($getdat'&'));
                
    $getdat=substr($getdatstrpos($getdat'&')+1strlen($getdat));
                
    $_GET[substr($prefdat0strpos($getdat'='))]=substr($prefdatstrpos($getdat'=')+1strlen($getdat));
            }
            
    $_GET[substr($getdat0strpos($getdat'='))]=substr($getdatstrpos($getdat'=')+1strlen($getdat));
        }
    ?>
    Last edited by Blaher; 02-24-2008 at 05:59 PM.


  •  

    Posting Permissions

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