...

View Full Version : manually setting $_GET array



Blaher
02-23-2008, 11:07 PM
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
$location=$_SERVER["REQUEST_URI"];
if (strchr($location, '?'))
{
$getdat=substr($location, strpos($location, '?')+1, strlen($location));
$location=substr($location, 0, strpos($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.

Inigoesdr
02-24-2008, 01:47 PM
Why are you parsing the URL when you can just use the $_GET array?

Blaher
02-24-2008, 03:14 PM
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.

Inigoesdr
02-24-2008, 03:50 PM
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:
var_dump($_GET);

Blaher
02-24-2008, 04:46 PM
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.

Inigoesdr
02-24-2008, 05:10 PM
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:

$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.

Blaher
02-24-2008, 05:18 PM
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?

_Aerospace_Eng_
02-24-2008, 05:23 PM
Are you using mod_rewrite at all?

oesxyl
02-24-2008, 05:27 PM
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.



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

Blaher
02-24-2008, 05:40 PM
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.
There's only ONE accessible file in my whole site and that's /index.php.
I have my 404 error page set up to go to /index.php
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.
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.
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.

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.

oesxyl
02-24-2008, 05:51 PM
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.
There's only ONE accessible file in my whole site and that's /index.php.
I have my 404 error page set up to go to /index.php

that is redirection! I guess this way you cut off the query string, so no $_GET available.



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.
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

Blaher
02-24-2008, 06:07 PM
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
$location=$_SERVER["REQUEST_URI"];
if (strchr($location, '?'))
{
$getdat=substr($location, strpos($location, '?')+1, strlen($location));
$location=substr($location, 0, strpos($location, '?'));
}
if (isset($getdat))
{
while (strchr($getdat, '&'))
{
$prefdat=substr($getdat, 0, strpos($getdat, '&'));
$getdat=substr($getdat, strpos($getdat, '&')+1, strlen($getdat));
$_GET[substr($prefdat, 0, strpos($getdat, '='))]=substr($prefdat, strpos($getdat, '=')+1, strlen($getdat));
}
$_GET[substr($getdat, 0, strpos($getdat, '='))]=substr($getdat, strpos($getdat, '=')+1, strlen($getdat));
}
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum