Jump to content

[SOLVED] Page Location Script


robindean

Recommended Posts

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.