Larry101 Posted May 14, 2011 Share Posted May 14, 2011 Hi if the URL is http://www.domain.com/?somedata how would I get "somedata" into a variable? Link to comment https://forums.phpfreaks.com/topic/236426-get-data-from-url/ Share on other sites More sharing options...
Insecure Posted May 14, 2011 Share Posted May 14, 2011 Lets say you have: http://www.domain.com/?x=value In your script you can do: $x = $_GET['value']; Link to comment https://forums.phpfreaks.com/topic/236426-get-data-from-url/#findComment-1215513 Share on other sites More sharing options...
Larry101 Posted May 14, 2011 Author Share Posted May 14, 2011 Lets say you have: http://www.domain.com/?x=value In your script you can do: $x = $_GET['value']; Thanks Insecure but there is no variable in the URL so I cant use the $_GET[] function. Link to comment https://forums.phpfreaks.com/topic/236426-get-data-from-url/#findComment-1215515 Share on other sites More sharing options...
MrSean Posted May 14, 2011 Share Posted May 14, 2011 Lets say you have: http://www.domain.com/?x=value In your script you can do: $x = $_GET['value']; Not quite. $x = $_GET['x']; echo $x; //Output: value Link to comment https://forums.phpfreaks.com/topic/236426-get-data-from-url/#findComment-1215516 Share on other sites More sharing options...
Insecure Posted May 14, 2011 Share Posted May 14, 2011 @MrSean: Lol oops typo thanks for catching that... I'm not sure how well this will work, but how about trying this? $queryString = $_SERVER['QUERY_STRING']; echo "Query: " . $queryString; Will that get the result? Link to comment https://forums.phpfreaks.com/topic/236426-get-data-from-url/#findComment-1215518 Share on other sites More sharing options...
Larry101 Posted May 14, 2011 Author Share Posted May 14, 2011 @MrSean: Lol oops typo thanks for catching that... I'm not sure how well this will work, but how about trying this? $queryString = $_SERVER['QUERY_STRING']; echo "Query: " . $queryString; Will that get the result? Thanks again Insecure... that did work!! Link to comment https://forums.phpfreaks.com/topic/236426-get-data-from-url/#findComment-1215519 Share on other sites More sharing options...
QuickOldCar Posted May 14, 2011 Share Posted May 14, 2011 I see the link was on your own server, but if it wasn't.... If the url contains multiple unknown queries or not a link on your server, you can do this. Grabs just the query, and also finds how many queries, and separates the queries and values. <?php $url = "http://www.youtube.com/watch?v=3fumBcKC6RE&feature=topvideos_music"; $url = trim($url); //add http:// if is not present if (substr($url, 0, 5) != "http:") { $url = "http://$url"; } $query_parse = parse_url($url, PHP_URL_QUERY); $query_chunk = ltrim($query_parse, "?"); $query_array = explode("&", $query_chunk); $query_number = 0; foreach($query_array as $value_chunk){ $query_number = $query_number +1; $query_value_array = explode("=", $value_chunk); $query_value[] = $query_number."|".$query_value_array[0]."|".$query_value_array[1]; } //the complete query echo $query_chunk."<br />"; //queries array foreach($query_value as $query_results){ $results = explode("|", $query_results); $number = $results[0]; $query = $results[1]; $value = $results[2]; echo "<b>$number: Query: </b>".$query."<b>Value: </b>".$value."<br />"; } ?> Link to comment https://forums.phpfreaks.com/topic/236426-get-data-from-url/#findComment-1215525 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.