Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

if statement in php

Posted on 2011-02-23
12
Medium Priority
?
296 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 1600 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 1600 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 400 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 1600 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 1600 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 111

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

Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The viewer will learn how to dynamically set the form action using jQuery.

719 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