[PHP] Current URL?
Trying to get the current viewed page's URL (query string intact). this works, but infrequently: $url = $_SERVER['URI']; and this ignores the query string: $url = $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; I'm certain there's a way, that is browser-independent, to get your script to grab the current URL (even if the script is an include). i'm just trying to get a log of users currently online, and which page they are viewing, and while the $_SERVER['REMOTE_ADDR'] will invariably grab the IP, $_SERVER['URI'] is often empty. i welcome any and all suggestions. thank you, ~jmp -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Current URL?
Jason Paschal wrote: Trying to get the current viewed page's URL (query string intact). this works, but infrequently: $url = $_SERVER['URI']; How about $_SERVER['REQUEST_URI'] and this ignores the query string: $url = $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; or you could add/check for $_SERVER['QUERY_STRING'] here. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Current URL
Also, on a Windows machiene, it returns something like c:\htdocs\subsite. Already tried it, but thanks. :-) I'll be going with your GLOBAL variable suggestion, it seems so obvious now. Thanks for the help! :-) Thanks, Stephen Craton http://www.melchior.us -Original Message- From: Robert Cummings [mailto:[EMAIL PROTECTED] Sent: Friday, June 04, 2004 12:59 AM To: Aidan Lister Cc: PHP-General Subject: Re: [PHP] Current URL On Fri, 2004-06-04 at 01:38, Aidan Lister wrote: Hi, You could use $_SERVER['DOCUMENT_ROOT'] That doesn't work... as the OP mentioned, the URLs might need to refer locally within a subsite built as a subdirectory within the document root. Cheers, Rob. Robert Cummings [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Thu, 2004-06-03 at 23:15, Stephen Craton wrote: I've wondered for quite some time, and search just as long it seems like, for a way to get the current URL directory. For example, let's say you were at www.example.com/files. The script is executing in this directory, and it's calling an include script from the base (www.example.com or maybe even www.example.com/includes). In this included file are some links and maybe some images. These images and links are set up to be called from the base directory, so basically all the links inside the file say something like images/bob.gif or something of that nature. How could you dynamicaly change this in relation to where the included script is? If I were to include it in that files in /files, it would look for the images in /files/images/bob.gif which would not be there. One solution I have thought of is just putting the / at the beginning (/images/) but that wouldn't be the safest solution if the script were running in a subfolder to begind with (like the entire site is in www.example.com/site1). I hope you understand what I'm trying to say. Any ideas? In a configuration file shared by the project's scripts have a constant or global variable like follows: $GLOBALS['imageBase'] = '/site1/'; Now wherever in your site you use an image you can use this value to prepend the image path. Cheers, Blobbie. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | a | powerful, scalable system for accessing system services | such as | forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | a | powerful, scalable system for accessing system services | such as | forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Current URL
I've wondered for quite some time, and search just as long it seems like, for a way to get the current URL directory. For example, let's say you were at www.example.com/files. The script is executing in this directory, and it's calling an include script from the base (www.example.com or maybe even www.example.com/includes). In this included file are some links and maybe some images. These images and links are set up to be called from the base directory, so basically all the links inside the file say something like images/bob.gif or something of that nature. How could you dynamicaly change this in relation to where the included script is? If I were to include it in that files in /files, it would look for the images in /files/images/bob.gif which would not be there. One solution I have thought of is just putting the / at the beginning (/images/) but that wouldn't be the safest solution if the script were running in a subfolder to begind with (like the entire site is in www.example.com/site1). I hope you understand what I'm trying to say. Any ideas? Thanks, Stephen Craton http://www.melchior.us http://www.melchior.us/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Current URL
On Thu, 2004-06-03 at 23:15, Stephen Craton wrote: I've wondered for quite some time, and search just as long it seems like, for a way to get the current URL directory. For example, let's say you were at www.example.com/files. The script is executing in this directory, and it's calling an include script from the base (www.example.com or maybe even www.example.com/includes). In this included file are some links and maybe some images. These images and links are set up to be called from the base directory, so basically all the links inside the file say something like images/bob.gif or something of that nature. How could you dynamicaly change this in relation to where the included script is? If I were to include it in that files in /files, it would look for the images in /files/images/bob.gif which would not be there. One solution I have thought of is just putting the / at the beginning (/images/) but that wouldn't be the safest solution if the script were running in a subfolder to begind with (like the entire site is in www.example.com/site1). I hope you understand what I'm trying to say. Any ideas? In a configuration file shared by the project's scripts have a constant or global variable like follows: $GLOBALS['imageBase'] = '/site1/'; Now wherever in your site you use an image you can use this value to prepend the image path. Cheers, Blobbie. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Current URL
Hi, You could use $_SERVER['DOCUMENT_ROOT'] Robert Cummings [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Thu, 2004-06-03 at 23:15, Stephen Craton wrote: I've wondered for quite some time, and search just as long it seems like, for a way to get the current URL directory. For example, let's say you were at www.example.com/files. The script is executing in this directory, and it's calling an include script from the base (www.example.com or maybe even www.example.com/includes). In this included file are some links and maybe some images. These images and links are set up to be called from the base directory, so basically all the links inside the file say something like images/bob.gif or something of that nature. How could you dynamicaly change this in relation to where the included script is? If I were to include it in that files in /files, it would look for the images in /files/images/bob.gif which would not be there. One solution I have thought of is just putting the / at the beginning (/images/) but that wouldn't be the safest solution if the script were running in a subfolder to begind with (like the entire site is in www.example.com/site1). I hope you understand what I'm trying to say. Any ideas? In a configuration file shared by the project's scripts have a constant or global variable like follows: $GLOBALS['imageBase'] = '/site1/'; Now wherever in your site you use an image you can use this value to prepend the image path. Cheers, Blobbie. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Current URL
On Fri, 2004-06-04 at 01:38, Aidan Lister wrote: Hi, You could use $_SERVER['DOCUMENT_ROOT'] That doesn't work... as the OP mentioned, the URLs might need to refer locally within a subsite built as a subdirectory within the document root. Cheers, Rob. Robert Cummings [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Thu, 2004-06-03 at 23:15, Stephen Craton wrote: I've wondered for quite some time, and search just as long it seems like, for a way to get the current URL directory. For example, let's say you were at www.example.com/files. The script is executing in this directory, and it's calling an include script from the base (www.example.com or maybe even www.example.com/includes). In this included file are some links and maybe some images. These images and links are set up to be called from the base directory, so basically all the links inside the file say something like images/bob.gif or something of that nature. How could you dynamicaly change this in relation to where the included script is? If I were to include it in that files in /files, it would look for the images in /files/images/bob.gif which would not be there. One solution I have thought of is just putting the / at the beginning (/images/) but that wouldn't be the safest solution if the script were running in a subfolder to begind with (like the entire site is in www.example.com/site1). I hope you understand what I'm trying to say. Any ideas? In a configuration file shared by the project's scripts have a constant or global variable like follows: $GLOBALS['imageBase'] = '/site1/'; Now wherever in your site you use an image you can use this value to prepend the image path. Cheers, Blobbie. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] current url function
Luis Mirabal wrote: i checked http://sk2.php.net/manual/en/features.http-auth.php, but it doesnt shows how to see if i passed user:pass in the url. i try http://user:[EMAIL PROTECTED]/ and dumped globals, and there is nothing... any ideas? variables $_SERVER['PHP_AUTH_USER'] and $_SERVER['PHP_AUTH_PW'], but it is not necessary anyways. the browser will remember credentials once they are set so it is useless to keep them in the url. and IE with the latest patch will ignore user:pass@ part. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] current url function
hey! i am working in an open source development, and have done a function that gives me the current url, but i need it to work always, everywhere, in every server with all browsers, could you tell me if you think it will or if you have any suggestions? here is the code: /* Returns the current URL TODO: The function can not manage nor return user and pass in the URL if present because it seems that you can not fetch them from PHP (or at least I dont't know how to do it :P) LIMITATIONS: fragment (after # sign) can not be fetched since it is a client-side feature */ function url($host=true, $querystring=true) { $url = ''; if($host) { if ( (!empty($_SERVER['HTTPS']) $_SERVER['HTTPS']=='on') || (!empty($_ENV['HTTPS']) $_ENV['HTTPS']=='on') ) $url = 'https://'; else $url = 'http://'; $url .= !empty($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME']; //if((int)$_SERVER['SERVER_PORT']!=80) $url .= ':' . $_SERVER['SERVER_PORT']; } //$url .= $_SERVER['SCRIPT_NAME']; //if($querystring !empty($_SERVER['QUERY_STRING'])) $url .= '?' . $_SERVER['QUERY_STRING']; if($querystring) $url .= $_SERVER['REQUEST_URI']; else $url .= $_SERVER['PHP_SELF']; return $url; } thanx in advance! luis. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] current url function
Luis Mirabal wrote: hey! i am working in an open source development, and have done a function that gives me the current url, but i need it to work always, everywhere, in every server with all browsers, could you tell me if you think it will or if you have any suggestions? here is the code: /* Returns the current URL TODO: The function can not manage nor return user and pass in the URL if present because it seems that you can not fetch them from PHP (or at least I dont't know how to do it :P) False, check http://sk2.php.net/manual/en/features.http-auth.php LIMITATIONS: fragment (after # sign) can not be fetched since it is a client-side feature True */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] current url function
i checked http://sk2.php.net/manual/en/features.http-auth.php, but it doesnt shows how to see if i passed user:pass in the url. i try http://user:[EMAIL PROTECTED]/ and dumped globals, and there is nothing... any ideas? Marek Kilimajer [EMAIL PROTECTED] escribió en el mensaje news:[EMAIL PROTECTED] Luis Mirabal wrote: hey! i am working in an open source development, and have done a function that gives me the current url, but i need it to work always, everywhere, in every server with all browsers, could you tell me if you think it will or if you have any suggestions? here is the code: /* Returns the current URL TODO: The function can not manage nor return user and pass in the URL if present because it seems that you can not fetch them from PHP (or at least I dont't know how to do it :P) False, check http://sk2.php.net/manual/en/features.http-auth.php LIMITATIONS: fragment (after # sign) can not be fetched since it is a client-side feature True */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re[2]: [PHP] current url function
Hello Luis, Tuesday, March 16, 2004, 1:41:49 AM, you wrote: LM i checked LM http://sk2.php.net/manual/en/features.http-auth.php, but it doesnt LM shows how to see if i passed user:pass in the url. i try LM http://user:[EMAIL PROTECTED]/ and dumped globals, and there is nothing... any LM ideas? If you are running PHP as an Apache module (and not CGI) then a correctly validated user will have their details in: $_SERVER['PHP_AUTH_USER'] and $_SERVER['PHP_AUTH_PW'] There is a whole chapter on this (16) in the manual. -- Best regards, Richard Davey http://www.phpcommunity.org/wiki/296.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Current URL is http or https?
Hi, I'm trying to find a way to determine whether a clients browser current url is prefixed by http or https. However, I cannot seem to find the right predefined variable to give me this information. Basically, I want the same thing that HTTP_REFERER provides, but for the _current_ page. Any ideas? Steven J. Walker Walker Effects www.walkereffects.com [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Current URL, Last URL, error handeling
Is there a way I can get the whole URL of the current page for error handling/reporting. Also is there a way of getting the previous/referrer URL for a similar purpose. Lastly if anyone could point me in the direction on error handling strategy/techniques in general this would be good. Regards, Ben * Ben Edwards +44 (0)117 9400 636 * * Critical Site Builderhttp://www.criticaldistribution.com * * online collaborative web authoring content management system * * i-Contact Progressive Video http://www.videonetwork.org * * Smashing the Corporate image http://www.subvertise.org * * Bristol Indymedia http://bristol.indymedia.org * * Bristol's radical news http://www.bristle.org.uk * * PGP : F0CA 42B8 D56F 28AD 169B 49F3 3056 C6DB 8538 EEF8 * -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Current URL, Last URL, error handeling
On Thursday 04 April 2002 21:56, Ben Edwards wrote: Is there a way I can get the whole URL of the current page for error handling/reporting. Also is there a way of getting the previous/referrer URL for a similar purpose. Have a look at the values inside $HTTP_SERVER_VARS: print_r($HTTP_SERVER_VARS); -- Jason Wong - Gremlins Associates - www.gremlins.com.hk /* Because he's a character who's looking for his own identity, [He-Man is] an interesting role for an actor. -- Dolph Lundgren, actor */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Current URL, Last URL, error handling
Kind of but not quite. Was wondering if PHP help the actual full url. Ben At 15:26 04/04/2002, you wrote: On Thursday 04 April 2002 21:56, Ben Edwards wrote: Is there a way I can get the whole URL of the current page for error handling/reporting. Also is there a way of getting the previous/referrer URL for a similar purpose. Have a look at the values inside $HTTP_SERVER_VARS: print_r($HTTP_SERVER_VARS); -- Jason Wong - Gremlins Associates - www.gremlins.com.hk /* Because he's a character who's looking for his own identity, [He-Man is] an interesting role for an actor. -- Dolph Lundgren, actor */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php * Ben Edwards +44 (0)117 9400 636 * * Critical Site Builderhttp://www.criticaldistribution.com * * online collaborative web authoring content management system * * i-Contact Progressive Video http://www.videonetwork.org * * Smashing the Corporate image http://www.subvertise.org * * Bristol Indymedia http://bristol.indymedia.org * * Bristol's radical news http://www.bristle.org.uk * * PGP : F0CA 42B8 D56F 28AD 169B 49F3 3056 C6DB 8538 EEF8 * -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Current URL, Last URL, error handling
$REQUEST_URI? If it's not the full you can complement with $HTTP_HOST or similar. -- Julio Nobrega. Um dia eu chego lá: http://sourceforge.net/projects/toca Ajudei? Salvei? Que tal um presentinho? http://www.submarino.com.br/wishlistclient.asp?wlid=664176742884 Ben Edwards [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Kind of but not quite. Was wondering if PHP help the actual full url. Ben At 15:26 04/04/2002, you wrote: On Thursday 04 April 2002 21:56, Ben Edwards wrote: Is there a way I can get the whole URL of the current page for error handling/reporting. Also is there a way of getting the previous/referrer URL for a similar purpose. Have a look at the values inside $HTTP_SERVER_VARS: print_r($HTTP_SERVER_VARS); -- Jason Wong - Gremlins Associates - www.gremlins.com.hk /* Because he's a character who's looking for his own identity, [He-Man is] an interesting role for an actor. -- Dolph Lundgren, actor */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php * Ben Edwards +44 (0)117 9400 636 * * Critical Site Builderhttp://www.criticaldistribution.com * * online collaborative web authoring content management system * * i-Contact Progressive Video http://www.videonetwork.org * * Smashing the Corporate image http://www.subvertise.org * * Bristol Indymedia http://bristol.indymedia.org * * Bristol's radical news http://www.bristle.org.uk * * PGP : F0CA 42B8 D56F 28AD 169B 49F3 3056 C6DB 8538 EEF8 * -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Current URL, Last URL, error handling
On Thursday 04 April 2002 22:56, Ben Edwards wrote: Kind of but not quite. Was wondering if PHP help the actual full url. If you look closely you can concatenate two of those values together to get what you want. -- Jason Wong - Gremlins Associates - www.gremlins.com.hk /* The good life was so elusive It really got me down I had to regain some confidence So I got into camouflage */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Current URL, Last URL, error handling
Don't seem to exist, neither douse REQUEST_URL? At 16:13 04/04/2002, Julio Nobrega Trabalhando wrote: $REQUEST_URI? If it's not the full you can complement with $HTTP_HOST or similar. -- Julio Nobrega. Um dia eu chego lá: http://sourceforge.net/projects/toca Ajudei? Salvei? Que tal um presentinho? http://www.submarino.com.br/wishlistclient.asp?wlid=664176742884 Ben Edwards [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Kind of but not quite. Was wondering if PHP help the actual full url. Ben At 15:26 04/04/2002, you wrote: On Thursday 04 April 2002 21:56, Ben Edwards wrote: Is there a way I can get the whole URL of the current page for error handling/reporting. Also is there a way of getting the previous/referrer URL for a similar purpose. Have a look at the values inside $HTTP_SERVER_VARS: print_r($HTTP_SERVER_VARS); -- Jason Wong - Gremlins Associates - www.gremlins.com.hk /* Because he's a character who's looking for his own identity, [He-Man is] an interesting role for an actor. -- Dolph Lundgren, actor */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php * Ben Edwards +44 (0)117 9400 636 * * Critical Site Builderhttp://www.criticaldistribution.com * * online collaborative web authoring content management system * * i-Contact Progressive Video http://www.videonetwork.org * * Smashing the Corporate image http://www.subvertise.org * * Bristol Indymedia http://bristol.indymedia.org * * Bristol's radical news http://www.bristle.org.uk * * PGP : F0CA 42B8 D56F 28AD 169B 49F3 3056 C6DB 8538 EEF8 * -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php * Ben Edwards +44 (0)117 9400 636 * * Critical Site Builderhttp://www.criticaldistribution.com * * online collaborative web authoring content management system * * i-Contact Progressive Video http://www.videonetwork.org * * Smashing the Corporate image http://www.subvertise.org * * Bristol Indymedia http://bristol.indymedia.org * * Bristol's radical news http://www.bristle.org.uk * * PGP : F0CA 42B8 D56F 28AD 169B 49F3 3056 C6DB 8538 EEF8 * -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Current URL, Last URL, error handling
Okay, just phpinfo(); and use the variables. You can see whetever you will need there for url script construction. If you need, setup two pages with phpinfo() and a link between them so you can check for Referers (the Last Url you need) -- Julio Nobrega. Um dia eu chego lá: http://sourceforge.net/projects/toca -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php