Lamez Posted August 18, 2008 Share Posted August 18, 2008 Question 1: I am working on a external link checker, but If the user does not add a protocol like http:// or ftp:// or something like that how can I add it to the beginning of the URL? Example: -User input: www.google.com -Code Added: http://www.google.com Question 2 How can I find the address the user came from? -Thanks guys! Quote Link to comment Share on other sites More sharing options...
unsider Posted August 18, 2008 Share Posted August 18, 2008 1. <?php $form = array('url'); if ($form['url'] != '' && strpos(strtolower($form['url']), 'http://') !== 0) $form['url'] = 'http://'.$form['url']; ?> 2. php referrals - google a script or something Quote Link to comment Share on other sites More sharing options...
Lamez Posted August 18, 2008 Author Share Posted August 18, 2008 I am sorry, but the code you gave me does not echo anything out. Here is how I integrated it. <?php $url = htmlspecialchars($_GET["url"]); $form = array($url); if ($form['url'] != '' && strpos(strtolower($form['url']), 'http://') !== 0) $form['url'] = 'http://'.$form['url']; $url = $form['url']; if (!isset($_GET["url"])){ header("Location: http://www.krazypicks.com"); }else{ echo "<center>You are about to leave KrazyPicks! to an external link. <br>Do you want to continue?"; echo "<br>External Link: ".$url."</center>"; ?> Thanks! Quote Link to comment Share on other sites More sharing options...
unsider Posted August 18, 2008 Share Posted August 18, 2008 Sorry bout' that, didn't include the output Well it's good that you took it upon yourself to figure it out. Glad I could help, half way atleast. Quote Link to comment Share on other sites More sharing options...
Lamez Posted August 18, 2008 Author Share Posted August 18, 2008 see that is the thing, I get nothing echoed out! you can test the code here: http://links.krazypicks.com/?url=google.com Quote Link to comment Share on other sites More sharing options...
unsider Posted August 18, 2008 Share Posted August 18, 2008 I am sorry, but the code you gave me does not echo anything out. Here is how I integrated it. <?php $url = htmlspecialchars($_GET["url"]); $form = $url; if ($form != '' && strpos(strtolower($form), 'http://') !== 0) $form = 'http://'.$form; $url = $form; if (!isset($_GET["url"])){ header("Location: http://www.krazypicks.com"); }else{ echo "<center>You are about to leave KrazyPicks! to an external link. <br>Do you want to continue?"; echo "<br>External Link: ".$url."</center>"; ?> Thanks! Try it? The values in the array() shouldn't return anything because they weren't extracted. Should work now. Ugh, man it's 3 am here, and I'm tired. Forgive me for my stupidity. But keep in mind that this quick little fix up will always add http://, it does not interpret the protocol beforehand. Although, I'm not quite sure why you would want to worry about ftp://, etc...? This function should interpret it though, so just incorporate it where necessary. Unless it's for the active protocol only. *shrug* If none of this helped you, I'm sure someone else can. I gotta get some rest, and I'll help you more in the morning if your problem is still unresolved. Good luck. http://us.php.net/manual/en/function.gnupg-getprotocol.php Quote Link to comment Share on other sites More sharing options...
Lamez Posted August 18, 2008 Author Share Posted August 18, 2008 Thank you for that little bit of code, it was exactly what I was looking for. Thanks Again! Quote Link to comment Share on other sites More sharing options...
Lamez Posted August 18, 2008 Author Share Posted August 18, 2008 I thought there was a way to find out where the user came from. Example: User googles my website, but I redirect them back to the google search. Any way? 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.