Help rendering Javascript?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • brett

    #1

    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="javas cript">
    var sc_project=1000 ;
    var sc_invisible=1;
    var sc_partition=10 1;
    var sc_security="10 00";
    </script>

    <script type="text/javascript" language="javas cript"
    src="http://www.abc.com/counter/counter.js"></script><noscrip t><a
    href="http://www.abc.com/" target="_blank" ><img
    src="http://11.abc.com/counter.php?sc_ project=1000&am p;java=0&amp;se curity=1000&amp ;
    invisible=1" alt="hit counter" border="0"></a</noscript>
    <!-- End of Code -->

    }
    ?>

    Thanks,
    Brett

  • josh.23.french

    #2
    Re: Help rendering Javascript?

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

    <script type="text/javascript" language="javas cript"
    src="http://www.abc.com/counter/counter.js"></script><noscrip t><a
    href="http://www.abc.com/" target="_blank" ><img
    src="http://11.abc.com/counter.php?sc_ project=1000&ja va=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="javas cript">
    var sc_project=1000 ;
    var sc_invisible=1;
    var sc_partition=10 1;
    var sc_security="10 00";
    </script>
    >
    <script type="text/javascript" language="javas cript"
    src="http://www.abc.com/counter/counter.js"></script><noscrip t><a
    href="http://www.abc.com/" target="_blank" ><img
    src="http://11.abc.com/counter.php?sc_ project=1000&ja va=0&security.. .
    invisible=1" alt="hit counter" border="0"></a</noscript>
    <!-- End of Code -->
    >
    }?>
    >
    Thanks,
    Brett

    Comment

    • brett

      #3
      Re: Help rendering Javascript?

      Excellent! Thanks.

      Comment

      • brett

        #4
        Re: Help rendering Javascript?

        That doesn't seem to work when the URL has a "?" in it:

        /blog/?p=4&preview=tr ue

        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=tr ue"?

        Thanks,
        Brett

        Comment

        • AlexVN

          #5
          Re: Help rendering Javascript?



          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=tr ue
          >
          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=tr ue"?
          >
          Thanks,
          Brett
          Parse a URL and return its components

          Parse a string as a URL query string


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

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

          Comment

          • josh.23.french

            #6
            Re: Help rendering Javascript?

            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
            };

            Comment

            • josh.23.french

              #7
              Re: Help rendering Javascript?

              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
              };

              Comment

              • brett

                #8
                Re: Help rendering Javascript?

                Let $url = '/blog/?p=4&preview=tr ue';
                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

                Comment

                • brett

                  #9
                  Re: Help rendering Javascript?

                  $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

                  Comment

                  • rchmura

                    #10
                    Re: Help rendering Javascript?

                    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:


                    Comment

                    Working...