Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

In need of 'how to' for $_SERVER['QUERY_STRING']

Status
Not open for further replies.

iggitme

IS-IT--Management
Sep 13, 2006
47
US
I need to determine if $_SERVER['QUERY_STRING'] contains ?p . (the question mark followed by a p) and if it does NOT, serve a set of javascript files, if it does, do NOT serve those javascript files inside a hardcoded header.

example

if ?p is not present include these
Code:
	<script type="text/javascript"  src="<? bloginfo('template_url')?>/css/jquery.js"></script>		
	<script type="text/javascript"  src="<? bloginfo('template_url')?>/css/interface.js"></script>

if ?p is present do not include them...

any help would be very appreciated

thank you
 
If its in the query string use the $_GET superglobal and test for it:

Code:
if(isset($_GET['[red]p[/red]'])){
do_something();
}

else{
do_something_else();
}




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
the QUERY_STRING value doesn't actually hold the ? (at least not in my experience). So you really want to see if the first 2 chars are p=

to determine if one string is inside another you would use the strpos function.

something like this:
Code:
if (strpos($_SERVER['QUERY_STRING'],'p=') === false) 
{
  $scriptBlock = '<script type="text/javascript"  src="' . bloginfo('template_url') . '/css/jquery.js"></script><script type="text/javascript"  src="' . bloginfo('template_url') . '/css/interface.js"></script>';
} else {
  $scriptBlock = '';
}
echo $scriptBlock;

I'm using === in the comparison because if the p= was in the QUERY_STRING it would be at the first character which would return 0, which would also == false, but obviously 0 doesn't === false.

So, that should do it for you.


Travis Hawkins
 
i would instead use wordpress's built in methods to enqueue scripts and stylesheets. it's always better to use the proper API's rather than use 'hacks' from within templates.

if you want WP help feel free to post in the wordpress forum on this site.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top