Jump to content

Confirm Site Leave


JesseToxik

Recommended Posts

I have been googling for this solution with no luck.

 

I want to create a page on my site that a user goes to when they click a link that will take them off of my site.

The way Facebook does.

 

How can I use PHP to detect if a link is taking someone off of my site, and if so redirect them to a page where they can confirm they wish to leave the site?

I know Facebook uses a URL like so to keep track of the URL.

 

http://site.com/exit.php?url=http://othersite.com

 

Link to comment
Share on other sites

You could send them to a page called exit.php and along with it send a parameter with the new URL, like this: confirm.php?url=http://yahoo.com

 

Then, in exit.php you fetch the url, something like:

$url = $_GET['url'];

echo '<a href="' . $url . '">Click here to leave my website.</a>';

Hope it helps!

 

- W

Link to comment
Share on other sites

@yomanny thats basically what I am looking for, but how can I add to the script to detect if its a link on my site or an external link?

 

@ignance I like your idea but I am trying to use PHP so if it is on mobile(the mobile portion of my site) or a javascript disabled browser it will still work.

Link to comment
Share on other sites

@yomanny thats basically what I am looking for, but how can I add to the script to detect if its a link on my site or an external link?

 

You need to be more specific when you say "on my site". If the user is clicking a favorite for example, you have no way to add the function that you are asking. As for links that are displayed within your site that point to URLs outside your site, YOU have control of the content on your site. You will need to change all those external links from

 

<a href="http://www.anothersite.com">http://www.anothersite.com</a>

 

To

 

<a href="exit.php?url=http://www.anothersite.com">http://www.anothersite.com</a>

Link to comment
Share on other sites

@Psycho I understand that, but let's say I add a forum to my site.

If a user posts a link to an external site, how can PHP detect the link does not link to my site, and automatically converts it from <a href="http://www.anothersite.com">http://www.anothersite.com</a> to <a href="exit.php?url=http://www.anothersite.com">http://www.anothersite.com</a>

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.