Page 1 of 1
Storing current url in a variable
Posted: Sun Sep 02, 2007 6:52 am
by kkonline
I want to store the current page url in variable $link
I used
But it gave me
only pages.php if the current link is
http://localhost/pages.php?catid=1&id=3
This is required as i am storing the url in a social bookmarking site
What to do?
Posted: Sun Sep 02, 2007 7:34 am
by Ballam
I was actually doing the same thing yesterday, but for a different reason!
To get the full url you're best doing this:
$variable = $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
Hope this helps
B
Posted: Sun Sep 02, 2007 7:43 am
by kkonline
Ballam wrote:I was actually doing the same thing yesterday, but for a different reason!
To get the full url you're best doing this:
$variable = $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
Hope this helps
B
It works if i use
Code: Select all
$link = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
I am wondering what should i write if there are some sub directories
http://localhost/article/pages.php?page=1&catid=1
will the above code still work???
Posted: Sun Sep 02, 2007 7:48 am
by Ballam
yeah that should work fine

Posted: Sun Sep 02, 2007 7:59 am
by feyd
There are a lot of other things you need to be concerned with regarding the rebuilding of the current URL.
viewtopic.php?t=37950&highlight=geturl