Jump to content

defining variables in links within other links


kigoe

Recommended Posts

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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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 this

http://mydomain.com/link.php?e=i&link=index.php?foo|bar||user|happy

Then 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....
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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