[web] How to call a link without redirecting a page

Started by
16 comments, last by Mayple 12 years, 9 months ago
Hello,
I have a shortened link, for example like http://bit.ly but I need to find out what url it really is..
I was told I could use javascript to make an asynchronous call to the page and get the header information or something, which will give me the status code if it is redirecting and the actual link..I am newbie, and I don't know wtf that is lmao..
Can someone tell me if there is a way I can get this done with javascript thanks.
Advertisement

Hello, I need to find out what url it really is..


For bit.ly, then append a '+' to the end of the link: http://bit.ly/900913 becomes http://bit.ly/900913+.
For tinyurl.com, use the preview feature: http://tinyurl.com/2tx becomes http://preview.tinyurl.com/2tx.

I was told I could use javascript to make an asynchronous call to the page and get the header information or something, which will give me the status code if it is redirecting and the actual link
You can only make asynchronous requests to the host of the page you're currently viewing, so this won't work.

Is it an option for you to do this server-side, instead of on the client?
@fastcall what does adding a + sign do ?
@Hodgman yeah it has to be on the client side :(
If you want the fast and easy dirty way to do it use PHP and Bit.ly API:

$url = 'url'; // you can use javascript to set this or php to dynamically set it
include('bitly.php'); //api php
$bitly = new bitly('username', 'apikey'); //your username and apikey for the bitly serviceecho
$bitly->expand($url);


-Mayple
I usually just give my 2 cents, but since most of the people I meet are stubborn I give a 1$ so my advice isn't lost via exchange rate.


If you want the fast and easy dirty way to do it use PHP and Bit.ly API:

$url = 'url'; // you can use javascript to set this or php to dynamically set it
include('bitly.php'); //api php
$bitly = new bitly('username', 'apikey'); //your username and apikey for the bitly serviceecho
$bitly->expand($url);


-Mayple

Your method would have been very useful if I could assign a javascript value to a php variable without using a get or post..or is there a way to do that? Because so far I have no idea how to do that



[quote name='Mayple' timestamp='1310295135' post='4833290']
If you want the fast and easy dirty way to do it use PHP and Bit.ly API:

$url = 'url'; // you can use javascript to set this or php to dynamically set it
include('bitly.php'); //api php
$bitly = new bitly('username', 'apikey'); //your username and apikey for the bitly serviceecho
$bitly->expand($url);


-Mayple

Your method would have been very useful if I could assign a javascript value to a php variable without using a get or post..or is there a way to do that? Because so far I have no idea how to do that

[/quote]

you could use ajax and load the php script the background which should make the use of get or post pretty much irrelevant for the end user (Which is all that matters)
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
check out CURL which can call a remote url from your server (php).
create a local php that calls the remote url and returns the result.
call the local php from ajax.
Those are really good ideas, unfortunately It has to be strictly javascript and php
what about the XMLHttpRequest object? can it accomplish what i want without reloading the page?

[quote name='Elyas_321' timestamp='1310332080' post='4833459']
[quote name='Mayple' timestamp='1310295135' post='4833290']
If you want the fast and easy dirty way to do it use PHP and Bit.ly API:

$url = 'url'; // you can use javascript to set this or php to dynamically set it
include('bitly.php'); //api php
$bitly = new bitly('username', 'apikey'); //your username and apikey for the bitly serviceecho
$bitly->expand($url);


-Mayple

Your method would have been very useful if I could assign a javascript value to a php variable without using a get or post..or is there a way to do that? Because so far I have no idea how to do that

[/quote]

you could use ajax and load the php script the background which should make the use of get or post pretty much irrelevant for the end user (Which is all that matters)
[/quote]


<?php
if (1==1)
{
?>
<script language="JavaScript">
bitlyURL = INPUT METHOD; // use this to assign your bitly url, add either a form, a post, a get, anything you want. a document write maybe?
urlString = "bitly.php?var=" +bitlyURL;
window.location = urlString;

</script>
<?php
$url = $_GET["bitlyURL"];
$bitly = new bitly('username', 'apikey'); //your username and apikey for the bitly serviceecho
$bitly->expand($url);
}
?>


[color="#000000"]Above is very rough, but should put you in the right direction.
-Mayple
I usually just give my 2 cents, but since most of the people I meet are stubborn I give a 1$ so my advice isn't lost via exchange rate.

This topic is closed to new replies.

Advertisement