473,382 Members | 1,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Help rendering Javascript?

I'd like to execute javascript if I'm in a certain directory. I can't
figure out how to render the javascript script below. I always end up
with some type of parsing error. Any suggestions?

<?php
$url= $_SERVER['PHP_SELF'];
$isWPAdmin = strstr($url, "wp-admin");
if($isWPAdmin) {}
else {

<!-- Start of Code -->
<script type="text/javascript" language="javascript">
var sc_project=1000;
var sc_invisible=1;
var sc_partition=101;
var sc_security="1000";
</script>

<script type="text/javascript" language="javascript"
src="http://www.abc.com/counter/counter.js"></script><noscript><a
href="http://www.abc.com/" target="_blank"><img
src="http://11.abc.com/counter.php?sc_project=1000&amp;java=0&amp;securit y=1000&amp;
invisible=1" alt="hit counter" border="0"></a</noscript>
<!-- End of Code -->

}
?>

Thanks,
Brett

Nov 2 '06 #1
9 2577
Try This:
<?php
$url= $_SERVER['PHP_SELF'];
$isWPAdmin = strstr($url, "wp-admin");
if($isWPAdmin) {}
else {
?>
<!-- Start of Code -->
<script type="text/javascript" language="javascript">
var sc_project=1000;
var sc_invisible=1;
var sc_partition=101;
var sc_security="1000";
</script>

<script type="text/javascript" language="javascript"
src="http://www.abc.com/counter/counter.js"></script><noscript><a
href="http://www.abc.com/" target="_blank"><img
src="http://11.abc.com/counter.php?sc_project=1000&java=0&security...
invisible=1" alt="hit counter" border="0"></a</noscript>
<!-- End of Code -->
<?php
}
?>

On Nov 2, 7:04 pm, "brett" <acco...@cygen.comwrote:
I'd like to execute javascript if I'm in a certain directory. I can't
figure out how to render the javascript script below. I always end up
with some type of parsing error. Any suggestions?

<?php
$url= $_SERVER['PHP_SELF'];
$isWPAdmin = strstr($url, "wp-admin");
if($isWPAdmin) {}
else {

<!-- Start of Code -->
<script type="text/javascript" language="javascript">
var sc_project=1000;
var sc_invisible=1;
var sc_partition=101;
var sc_security="1000";
</script>

<script type="text/javascript" language="javascript"
src="http://www.abc.com/counter/counter.js"></script><noscript><a
href="http://www.abc.com/" target="_blank"><img
src="http://11.abc.com/counter.php?sc_project=1000&java=0&security...
invisible=1" alt="hit counter" border="0"></a</noscript>
<!-- End of Code -->

}?>

Thanks,
Brett
Nov 2 '06 #2
Excellent! Thanks.

Nov 2 '06 #3
That doesn't seem to work when the URL has a "?" in it:

/blog/?p=4&preview=true

I get up to "/blog/" and that's it. It seems the rest is cut off. I
suppose that is the query string part. Is there a way to include it so
I can also check for "preview=true"?

Thanks,
Brett

Nov 3 '06 #4


On Nov 3, 5:50 pm, "brett" <acco...@cygen.comwrote:
That doesn't seem to work when the URL has a "?" in it:

/blog/?p=4&preview=true

I get up to "/blog/" and that's it. It seems the rest is cut off. I
suppose that is the query string part. Is there a way to include it so
I can also check for "preview=true"?

Thanks,
Brett
http://php.net/parse_url
http://php.net/parse_str

Let $url = '/blog/?p=4&preview=true';
then
$uri = parse_url($url);
parse_str($uri['query'], $get);
echo $get['preview'];

Sincerely,
Alexander
http://www.alexatnet.com/ - PHP/ZendFramework/Ajax blog

Nov 3 '06 #5
I get up to "/blog/" and that's it. It seems the rest is cut off.

$_SERVER['PHP_SELF'] only returns the current dir/scriptname.ext, not
the query string.

You could say:

$preview (@$_GET['preview']) ? $_GET['preview'] : false;
if($preview){
//Include JS
};
or
if((!$isWPAdmin) xor ($preview)){
//Include JS
};

Nov 3 '06 #6
I get up to "/blog/" and that's it. It seems the rest is cut off.

$_SERVER['PHP_SELF'] only returns the current dir/scriptname.ext, not
the query string.

You could say:

$preview = (@$_GET['preview']) ? $_GET['preview'] : false;
if($preview){
//Include JS

};

or

if((!$isWPAdmin) xor ($preview)){
//Include JS
};

Nov 3 '06 #7
Let $url = '/blog/?p=4&preview=true';
then
$uri = parse_url($url);
parse_str($uri['query'], $get);
echo $get['preview'];
For some reason, the conditions weren't running. When I output

print_r($get);

I see

Array
(
)

The URL does have a query string. Any suggestions?

Thanks,
Brett

Nov 3 '06 #8
$preview = (@$_GET['preview']) ? $_GET['preview'] : false;
if($preview){
//Include JS

};

or

if((!$isWPAdmin) xor ($preview)){
//Include JS
};
This seems to be doing what I want.

Thanks,
Brett

Nov 3 '06 #9
brett wrote:
I'd like to execute javascript if I'm in a certain directory. I can't
figure out how to render the javascript script below. I always end up
with some type of parsing error. Any suggestions?
It looks like from that code you are trying to install a counter using
WordPress. If this is helpful for future developments (or anyone else
out there): there are plug-ins which allow you to easily install
counters; for example:
http://counterblog.gostats.com/how-t...dpress-plugins

Nov 9 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Bruce E. Pullum | last post by:
Can anyone please help me understand how to do the following: I have an ASPX page that has a tabstrip and multipage. On the multipage, each pageview has an IFRAME that has another ASPX page...
1
by: fabius | last post by:
Hi, I want display page rendering time. Is correct this code? : <html> <head> <SCRIPT> var timestampa =new Date;
9
by: glin | last post by:
Hi Guys, I am having problem finding the position of a button that I can set the div position next to the button. Can you please help? Thanks in advance.
9
by: Yama | last post by:
Hi, How can I dynamically embed the content of a filename.js into a .aspx page before rendering it to the client? Thanks, ~yamazed
6
by: drec | last post by:
I am just learning Javascript and I would like to create a basic form that gives me two options. This will be using either checkbox or radio input type, however I would like the second option to...
53
by: Hexman | last post by:
Hello All, I'd like your comments on the code below. The sub does exactly what I want it to do but I don't feel that it is solid as all. It seems like I'm using some VB6 code, .Net2003 code,...
3
by: brian.turner | last post by:
This is sort of a design/javascript question. It involves CSS rendering in dynamic areas of a page using IE. E 6 & 7 HI There, We've created some example static html pages (using CSS) that...
3
by: SAL | last post by:
Hello, I did google this issue and found some stuff related to BrowserCaps section of either web.config or machine.config but it didn't work. It seems that most pages in my webapp are okay but a...
53
by: souporpower | last post by:
Hello All I am trying to activate a link using Jquery. Here is my code; <html> <head> <script type="text/javascript" src="../../resources/js/ jquery-1.2.6.js"</script> <script...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.