unistake Posted December 6, 2010 Share Posted December 6, 2010 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 More sharing options...
sweeb Posted December 6, 2010 Share Posted December 6, 2010 You can use _SERVER["QUERY_STRING"] for just the get vars and values, or _SERVER["REQUEST_URI"] to get the filename with vars and values attached Link to comment https://forums.phpfreaks.com/topic/220802-extracting-a-web-address-to-a-variable/#findComment-1143522 Share on other sites More sharing options...
unistake Posted December 6, 2010 Author Share Posted December 6, 2010 ok, I'll give it a go - thanks Link to comment https://forums.phpfreaks.com/topic/220802-extracting-a-web-address-to-a-variable/#findComment-1143523 Share on other sites More sharing options...
donatello Posted December 6, 2010 Share Posted December 6, 2010 I posted an URL extractor script earlier today... here's the thread: http://www.phpfreaks.com/forums/php-coding-help/email-extractor-script/ Link to comment https://forums.phpfreaks.com/topic/220802-extracting-a-web-address-to-a-variable/#findComment-1143577 Share on other sites More sharing options...
sweeb Posted December 6, 2010 Share Posted December 6, 2010 I posted an URL extractor script earlier today... here's the thread: http://www.phpfreaks.com/forums/php-coding-help/email-extractor-script/ This has no relevance to the OP at all... Link to comment https://forums.phpfreaks.com/topic/220802-extracting-a-web-address-to-a-variable/#findComment-1143581 Share on other sites More sharing options...
unistake Posted December 6, 2010 Author Share Posted December 6, 2010 I'll have a go with yours sweeb Link to comment https://forums.phpfreaks.com/topic/220802-extracting-a-web-address-to-a-variable/#findComment-1143739 Share on other sites More sharing options...
QuickOldCar Posted December 7, 2010 Share Posted December 7, 2010 <?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 Link to comment https://forums.phpfreaks.com/topic/220802-extracting-a-web-address-to-a-variable/#findComment-1143767 Share on other sites More sharing options...
unistake Posted December 7, 2010 Author Share Posted December 7, 2010 QOC, Thanks a lot for that - looks neat. I'll add that one to my script collection! Link to comment https://forums.phpfreaks.com/topic/220802-extracting-a-web-address-to-a-variable/#findComment-1143769 Share on other sites More sharing options...
QuickOldCar Posted December 7, 2010 Share Posted December 7, 2010 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. Link to comment https://forums.phpfreaks.com/topic/220802-extracting-a-web-address-to-a-variable/#findComment-1143789 Share on other sites More sharing options...
unistake Posted December 7, 2010 Author Share Posted December 7, 2010 yeah please don't bombard me with maths! Link to comment https://forums.phpfreaks.com/topic/220802-extracting-a-web-address-to-a-variable/#findComment-1143908 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.