Solved

if statement in php

Posted on 2011-02-23
12
287 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 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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 110

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

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

Question has a verified solution.

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

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
This article discusses how to implement server side field validation and display customized error messages to the client.
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

626 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