should i use $_SERVER['REQUEST_URI'] ?
Moderator: General Moderators
-
original89
- Forum Newbie
- Posts: 22
- Joined: Wed Nov 17, 2004 8:25 am
should i use $_SERVER['REQUEST_URI'] ?
Hi
I am currently using
if ($_SERVER['REQUEST_URI'] == "/thingy_browse.html")
to generate meta tags and descriptions on the fly that are related to the contents of this page but i would like to be able to create them for more specific results. As with most php things i pass some variables in the search string eg.
/thingy_browse.html?type=candles&clour= red
how is possible to target only the type and the colour and pass these results to the page, so whenever someone does a search on candles, i could have a bt of text that says.
''You searched on candles and we have lots of candles to choose from here.''
I know i could create a if ($_SERVER['REQUEST_URI'] for every combination but this would take forever, i already have a meta_tag.php page that is 5000 lines long and its becoming to big to handle.
Is there a way i could read in the possible variables i use in the searches and echo them onto the page and use them in the meta tags?.
many thanks for your suggestions etc...
I am currently using
if ($_SERVER['REQUEST_URI'] == "/thingy_browse.html")
to generate meta tags and descriptions on the fly that are related to the contents of this page but i would like to be able to create them for more specific results. As with most php things i pass some variables in the search string eg.
/thingy_browse.html?type=candles&clour= red
how is possible to target only the type and the colour and pass these results to the page, so whenever someone does a search on candles, i could have a bt of text that says.
''You searched on candles and we have lots of candles to choose from here.''
I know i could create a if ($_SERVER['REQUEST_URI'] for every combination but this would take forever, i already have a meta_tag.php page that is 5000 lines long and its becoming to big to handle.
Is there a way i could read in the possible variables i use in the searches and echo them onto the page and use them in the meta tags?.
many thanks for your suggestions etc...
Last edited by original89 on Mon Feb 27, 2006 2:43 pm, edited 2 times in total.
hmm i'm not really clear on what you want to do here
but maybe something like this?
but maybe something like this?
Code: Select all
echo $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
-
original89
- Forum Newbie
- Posts: 22
- Joined: Wed Nov 17, 2004 8:25 am
hi
thanks for that reply well im not too sure what it is im asking for because im not too sure either..
i think you might be on the right lines though but i think i might have a problem using php_self as i re-write my php pages into .html which is why i have been using $_SERVER['REQUEST_URI']
what i really want is to be able to do is include the text from the query string in the page somewhere to help my SEO a bit, and not rely on having to write a script that interprets all the combinations of a dynamic page..so if my query string is
?type-candles&colour=red
then i could have a bit of text that says,,
'''youve found the best page in the world for buying red candles.''
but in another case it could be
?type-candles&colour=gold
''youve found the best page in the world for buying gold candles.''
or maybe the string might be just
?type-candles
''youve found the best page in the world for buying candles.''
i just wondered if there was a way i could set the text just for the search elements (is this what $_SERVER['QUERY_STRING']; does) rather than writing a massive if statement, which is already at 5000 lines..
does that make more sense? im sorry im a bit of a newbie, you can probably tell..
thanks v m
thanks for that reply well im not too sure what it is im asking for because im not too sure either..
i think you might be on the right lines though but i think i might have a problem using php_self as i re-write my php pages into .html which is why i have been using $_SERVER['REQUEST_URI']
what i really want is to be able to do is include the text from the query string in the page somewhere to help my SEO a bit, and not rely on having to write a script that interprets all the combinations of a dynamic page..so if my query string is
?type-candles&colour=red
then i could have a bit of text that says,,
'''youve found the best page in the world for buying red candles.''
but in another case it could be
?type-candles&colour=gold
''youve found the best page in the world for buying gold candles.''
or maybe the string might be just
?type-candles
''youve found the best page in the world for buying candles.''
i just wondered if there was a way i could set the text just for the search elements (is this what $_SERVER['QUERY_STRING']; does) rather than writing a massive if statement, which is already at 5000 lines..
does that make more sense? im sorry im a bit of a newbie, you can probably tell..
thanks v m
-
original89
- Forum Newbie
- Posts: 22
- Joined: Wed Nov 17, 2004 8:25 am
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
$_SERVER['QUERY_STRING'] will show you the entire string after the '?' in the URI. If you echo that you will see something like...
type=candles&color=red
To get the values for each var in the query string, use $_GET (you could use $_REQUEST, but that is not as secure as $_GET, in my opinion).
type=candles&color=red
To get the values for each var in the query string, use $_GET (you could use $_REQUEST, but that is not as secure as $_GET, in my opinion).
Code: Select all
if ( isset($_GET) )
{
$type = '';
$color = '';
if ( isset($_GET['type']) )
{
$type = $_GET['type'];
if ( isset($_GET['color']) )
{
$color = $_GET['color'];
}
}
echo "You have selected $color $type.<br />";
}-
original89
- Forum Newbie
- Posts: 22
- Joined: Wed Nov 17, 2004 8:25 am
hi this seems to have done the trick
thanks very much..
although i have one query string that just doesnt want to work.
in the url its like this
type%5B%5D=cone
and also
but neither work only when i manually change the url from my posted form to
type[]=cone
will it work..
whats goign on, why is that one variable doing this and where does it get the [] from??
thanks for the help Everah and scrotaye, ive been stuck on this for a while, good job someone invented forums...
thanks very much..
although i have one query string that just doesnt want to work.
in the url its like this
type%5B%5D=cone
Code: Select all
if ( isset($_GET['type%5B%5D']) )
{
$type= $_GET['type%5B%5D'];
}Code: Select all
if ( isset($_GET['type[]']) )
{
$type= $_GET['type[]'];
}but neither work only when i manually change the url from my posted form to
type[]=cone
will it work..
whats goign on, why is that one variable doing this and where does it get the [] from??
thanks for the help Everah and scrotaye, ive been stuck on this for a while, good job someone invented forums...
-
original89
- Forum Newbie
- Posts: 22
- Joined: Wed Nov 17, 2004 8:25 am
-
original89
- Forum Newbie
- Posts: 22
- Joined: Wed Nov 17, 2004 8:25 am
sorted it, i just declare it as the first array
and it works..
thanks me..
Code: Select all
if ( isset($_GET['type']) )
{
$aac_type = $_GET['type'][0];
}
}thanks me..
-
original89
- Forum Newbie
- Posts: 22
- Joined: Wed Nov 17, 2004 8:25 am
okay, its working but i have a little problem
when i have a search result where not all of the $_GET variables appear in the url then the echo doesnt work at all! they both have to be returned to make this work, otherwise nothing shows....
any ideas?
how do you get the echo to work even if just one $_GET has been returned..
when i have a search result where not all of the $_GET variables appear in the url then the echo doesnt work at all! they both have to be returned to make this work, otherwise nothing shows....
any ideas?
Code: Select all
if ( isset($_GET) )
{
$type = '';
$color = '';
if ( isset($_GET['type']) )
{
$type = $_GET['type'];
if ( isset($_GET['color']) )
{
$color = $_GET['color'];
}
}
echo "You have selected $color $type.<br />";
}- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
How about
Or:
Code: Select all
if ( isset($_GET) )
{
$type = '';
$color = '';
if ( isset($_GET['type']) )
{
$type = $_GET['type'];
if ( isset($_GET['color']) )
{
$color = $_GET['color'];
}
}
echo "You have selected $color $type.<br />";
} else {
echo "You have not selected anything.<br />";
}Code: Select all
$type = 'nothing';
$color = '';
if ( isset($_GET) )
{
if ( isset($_GET['type']) )
{
$type = $_GET['type'];
if ( isset($_GET['color']) )
{
$color = $_GET['color'];
}
}
}
echo "You have selected $color $type.<br />";(#10850)
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
EDIT: Sorry, screwed up the echo message part in the original...
Try something like this...
Try something like this...
Code: Select all
<?php
$type = '';
$color = '';
$message = 'You have made no selections yet.<br />';
if ( isset($_GET) )
{
if ( isset($_GET['type']) )
{
$type = $_GET['type'];
}
if ( isset($_GET['color']) )
{
$color = $_GET['color'];
}
if ( $type || $color )
{
$message = "You have selected $color $type.<br />";
}
}
echo $message;
?>