Jump to content

Extracting a web address to a variable


unistake

Recommended Posts

Morning all,

 

I am wondering whether there is a way (I am sure there is!) to extract the full website address with any GET variables in it also.

 

Basically, I am trying to extract the website address and add another $_GET['var'] to it.

 

Something like.

 

example web address:  http://www.website.com/index.php?type=abc

<?php
$address = // Extract the current website address here.
$newvar = "?model=123";
$link = $address.$newvar;

echo '<a href="$link">Click here to add a variable</a>';
?>

Link to comment
https://forums.phpfreaks.com/topic/220802-extracting-a-web-address-to-a-variable/
Share on other sites

<?php
$newvar = mysql_real_escape_string($_GET['newvar']);
$home_url = "http://".$_SERVER['HTTP_HOST'];
$url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];

if (!empty($_SERVER["QUERY_STRING"])){
$url .= "?".$_SERVER['QUERY_STRING'];
}
if ($url == "$home_url") {
$url = "$url?$newvar";
}
echo "<a href='$home_url'>Home</a><br />";
echo "<a href='$url'>$url</a><br />";

?>
<form name="input" action="<?php echo $url; ?>" method="get">
New Variable:<input size="30"type="text" name="newvar" style="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #000000;" size="15" value="<?php echo $_GET['newvar']; ?>">
<input type="submit" style="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #000000;" size="15" value="Make New Variable" />
</form>
<?php
echo "Compliments of Quick";
?>

 

And to see in action

http://dynaindex.com/test-new-query

 

You are welome.

 

I used this method in creating a paginated full search/navigation system with multiple selects for mysql.

 

Converting the count to page numbers and a whole lot of math and determining mysqls start row for the selects. Then set max pages to those values.

 

I'd post the code but is so complex would not be usable unless under real circumstances will all the correct parameters set.

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.