Jump to content


Photo

Displaying information after a # in PHP_SELF


  • Please log in to reply
6 replies to this topic

#1 Doqrs

Doqrs
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 21 April 2006 - 12:53 AM

Hello,
say i have a weblocation [a href=\"http://someurl.com/index.php#here\" target=\"_blank\"]http://someurl.com/index.php#here[/a], how would i get the information after the # sign, php_self only returns index.php. I am in need of the 'here' text.

Thanks in advance, its hard doing a search on a pound sign :-p

#2 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 21 April 2006 - 11:39 AM

[!--quoteo(post=367060:date=Apr 21 2006, 01:53 AM:name=Doqrs)--][div class=\'quotetop\']QUOTE(Doqrs @ Apr 21 2006, 01:53 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Hello,
say i have a weblocation [a href=\"http://someurl.com/index.php#here\" target=\"_blank\"]http://someurl.com/index.php#here[/a], how would i get the information after the # sign, php_self only returns index.php. I am in need of the 'here' text.

Thanks in advance, its hard doing a search on a pound sign :-p
[/quote]

hmm i tried this with a couple of files and a phpinfo(), but couldn't actually find anything. i'd probably say then it's not possible to do it this way.
however, there maybe alternative ways of getting your desired effect, depending on what youre trying to achieve?
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#3 Doqrs

Doqrs
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 21 April 2006 - 12:03 PM

well im using ajax to load the content of my page, and am changing the document.href in javascript after the content loads ( i want to be able to copy and paste the link to be able to hotlink to a certain area). Anyways all the stuff is done with javascript but i wanted to be able to get the variables into php without having to manage cookies.

#4 wisewood

wisewood
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts
  • LocationRotherham, England

Posted 21 April 2006 - 12:10 PM

This will help you on your way. I found this when trying to do the same thing.

If you set a variable to contain the value of selfURL(); you will then be able to use substr to get whatever is after the #.



<?php

function selfURL() {
 $s = empty($_SERVER["HTTPS"]) ? ''
  : ($_SERVER["HTTPS"] == "on") ? "s"
  : "";
 $protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
 $port = ($_SERVER["SERVER_PORT"] == "80") ? ""
  : (":".$_SERVER["SERVER_PORT"]);
 return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
}
function strleft($s1, $s2) {
 return substr($s1, 0, strpos($s1, $s2));
} 

?>

wisewood: proven fact, I am both wise, and wooden.

#5 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 21 April 2006 - 03:11 PM

[!--quoteo(post=367170:date=Apr 21 2006, 01:10 PM:name=wisewood)--][div class=\'quotetop\']QUOTE(wisewood @ Apr 21 2006, 01:10 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
This will help you on your way. I found this when trying to do the same thing.

If you set a variable to contain the value of selfURL(); you will then be able to use substr to get whatever is after the #.
<?php

function selfURL() {
 $s = empty($_SERVER["HTTPS"]) ? ''
  : ($_SERVER["HTTPS"] == "on") ? "s"
  : "";
 $protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
 $port = ($_SERVER["SERVER_PORT"] == "80") ? ""
  : (":".$_SERVER["SERVER_PORT"]);
 return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
}
function strleft($s1, $s2) {
 return substr($s1, 0, strpos($s1, $s2));
} 

?>
[/quote]

but all of your methods here containt variables from the $_SERVER array, which i checked whilst looking through the phpinfo(). notably, $_SERVER['REQUEST_URI'] which i would have expected to hold the result - didnt work there, either.

"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#6 wisewood

wisewood
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts
  • LocationRotherham, England

Posted 21 April 2006 - 03:19 PM

just curious, but why use the # instead of the ? anyway
wisewood: proven fact, I am both wise, and wooden.

#7 Doqrs

Doqrs
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 21 April 2006 - 11:26 PM

[!--quoteo(post=367214:date=Apr 21 2006, 11:19 AM:name=wisewood)--][div class=\'quotetop\']QUOTE(wisewood @ Apr 21 2006, 11:19 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
just curious, but why use the # instead of the ? anyway
[/quote]
All of the pages load via ajax, and i dont want the page to refresh because there is a flash audio player in the top.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users