Jump to content

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.

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.