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
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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.