Obtain Variables from URL
Moderator: General Moderators
Obtain Variables from URL
Hi all,
Does anyone know how php can get this data (myid) from the URL...
Example 1: mydomain.com/myid
I am aware that if I wrote the URL 'mydomain.com/?id=myid' I could GET the variable 'id' using the $_GET statement but how do I get myid from example 1?
Thanks in advance.
Larry.
Does anyone know how php can get this data (myid) from the URL...
Example 1: mydomain.com/myid
I am aware that if I wrote the URL 'mydomain.com/?id=myid' I could GET the variable 'id' using the $_GET statement but how do I get myid from example 1?
Thanks in advance.
Larry.
Last edited by lazersam on Thu May 12, 2005 3:26 am, edited 1 time in total.
Hmmm.. no that didn't work. I am experimenting with reading the URL and then spliting the address - the only problem is that the data is not included in the URL I have retrieved...
The $referred_from is not picking up the 'myid' data!
Any ideas?
Larry.
Code: Select all
<?php
//HTTP_REFERRER = "mydomain.com/test.php/myid"
$referred_from = $HTTP_REFERER;
$parsed = parse_url("$referred_from");
print_r($parsed);//prints Array ( [scheme] => http [host] => mydomain.com [path] => /test.htm )
?>Any ideas?
Larry.
what about this
Code: Select all
$elements = split("/", $referred_from);
array_reverse($elements);
echo $elements[0];Thanks pimptastic... but that didn't work. The problem I am having is that I cannot bring the data part of the URL into a string. Whenever I try to caputre the URL I get the entire string except the data at the end for some strange reason....
This is the string... 'mydomain.com/test.php/myid' but the 'myid' part is always missed out. Even the HTTP_REFERER and parse_url function cuts it off(??)
I am able to retract the URL into a string variable BUT the data part (i.e. myid) is always missing from the string. If I can figure out how to bring the entire URL into a string then the problem is solved.
This is becoming a bigger issue then I first thought
Can anyone help?
This is the string... 'mydomain.com/test.php/myid' but the 'myid' part is always missed out. Even the HTTP_REFERER and parse_url function cuts it off(??)
I am able to retract the URL into a string variable BUT the data part (i.e. myid) is always missing from the string. If I can figure out how to bring the entire URL into a string then the problem is solved.
This is becoming a bigger issue then I first thought
Can anyone help?
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Never trust HTTP_REFERER. There is browsers out there that do not pass on that variable, among others.
Run this:
Check out some of the variables listed in that array dump.
Run this:
Code: Select all
echo '<pre>';
print_r ($_SERVER);
echo '</pre>';Hi d11wtq
I am writing a script that allows users to shorten their affiliate URL's by using my domain name with their username. Visitors would use the shortend version of the URL, bounce into my script and be re-directed to the users URL.
So, 'www.TheirAffiliateLink.com/whatever.php/?id=theirid' could be shortend to 'mydomain.com/TheirUsername'. My script would need to disect the URL and identify the data 'TheirUsername'. The problem is that I would like the URL to be 'mydomain.com/TheirUsername' rather than 'mydomain.com/?id=TheirUsername' - BUT I am unable to isolate the data 'TheirUsername' from the URL string as functions are failing to pick it up. As mentioned above, even HTTP_REFERER and parse_url do not bring it into my string variables.
I hope this helps
Larry.
I am writing a script that allows users to shorten their affiliate URL's by using my domain name with their username. Visitors would use the shortend version of the URL, bounce into my script and be re-directed to the users URL.
So, 'www.TheirAffiliateLink.com/whatever.php/?id=theirid' could be shortend to 'mydomain.com/TheirUsername'. My script would need to disect the URL and identify the data 'TheirUsername'. The problem is that I would like the URL to be 'mydomain.com/TheirUsername' rather than 'mydomain.com/?id=TheirUsername' - BUT I am unable to isolate the data 'TheirUsername' from the URL string as functions are failing to pick it up. As mentioned above, even HTTP_REFERER and parse_url do not bring it into my string variables.
I hope this helps
Larry.
Here is a recent post with some info to back that suggestion up:Sami wrote:Never trust HTTP_REFERER.
viewtopic.php?t=33296
Sami... thanks for that. If I run
then the data part of the URL is recovered. That's what I wanted 
Larry.
Code: Select all
$data1 = $_SERVER['PATH_INFO'];Larry.
trying to do whathttp://www.tinyurl.comdoes?