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 :) Quote Link to comment 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... Quote Link to comment 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] Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.