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? Quote Link to comment 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']; Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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!! Quote Link to comment 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 />"; } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.