View Full Version : passing variables in a a url
earthman
01-02-2007, 10:34 AM
Hello again,
Ive never had a problem before sending variables through a link eg...
www.mydomain.com/target.php?X=n&Y=n
For some reason on monster this doesnt work, eg on the target page X and Y are not recognised.
Any reason for this? Is there something i need to activate to allow passing of variables in urls?
Please help, this is quite critical to the operation of my site!
Cheers
McCoy
01-02-2007, 10:52 AM
In hostmonster, register_globals is disable for PHP.
This is in order of security as I explained in this post:
http://www.hostmonsterforums.com/showpost.php?p=2192&postcount=5
So use the superglobals $_GET to get access X and Y passed by the url, i.e.
$x = $_GET['x'];
$y = $_GET['y'];
earthman
01-02-2007, 11:15 AM
Yes I feared that would be the solution.
The problem is that the way my site works it would make it near enough impossible.
On each page there are 60 links each with different values of X and Y that all go to the same target page.
eg
www.mydomain.com/target.php?X=2&Y=3
www.mydomain.com/target.php?X=2&Y=4
www.mydomain.com/target.php?X=2&Y=5
etc etc.
The target page repsonds only to X and Y in a coordinate type system.
Any suggestions?
McCoy
01-02-2007, 11:30 AM
just put at the very start of your script:
$x = $_GET['x'];
$y = $_GET['y'];
And from that moment you'll have $x and $y available for the rest of the script.
If you need to use them inside functions or something maybe you'll need to make them global, but that's all.
earthman
01-02-2007, 11:59 AM
cheers.
completely confused myself. never used $GET before, obviously it goes in the target page, not the sender page!
Sorted.
McCoy
01-02-2007, 12:12 PM
Great!
And now you can sleep well knowing that your page is more secure ;)
vBulletin® v3.7.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.