*sigh* Super noob has a question :)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hurdy gurdy
Forum Commoner
Posts: 40
Joined: Mon Jun 09, 2003 8:19 pm

*sigh* Super noob has a question :)

Post by hurdy gurdy »

I've looked everywhere, and I'm kicking myself constantly over this, but how does one get the URL of a page and pass it to a variable as a string?

or

Would I get the current pages URL bu using something like this:

Code: Select all

$url = $_SERVER['REQUEST_URI'];
or would this be better?

Code: Select all

$url = $_SERVER['PHP_SELF'];
essentially, what I want to do is pass the URL as a string to a variable, so that

$url = "http://www.someplace.com/somepage.php";

did any of that make sense? :)

Thanks in advance
User avatar
Crashin
Forum Contributor
Posts: 223
Joined: Mon May 06, 2002 3:42 pm
Location: Colorado

Post by Crashin »

Are you trying to get the URL of the page that you are on? I'm not sure where your URL is coming from...
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

For a link you are better off using

Code: Select all

$url = $_SERVER['REQUEST_URI'];
. This will give you the full URL along with any arguments passed (like file.php?id=12)

Using

Code: Select all

$_SERVER['PHP_SELF'];
will only give the filename relative to the document root, so something like: public_HTML/mystuff/files/thisfile.php
hurdy gurdy
Forum Commoner
Posts: 40
Joined: Mon Jun 09, 2003 8:19 pm

Post by hurdy gurdy »

ah excellent!

muchas gracias!
Post Reply