mosey Posted August 17, 2007 Share Posted August 17, 2007 Hi I'm a bit stuck on this and would really appreciate some help! The visitor comes to the site via a 'personalised' value - http://www.mysite.com/?384 as I would like to be able to 'track' the user using this value (348) so need to extract this data for later. I am able to print out the /?384 part using $REQUEST_URL, but when I try and write it to a log file (or send using the mail() function) it doesnt' seem to work. The code I'm using for writing to log is simply: $entry_line = "Username: $username | ID: $REQUEST_URL \n"; $fp = fopen('logs.txt', 'a'); fputs($fp, $entry_line); fclose($fp); I also tried defining: $number = str_replace("/?", "", $REQUEST_URL); to see if I could just log the variable $number, but to no avail as it remains blank. Thanks in advance for any help! Quote Link to comment https://forums.phpfreaks.com/topic/65436-solved-extract-data-from-url/ Share on other sites More sharing options...
LiamProductions Posted August 17, 2007 Share Posted August 17, 2007 try storing $REQUEST_URL in a variable. Quote Link to comment https://forums.phpfreaks.com/topic/65436-solved-extract-data-from-url/#findComment-326760 Share on other sites More sharing options...
MadTechie Posted August 17, 2007 Share Posted August 17, 2007 $entry_line = "Username: $username | ID: {$_SERVER['REQUEST_URI']} \n"; I not L note $_SERVER['QUERY_STRING'] $entry_line = "Username: $username | ID: {$_SERVER['QUERY_STRING']} \n"; is the correct one to use Quote Link to comment https://forums.phpfreaks.com/topic/65436-solved-extract-data-from-url/#findComment-326762 Share on other sites More sharing options...
lemmin Posted August 17, 2007 Share Posted August 17, 2007 With that URL you suggested, 384 will be a key in the $_GET array. If that will always be the only value passed in the URL you can get it by iterating pretty easy, if there will be more values, you can return all the keys with array_keys. The whole process would be a lot simpler, though, if you put a name for the value being passed like, http://mysite.com/?n=384. Then it is as simple as $_GET['n']. But, whatever works for you. Quote Link to comment https://forums.phpfreaks.com/topic/65436-solved-extract-data-from-url/#findComment-326767 Share on other sites More sharing options...
mosey Posted August 17, 2007 Author Share Posted August 17, 2007 Wow! Thank you all very much for your help! I'm still very new to PHP and these are great tips! Have a great weekend! Quote Link to comment https://forums.phpfreaks.com/topic/65436-solved-extract-data-from-url/#findComment-326806 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.