robindean Posted May 31, 2006 Share Posted May 31, 2006 I have a javascript which I need to convert into php code.It does something to the effect of this ...<script language="javascript">var mypage=window.location.hrefif (mypage=="page_name.html?extension"){do somthing here;}else do another thing;</script>Basically, It's asking for a page name and then deciding what to do based on the result. The code is going to be placed within the same page that it is actively attemping to identify, which is why I'll be adding ?extension to the end.Is there a simple php version of this action?Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/10899-solved-page-location-script/ Share on other sites More sharing options...
poirot Posted May 31, 2006 Share Posted May 31, 2006 Yes, you can check the predefined variable $_SERVER['REQUEST_URI'] Quote Link to comment https://forums.phpfreaks.com/topic/10899-solved-page-location-script/#findComment-40701 Share on other sites More sharing options...
robindean Posted May 31, 2006 Author Share Posted May 31, 2006 How do I make use of this? I'm a newbie to php.I'm assuming thus far that I can say something to the effect of ...$mypage = $_SERVER['REQUEST_URI']if $mypage = "page_name.html?extension"{print('this is written to the page')} Quote Link to comment https://forums.phpfreaks.com/topic/10899-solved-page-location-script/#findComment-40715 Share on other sites More sharing options...
sprinkles Posted May 31, 2006 Share Posted May 31, 2006 If what you're looking to do is re-direct based on parameters (such as index.php?location=forums redirects to forums.php) then this should do it:<?$location = $_GET['location'];if($location=="PAGENAME") {header("location: pagename.php");} else if($location=="OTHERPAGENAME") {header("location: otherpagename.php");}etc. Quote Link to comment https://forums.phpfreaks.com/topic/10899-solved-page-location-script/#findComment-40716 Share on other sites More sharing options...
robindean Posted June 1, 2006 Author Share Posted June 1, 2006 Thank you very much! Quote Link to comment https://forums.phpfreaks.com/topic/10899-solved-page-location-script/#findComment-40757 Share on other sites More sharing options...
robindean Posted June 1, 2006 Author Share Posted June 1, 2006 Just for safe posting, I'm trying to differentiate between "somesite.com" and "somesite.com?complimentary_tag"My intention is that, if the url location is "somesite.com" it prints one line of code but if it ends with "?complimentary_tag" on the end it prints a completely different line of code.Further more,In javascript, there's a difference between:somesite.com... and ...[a href=\"http://somesite.com\" target=\"_blank\"]http://somesite.com[/a]... and ...[a href=\"http://www.somesite.com\" target=\"_blank\"]http://www.somesite.com[/a]so I'm wondering how to use the "or" statement in php ... or do I even need to? Quote Link to comment https://forums.phpfreaks.com/topic/10899-solved-page-location-script/#findComment-40765 Share on other sites More sharing options...
robindean Posted June 1, 2006 Author Share Posted June 1, 2006 I'm getting close, so I'm going to start a new thread. Thanks for pointing me in the right direction. Quote Link to comment https://forums.phpfreaks.com/topic/10899-solved-page-location-script/#findComment-40787 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.