Page 1 of 1

how do i get the current page url? anyweb page

Posted: Sun Feb 01, 2009 8:31 pm
by chikooo
ok so i have this web site where i would like to put pictures like the ones that appears on the sites that offer image comments for myspace, where the html code is below the image; the code where you can copy it and paste it.

so how do i make my web page to generate the code itself so i dont have to be writing the code on every page

i only know this php code that will write the domain name <?php echo $HTTP_SERVER_VARS['HTTP_HOST']; ?> but i want the full page url, and also if i can get the image full url.

anybody gets what im saying?
well the webpage is http://www.espan-glish.com/comments/

Re: how do i get the current page url? anyweb page

Posted: Mon Feb 02, 2009 2:08 am
by susrisha
have you tried $_SERVER[PHP_SELF] ??

Re: how do i get the current page url? anyweb page

Posted: Mon Feb 02, 2009 4:08 pm
by chikooo
i tried the code u gave me and i modified it to this <?php echo $_SERVER[PHP_SELF]; ?> and it gave me the page url just what i wanted. but now how do i get an image url

Re: how do i get the current page url? anyweb page

Posted: Mon Feb 02, 2009 4:12 pm
by watson516
You know where the images are saved. You know what the image name is.

domain.com/imageFolder/imageName.ext

Re: how do i get the current page url? anyweb page

Posted: Mon Feb 02, 2009 4:23 pm
by chikooo
so i found this webpage that has this


Sometimes, you might want to get the current page URL that is shown in the browser URL window. For example if you want to let your visitors submit a blog post to Digg you need to get that same exact URL. There are plenty of other reasons as well. Here is how you can do that.

Add the following code to a page:

<?php
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
?>
You can now get the current page URL using the line:

<?php
echo curPageURL();
?>
Sometimes it is needed to get the page name only. The following example shows how to do it:

<?php
function curPageName() {
return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
}

echo "The current page name is ".curPageName();
?>




so i dont get where do i put the first code? it says on a page which page. i meAn should i put it on the page where i want the url to appear. on the header or where

Re: how do i get the current page url? anyweb page

Posted: Tue Feb 03, 2009 10:13 am
by pickle
Don't use $_SERVER['PHP_SELF'] - it isn't guaranteed to be set (comes from the client). Use $_SERVER['REQUEST_URI'] instead.