thebluebus Posted September 11, 2006 Share Posted September 11, 2006 Can anyone help. I want to add a text box to a page, which displays the current page URL. I've been told this can be done easily in php.Anyone walk me through it?thanks :) Link to comment https://forums.phpfreaks.com/topic/20392-current-page-url-in-text-box/ Share on other sites More sharing options...
shocker-z Posted September 11, 2006 Share Posted September 11, 2006 <input name="url" type="text" value="<?php echo $_SERVER['REQUEST_URI']; ?>">Should do the trick :)LiamEDIT: <input name="url" type="text" value="<?php echo $_SERVER['SERVER_NAME']; ?>">will show just the domain... Link to comment https://forums.phpfreaks.com/topic/20392-current-page-url-in-text-box/#findComment-89820 Share on other sites More sharing options...
hostfreak Posted September 11, 2006 Share Posted September 11, 2006 There is probably a more simplier solution than this, but this is what a google search returned:[code]<?phpfunction selfURL() { $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; $protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s; $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]); return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];}function strleft($s1, $s2) { return substr($s1, 0, strpos($s1, $s2));}print(selfURL());?>[/code]I have tested it and it works. It creates a function to retrieve the url. So to add that in a text box:[code]<?phpfunction selfURL() { $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; $protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s; $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]); return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];}function strleft($s1, $s2) { return substr($s1, 0, strpos($s1, $s2));}?><textarea><?php print(selfURL()); ?></textarea>[/code] Link to comment https://forums.phpfreaks.com/topic/20392-current-page-url-in-text-box/#findComment-89821 Share on other sites More sharing options...
hostfreak Posted September 11, 2006 Share Posted September 11, 2006 shocker-z, I was going to suggest $_SERVER['REQUEST_URI'], but for some reason when I was testing it, it didn't display the full url? Maybe that was just my host. Link to comment https://forums.phpfreaks.com/topic/20392-current-page-url-in-text-box/#findComment-89822 Share on other sites More sharing options...
thebluebus Posted September 11, 2006 Author Share Posted September 11, 2006 thanks both of you. i'll give them a try a bit later after work. ;D Link to comment https://forums.phpfreaks.com/topic/20392-current-page-url-in-text-box/#findComment-89824 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.