FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Getting a URL with PHP





Ben
Hiya,

I'm having loads of trouble withsomething.
I just need a way in PHP of 'getting' the URL that you are currently at.
I have tried many functions, that sort of do it, but not 100%.
The URLs also have a page.php?this=that which the functions I have used dont get.

Thanks in advance,
Ben Very Happy
mathiaus
using $_SERVER['REQUEST_URI'] will give you /folder/file.php?id=id
if you want the server name use $_SERVER['SERVER_NAME'] but that wont work if you use a parked domain as your primary domain
Atomo64
or you can use $_SERVER["HTTP_HOST"] if what you want is to get the host that the browser is trying to access. E.g: myacc.frihost.com, myacc.com, frihost.com/~myacc
PatTheGreat42
The built-in constant __FILE__ will get you the complete file path. That might do what you want it to.
simplyw00x
What you're secretly looking for is this:
Code:
strtolower(strtok($_SERVER['SERVER_PROTOCOL'], '/')).'://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']


This returns something like:
Code:
http://www.frihost.com/forums/posting.php?mode=reply&t=27246


I.E. the whole shebang. Hope this helps.
Terrasis-Cian
there are loads of websites which give a piece of code to plant on your page. they might have what your looking for, try looking on google. Goodluck Laughing
simplyw00x
Quote:
there are loads of websites which give a piece of code to plant on your page. they might have what your looking for, try looking on google. Goodluck Laughing

And the point of that post was?
Atomo64
simplyw00x wrote:
Quote:
there are loads of websites which give a piece of code to plant on your page. they might have what your looking for, try looking on google. Goodluck Laughing

And the point of that post was?

try to earn some points? he has... -52.82 Points Wink
izcool
Really simple :

Code:

<?php
echo $_SERVER[PHP_SELF];
?>


Would display as "/posting.php" for me, the page that I'm writing this reply from.

- Mike.
sonam
You can get full URL with:

Code:
<?php

echo "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];

?>


Hope it will help Wink

Sonam
rohan2kool
for the methods of izcool & sonam... i don't think it would return the query string.
sonam
Quote:
for the methods of izcool & sonam... i don't think it would return the query string.


Why dont you check. I cannot check this code now because my computer gone today, and who know when I will get new one. Sad
Sonam
rohan2kool
Nope it doesn't work. This example works:

Code:


<?php
$add = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
$add .= "?";
foreach($_GET as $key=>$value) {
   $add .= $key;
   $add .= "=";
   $add .= $value;
   $add .= "&";
}
echo($add);
php?>

sonam
I am wrong understand Bens question. I was thinking he want only to get URL and then he know how to parse. Now I read again his question.
Confused

What result is comming out from your script. Sorry for stupid question but I cannot check. Sad

Sonam
rohan2kool
If I save it as a file called 'cp.php' and go to page by:

http://localhost/qb/cp.php?num23=12&hobby=sex&dream=tomorrow&fear=mom

Then it displays the following line:

http://localhost/qb/cp.php?num23=12&hobby=sex&dream=tomorrow&fear=mom
sonam
Thanks grohan2kool,
hope it will help to ben.
sangharsha
You can use the combination of following two server variables to determine the working url.
$_SERVER['SCRIPT_NAME']."?".$_SERVER['QUERY_STRING']

If you want the physical path of currently working area then you can use:
getcwd();


R
Related topics
Za darmo w Internecie...
PHP and HTML????
CSS Help needed : Table emulation with divs
Explain and get up to 30FRIH!
SPAM ME!!!
Cafe18.NET ( The Best Indian Forum )
File permissions (Server 1)
mySQL set-up on Frihost help please
voting script with a twist
everybody has server 2 problem? [solved]
Problems with PHP-Nuke on Server2
CMS jakie systemy uzywacie i polecacie?
How do make a proxy?
Error with PHP-Nuke 7.8
PHP-Fusion | An Open Source CMS | PHP & MySQL Based
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.