Jump to content

Archived

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

robindean

[SOLVED] Page Location Script

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.

Share this post


Link to post
Share on other sites
Yes, you can check the predefined variable $_SERVER['REQUEST_URI']

Share this post


Link to post
Share on other sites
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')
}

Share this post


Link to post
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.

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites
I'm getting close, so I'm going to start a new thread. Thanks for pointing me in the right direction.

Share this post


Link to post
Share on other sites

×

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.