Jump to content

[SOLVED] how to php get url


starscream.pt

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/138152-solved-how-to-php-get-url/
Share on other sites

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.

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!

 

curl.jpg

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.

<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

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! :D

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.