kigoe Posted August 17, 2006 Share Posted August 17, 2006 I've got a rather simple script for links, where all my links point to a single PHP page (I'll call it the link redirection script), which then redirects users to the intended link (definened in the variable [b]link[/b]) and records their passage in a MySQL database, so I can see which links are the most popular. This has, up until this point, worked quite well; the structure is such:[code]http://mydomain.com/link.php?e=i&link=index.php[/code]where [b]e[/b] indicates an external or internal link and [b]link[/b] indicates the intended URL (in the above case, relative to the root directory, since its an internal link).However, I run into problems when I try to specify a link to another PHP page [i]with variables defined in the inteneded URL[/i]. For instace, if I were to link to [b]index.php?foo=bar&user=happy[/b], or something, the link would look like this:[code]http://mydomain.com/link.php?e=i&link=index.php?foo=bar&user=happy[/code]PHP then interprets this link as contating more variables for use by the link redirection script, and sends me to the page [b]index.php?foo=bar[/b], leaving out the subsequent [b]&user=happy[/b] or any other variables defined afterward.Is there any way for me to write this link so that only the [b]e[/b] and [b]link[/b] variables are used by the link redirection script, and the [b]foo[/b] and [b]user[/b] variables are ignored -- until they get to the intended PHP page?thanks!-nik Quote Link to comment Share on other sites More sharing options...
trq Posted August 17, 2006 Share Posted August 17, 2006 A better way would be to store the actual links (addresses) in a database, then just have your links pass an id to your script which loads the url from the database and does the redirect. Quote Link to comment Share on other sites More sharing options...
kigoe Posted August 17, 2006 Author Share Posted August 17, 2006 eh - too tedious for me. that requires a) inserting every link I want to use into the database and b) pulling these ids everytime I want to link to something. I could make a page with, say, a short form to add links above and a list of all links and their ids below, for reference, but simply making them and looking them up seems a bit overly tedious.thanks for the suggestion, though. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted August 17, 2006 Share Posted August 17, 2006 what you need to do is replace those characters in the url to be directed to. A browser would recognize as a variable by the &x=y.So replace & with somthing trivial like || and = with |so your link would look like thishttp://mydomain.com/link.php?e=i&link=index.php?foo|bar||user|happyThen in your redirection page you can do this....$find = array('/\|\|/','/\|/');$rep = array('&','=')$link = pregreplace($find,$rep,$_GET['link']);This would yield:$link = 'index.php?foo=bar&user=happy';you may even want to do similar with the '?' in the link variable.... Quote Link to comment Share on other sites More sharing options...
HeyRay2 Posted August 17, 2006 Share Posted August 17, 2006 You make a database call to record that a link was clicked.How much harder is it to do one more query right below the first and grab that same record, grab the URL and make a [b]header()[/b] call to it. ???Doesn't sound like that much more work. 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.