Jump to content


Photo

[SOLVED] Page Location Script


  • Please log in to reply
6 replies to this topic

#1 robindean

robindean
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 31 May 2006 - 08:48 PM

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.href
if (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.

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 31 May 2006 - 08:55 PM

Yes, you can check the predefined variable $_SERVER['REQUEST_URI']
~ D Kuang

#3 robindean

robindean
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 31 May 2006 - 10:13 PM

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')
}

#4 sprinkles

sprinkles
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 31 May 2006 - 10:16 PM

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.

#5 robindean

robindean
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 01 June 2006 - 01:25 AM

Thank you very much!

#6 robindean

robindean
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 01 June 2006 - 01:59 AM

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?

#7 robindean

robindean
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 01 June 2006 - 04:34 AM

I'm getting close, so I'm going to start a new thread. Thanks for pointing me in the right direction.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users