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
https://forums.phpfreaks.com/topic/10899-solved-page-location-script/
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.
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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.