starscream.pt Posted December 23, 2008 Share Posted December 23, 2008 Hello everyone, i want to make form text box which displays the current url, for example, this webpage i'm currently in is: http://www.phpfreaks.com/forums/index.php?action=post;board=1.0 so it should be displayed in the text box as that. Here is the page of my code including the form where it should display. Now, how do i do it? <head> <meta http-equiv="Content-Language" content="pt"> </head> <?php include "menu.php"; ?> </body> <body bgcolor="#C0C0C0"> <div align="center"> <table border="0" width="70%" height="100%" id="index_table" bgcolor="#B5CCFE" bordercolorlight="#FFFFFF" bordercolor="#FFFFFF" bordercolordark="#FFFFFF"> <tr> <td valign="top"> <form> <p style="margin-top: 0; margin-bottom: 0"> <font face="Verdana" size="2">Current URL: </font> <input type="text" name="curl" size="75" readonly="true" value=curl disabled="yes" ></p> </form> <p style="margin-top: 0; margin-bottom: 0"> </p> <p style="margin-top: 0; margin-bottom: 0"> <font face="Verdana" size="2">This is an index test</font></td> </tr> </table> </div> </html> Quote Link to comment Share on other sites More sharing options...
ranjuvs Posted December 23, 2008 Share Posted December 23, 2008 $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; Quote Link to comment Share on other sites More sharing options...
Yesideez Posted December 23, 2008 Share Posted December 23, 2008 Just run this little script somewhere on your page to see everything that is vbeing populated and what with - handy for debugging: <?php $crlf=chr(13).chr(10); $br='<br />'.$crlf; $p='<br /><br />'.$crlf; foreach ($_SERVER as $key => $datum) { echo $key.' : '.$datum.$br; } echo $p; ?> This dumps everything in $_SERVER[] with its values. Quote Link to comment Share on other sites More sharing options...
starscream.pt Posted December 23, 2008 Author Share Posted December 23, 2008 Ok i managed to get the url grab working, now, how exactly do i make it appear in the form box? This is waht i made, a separate php file called curl.php which will be included in the index.php curl.php <?php if(!isset($pageURL)) $pageURL ="http://"; $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; ?> index.php <head> <meta http-equiv="Content-Language" content="pt"> </head> <?php include "menu.php"; ?> <?php include "curl.php"; ?> </body> <body bgcolor="#C0C0C0"> <div align="center"> <table border="0" width="70%" height="100%" id="index_table" bgcolor="#B5CCFE" bordercolorlight="#FFFFFF" bordercolor="#FFFFFF" bordercolordark="#FFFFFF"> <tr> <td valign="top"> <form> <p style="margin-top: 0; margin-bottom: 0"> <font face="Verdana" size="2">Current URL: </font> <input type="text" name="curl" size="75" readonly="true" value=$pageURL disabled="yes" ></p> </form> <p style="margin-top: 0; margin-bottom: 0"> </p> <p style="margin-top: 0; margin-bottom: 0"> <font face="Verdana" size="2">This is an index test</font></td> </tr> </table> </div> </html> Thanks in advance! Quote Link to comment Share on other sites More sharing options...
Yesideez Posted December 23, 2008 Share Posted December 23, 2008 <input type="text" name="curl" size="75" readonly="true" value="<?=$pageURL?>" disabled="yes" ></p> That what you're after? Quote Link to comment Share on other sites More sharing options...
Yesideez Posted December 23, 2008 Share Posted December 23, 2008 Try this: $pageURL = 'http://'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];?> I can't see why you're using the if() there because you're always wiping the value out with the line above. Quote Link to comment Share on other sites More sharing options...
starscream.pt Posted December 23, 2008 Author Share Posted December 23, 2008 where do i put taht code? ion the curl.php? i used if to set the variable some value otherwise i keep getting variable undifined error Quote Link to comment Share on other sites More sharing options...
Yesideez Posted December 23, 2008 Share Posted December 23, 2008 Your current code: <?php if(!isset($pageURL)) $pageURL ="http://"; $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; ?> The if() is only valid for this: $pageURL ="http://"; If $pageURL contains anything before that you'll always be appending the server info onto the end of whatever is already there. Quote Link to comment Share on other sites More sharing options...
starscream.pt Posted December 23, 2008 Author Share Posted December 23, 2008 <input type="text" name="curl" size="75" readonly="true" value="<?=$pageURL?>" disabled="yes" ></p> That what you're after? yes! that is what i'm after, but somehow i cant get it to work on the field value :\ at least the way you put it there Quote Link to comment Share on other sites More sharing options...
starscream.pt Posted December 23, 2008 Author Share Posted December 23, 2008 i did it!!!! this is the correct code, curl.php must be included on top, then to display the link in the form goes like this: <input type="text" name="curl" size="75" readonly="true" value="<?php print $pageURL; ?>" disabled="yes" ></p> Quote Link to comment Share on other sites More sharing options...
redarrow Posted December 23, 2008 Share Posted December 23, 2008 side note. Hope people understand these built in server functions are not reliable. Using the path name and server name are more reliable. $_SERVER["SERVER_NAME"] $_SERVER["REQUEST_URI"] Quote Link to comment Share on other sites More sharing options...
starscream.pt Posted December 23, 2008 Author Share Posted December 23, 2008 i hope this works, i'll tell you why i needed this. my webpage will be redirected from another domain, sometimes a page needs to be copied and all i got on the address bar is the redirection name so ... really hope this url thing works, well it works localy and im happy with it! Quote Link to comment Share on other sites More sharing options...
starscream.pt Posted December 23, 2008 Author Share Posted December 23, 2008 yes it works server wise!!! check it out: http://wheeljack.pt.vu (just removed the redirection to the old site so no point clicking) address displayed on the box is the real address! TOPIC SOLVED!! Thank you guys!! 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.