Jump to content

[SOLVED] Extract data from URL


mosey

Recommended Posts

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! :D

 

 

Link to comment
https://forums.phpfreaks.com/topic/65436-solved-extract-data-from-url/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.