Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

if statement in php

Posted on 2011-02-23
12
Medium Priority
?
299 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 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

972 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