Sign in to follow this  
ElyasMachera

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

Recommended Posts

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.

Share this post


Link to post
Share on other sites
[quote name='Elyas_321' timestamp='1310220241' post='4833082']
Hello, I need to find out what url it really is..[/quote]

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

Share this post


Link to post
Share on other sites
[quote name='Elyas_321' timestamp='1310220241' post='4833082']
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[/quote]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?

Share this post


Link to post
Share on other sites
If you want the fast and easy dirty way to do it use PHP and Bit.ly API:

[code]$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);[/code]

-Mayple

Share this post


Link to post
Share on other sites
[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:

[code]$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);[/code]

-Mayple
[/quote]
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


Share this post


Link to post
Share on other sites
[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:

[code]$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);[/code]

-Mayple
[/quote]
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)

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
[quote name='SimonForsman' timestamp='1310332286' post='4833461']
[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:

[code]$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);[/code]

-Mayple
[/quote]
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]


[code]<?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);
}
?> [/code]

[color="#000000"]Above is very rough, but should put you in the right direction.
-Mayple[/color]

Share this post


Link to post
Share on other sites
ok this post is acting all funny

[code]$site = site; // enter the URL for the site http:// included
function bitlyURL($url) {
$headers = get_headers($url, 1);
return $headers['Location'];

}

echo bitlyURL($site);
[/code][font="Arial"]

-Mayple[/font]

Share this post


Link to post
Share on other sites
how is it acting funny? :o
what is the code ^^ doing?

I actually found a way to get the link..but the problem is the XMLHttpRequest
I think it overwrites previous data
for example if i have 2 bitly links only one gets called..the other isn't expanded :S

Share this post


Link to post
Share on other sites
[quote name='Elyas_321' timestamp='1310481965' post='4834321']
I did it! Thanks a lot dude and others who replied.
:)
[/quote]

Awesome job. Did you just assign a basic array for the values coming from the xHTTP?

-Mayple

Share this post


Link to post
Share on other sites
sorry for the late reply..I never get any notifications.
Yeah, I made an async call using xmlhttp to a php file which used the bitly api to expand the link.
then I jsonified lol to a javascript and echoed it.
The callback function in javascript gets called in a json array format..
But it was your bitly api idea that got me started thanks a lot

Share this post


Link to post
Share on other sites
[quote name='Elyas_321' timestamp='1310683068' post='4835461']
sorry for the late reply..I never get any notifications.
Yeah, I made an async call using xmlhttp to a php file which used the bitly api to expand the link.
then I jsonified lol to a javascript and echoed it.
The callback function in javascript gets called in a json array format..
But it was your bitly api idea that got me started thanks a lot
[/quote]


Not a problem :-).

-Mayple

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this