Solved

if statement in php

Posted on 2011-02-23
12
273 Views
Last Modified: 2012-05-11
I need to place an if, then statement in my index.php page so that if the page is /apply-online/ then it invokes some javascript on that index.php

This is a wordpress site and index.php in the root is where I had the script but I need to move it off of that home page and onto an internal page which is /apply-online/

Any ideas?
0
Comment
Question by:COwebmaster
12 Comments
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 400 total points
ID: 34964843
By apply-online you mean a web browser address in upper bar ?
0
 

Author Comment

by:COwebmaster
ID: 34964858
yes
0
 
LVL 27

Assisted Solution

by:Lukasz Chmielewski
Lukasz Chmielewski earned 400 total points
ID: 34964900
With that you can get a page address in php
http://www.webcheatsheet.com/PHP/get_current_page_url.php
and so - if the apply-online - depending on the position of it is inside that string, you can invoke a js.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:COwebmaster
ID: 34964962
I tried the following and the jquery popup loads on the home page if I set $uri to '/' but not if I set the path to /apply-online/

Any idea why?
<?php
$uri = $_SERVER['REQUEST_URI'];
if ($uri == "/apply-online/") {
      echo "<link rel='stylesheet' href='js/shadowbox/shadowbox.css' type='text/css' media='screen' />
	  <script type='text/javascript' src='js/nav.js'></script>
	  <script type='text/javascript' src='js/nav.js'></script>
	  <script type='text/javascript' src='js/jquery-1.3.2.min.js'></script>
	  <script type='text/javascript' src='js/shadowbox/shadowbox.js'></script>
	  <script type='text/javascript'>
		Shadowbox.init({
        displayNav: true,
        onClose:function(){
                top.location.href='http://domain.com/?s=';
        }
        

});

$(function() {
        if (document.URL == 'http://domain.com/') {
                setTimeout(function() {
                        //Shadowbox.init();
                        Shadowbox.open({
                                player:         'iframe',
                                content:        'test1.cfm',
                                displayNav:     true,
                                width:          '840',
                                height:         '750',
                                modal:          true
                        });
                }, 2000);
        }
});
function getCookieValue1() {
        var openUrl = '';
        var c_name = 'nowUrlIs';
        if (document.cookie.length > 0) {
                var c_start = document.cookie.indexOf(c_name + '=');
                if (c_start != -1) {
                        c_start = c_start + c_name.length + 1;
                        var c_end = document.cookie.indexOf(';', c_start);
                        if (c_end == -1)
                                c_end = document.cookie.length;
                        openUrl = document.cookie.substring(c_start, c_end);

                        setTimeout(function() {
                                //Shadowbox.init();
                                Shadowbox.open({
                                        player:         'iframe',
                                        content:        openUrl,
                                        displayNav:     true,
                                        width:          '840',
                                        height:         '750',
                                        title:          'Please click out side the frame to close it',
                                        modal:          false
                                });
                        }, 2000);
                }
        }
}
</script>";
} else {
     echo $_SERVER['REQUEST_URI'];
}
?>

Open in new window

0
 
LVL 8

Assisted Solution

by:ropenner
ropenner earned 100 total points
ID: 34964985
Something like below perhaps is what you are looking for?


<?PHP
if (strpos($_SERVER{'REQUEST_URI'},'/apply-online/') > -1) {
   print <<< endofjavascript
    <SCRIPT language=javascript>
      var dump;
      location.href='http://google.ca';
   </SCRIPT>
endofjavascript
} else {
print <<< endofhtml
  <HTML>
  <BODY>
hiya
  </BODY>
  </HTML
endofhtml
}
?>
0
 

Author Comment

by:COwebmaster
ID: 34965043
ropenner, my page broke using that.
0
 

Author Comment

by:COwebmaster
ID: 34965059
I need to remove those double quotes around all of my code because I think it sees it all as a string.  I tried removing the double quotes but it didn't work
0
 
LVL 27

Assisted Solution

by:Lukasz Chmielewski
Lukasz Chmielewski earned 400 total points
ID: 34965093
$uri = $_SERVER['REQUEST_URI'];
would not be /apply-online/
You would have to search for a presence of that string in a full uri.
0
 
LVL 27

Assisted Solution

by:Lukasz Chmielewski
Lukasz Chmielewski earned 400 total points
ID: 34965121
Maybe using substr_ count like
if (substr_count($uri,"/apply-online/") > 0)
rather than
if ($uri == "/apply-online/")
0
 

Author Comment

by:COwebmaster
ID: 34965216
tried that but it didn't work.

So I have which works from the home page and the internal page path /apply-online/ displays at the bottom just fine.  Just can't get that darn popup to show up on that page.
<?php
$uri = $_SERVER['REQUEST_URI'];
if ($uri == "/") {
      echo "<link rel='stylesheet' href='/js/shadowbox/shadowbox.css' type='text/css' media='screen' />
	  <script type='text/javascript' src='/js/nav.js'></script>
	  <script type='text/javascript' src='/js/jquery-1.3.2.min.js'></script>
	  <script type='text/javascript' src='/js/shadowbox/shadowbox.js'></script>
	  <script type='text/javascript'>
		Shadowbox.init({
        displayNav: true,
        onClose:function(){
                top.location.href='http://domain.com/?s=';
        }
        

});

$(function() {
        if (document.URL == 'http://domain.com/') {
                setTimeout(function() {
                        //Shadowbox.init();
                        Shadowbox.open({
                                player:         'iframe',
                                content:        'test1.cfm',
                                displayNav:     true,
                                width:          '840',
                                height:         '750',
                                modal:          true
                        });
                }, 2000);
        }
});

function getCookieValue1() {
        var openUrl = '';
        var c_name = 'nowUrlIs';
        if (document.cookie.length > 0) {
                var c_start = document.cookie.indexOf(c_name + '=');
                if (c_start != -1) {
                        c_start = c_start + c_name.length + 1;
                        var c_end = document.cookie.indexOf(';', c_start);
                        if (c_end == -1)
                                c_end = document.cookie.length;
                        openUrl = document.cookie.substring(c_start, c_end);

                        setTimeout(function() {
                                //Shadowbox.init();
                                Shadowbox.open({
                                        player:         'iframe',
                                        content:        openUrl,
                                        displayNav:     true,
                                        width:          '840',
                                        height:         '750',
                                        title:          'Please click out side the frame to close it',
                                        modal:          false
                                });
                        }, 2000);
                }
        }
}</script>";
} else {
     echo $_SERVER['REQUEST_URI'];
}
?>

Open in new window

0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 34969765
I think WordPress may be getting in your way of understanding the PHP-related issues here.  How much experience do you have in PHP (outside of WP)?
0
 

Author Closing Comment

by:COwebmaster
ID: 35064414
Thanks!
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question