Page 1 of 1
should i use $_SERVER['REQUEST_URI'] ?
Posted: Mon Feb 27, 2006 8:50 am
by original89
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...
Posted: Mon Feb 27, 2006 9:06 am
by s.dot
hmm i'm not really clear on what you want to do here
but maybe something like this?
Code: Select all
echo $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
Posted: Mon Feb 27, 2006 9:19 am
by original89
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
Posted: Mon Feb 27, 2006 9:34 am
by original89
okay ive pointed myself in the right direction would i just include this in the search results page.?
<?php echo $_SERVER['QUERY_STRING']; ?>
and my text would be
Youve arrived the the best place in the world to buy <? echo $_REQUEST['colour']; ?> <? echo $_REQUEST['type']; ?>
Posted: Mon Feb 27, 2006 10:06 am
by RobertGonzalez
$_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).
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 />";
}
Posted: Mon Feb 27, 2006 11:02 am
by original89
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
Code: Select all
if ( isset($_GET['type%5B%5D']) )
{
$type= $_GET['type%5B%5D'];
}
and also
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...
Posted: Mon Feb 27, 2006 1:54 pm
by original89
do i need to decode it or something the [] one will not get written and it returns Array
or is there anything i can do to stop the [] appearing in the first place it comes froma drop down box on a form from posted from a previous page..
many thanks.

Posted: Mon Feb 27, 2006 2:06 pm
by MinDFreeZ
the %5b is [ and %5d is ]
yea.. (edit) you've already got that figured out.

Posted: Mon Feb 27, 2006 2:16 pm
by original89
sorted it, i just declare it as the first array
Code: Select all
if ( isset($_GET['type']) )
{
$aac_type = $_GET['type'][0];
}
}
and it works..
thanks me..

Posted: Mon Feb 27, 2006 2:49 pm
by original89
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?
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 />";
}
how do you get the echo to work even if just one $_GET has been returned..
Posted: Mon Feb 27, 2006 3:05 pm
by Christopher
How about
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 />";
}
Or:
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 />";
Posted: Mon Feb 27, 2006 4:23 pm
by RobertGonzalez
EDIT: Sorry, screwed up the echo message part in the original...
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;
?>