Jump to content

2 Questions, Just finding the correct functions


Lamez

Recommended Posts

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!

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!

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

 

Archived

This topic is now archived and is closed to further replies.

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