Not logged in. · Lost password · Register
Forum: Support General support RSS
Current page link variable?
Does it exist?
Avatar
NFG #1
Member since Sep 2006 · 120 posts
Group memberships: Members
Show profile · Link to this post
Subject: Current page link variable?
It's killing me, I can't figure out how to get the current page URL in a plugin.  I'm trying to add the opengraph details for every page to a plugin, and I'm getting the results I expect, except the URL.  Is there a global variable that does this?  The template vars are not always available, so what works in a post might not work in a thread or a forum view, etc.

I've spent ages on it, and can't work it out.  Any hints? =)
Avatar
Yves (Administrator) #2
User title: UNB developer & webmaster
Member since Jan 2004 · 3818 posts · Location: Erlangen, Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Tried something from the $_SERVER space, like $_SERVER['PHP_SELF'] (formerly $PHP_SELF or so) or one of the HTTP_* entries? There's no UNB special for that. You need to go down to PHP.
♪ ...nanananah, all in all we’re just brilliant thieves, nanananah... ♪♬
Avatar
NFG #3
Member since Sep 2006 · 120 posts
Group memberships: Members
Show profile · Link to this post
That worked perfectly, thanks Yves!

For anyone who wonders, I used

$_SERVER['PHP_SELF']

followed by

$_SERVER['REQUEST_URI']
Avatar
Yves (Administrator) #4
User title: UNB developer & webmaster
Member since Jan 2004 · 3818 posts · Location: Erlangen, Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Note that PHP_SELF contains the absolute path of the file on the server's filesystem. You shouldn't want to expose this to the user. REQUEST_URI should be the very URL that was requested by the browser, so this should be better suited for your described requirement.
♪ ...nanananah, all in all we’re just brilliant thieves, nanananah... ♪♬
Avatar
NFG #5
Member since Sep 2006 · 120 posts
Group memberships: Members
Show profile · Link to this post
Actually PHP_SELF is just the filename of the script, relative to document root.  So my string is:

  1. $string = 'http://domainname.com' . $_SERVER['PHP_SELF'] . $_SERVER['REQUEST_URI'];

and the result is

http://domainname.com/path/to/script.php?any&additional&args

If it was the filesystem path it wouldn't be very useful at all.  =)
Avatar
Yves (Administrator) #6
User title: UNB developer & webmaster
Member since Jan 2004 · 3818 posts · Location: Erlangen, Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Alright. My memory must have fooled me. I haven't been using such low-level things for a time.
♪ ...nanananah, all in all we’re just brilliant thieves, nanananah... ♪♬
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
This board is powered by the Unclassified NewsBoard software, 20110527-dev, © 2003-2011 by Yves Goergen
Page created in 141.4 ms (85.2 ms) · 69 database queries in 96.4 ms
Current time: 2012-05-21, 19:03:43 (UTC +02:00)