-1

I am using Simple HTML Dom and i am easily get the href link but this is not the actual link it's very long when i click the link it's open on new window and the long url convert into short or real link i want this link please help me how can i get this real link.

Here is the code which i get by using Simple HTML DOM

<a href="/external.php?title=Camp+Massacre&amp;url=aHR0cDovL3ZpZHppLnR2L2Z3eWM4bmZreDJ3eC5odG1s&amp;domain=dmlkemkudHY=&amp;loggedin=1" onclick="return  addHit('1894159921', '1')" rel="nofollow" title="Watch Version 1 of Camp Massacre" target="_blank">Version 1</a>

And after click the link it will load this link on new window and i want this real link.

http://vidzi.tv/fwyc8nfkx2wx.html

1 Answers1

1

First of all, hope I get your meaning, especially "real link".

In your case, the url maybe originally something like http://www.aaa.com/aaa/bbb/ccc/ddd.php?id=1234567890 When you open the page, it becomes http://www.aaa.com/aaa/bbb/ccc/eee.php

This might be because the server redirects you to another page according to your original url. Since this is a server side matter, you, as a client, might be not able to know where you are redirected.

Another possible reason is that the server rewrite your url using .htaccess file. You may get more information from here and here

Regarding to the issue on login, some server reads cookies or keep session variables. You, thus, have to create cookies or session information and send together with you request, so that you can get the "real link".


I think that you are redirected, as mentioned.

Just assume that the base url is http://www.aaa.com When accessing it, you see your the tag. The href contains the value /external.php?title=Camp+Massacre&amp;url=aHR0cDovL3ZpZHppLnR2L2Z3eWM4bmZreDJ3eC5odG1s&amp;domain=dmlkemkudHY=&amp;loggedin=1 You then combine the base url and the href. This, however, cannot give you http://vidzi.tv/fwyc8nfkx2wx.html because you are accessing a php and the server side php program redirects you to the html page.

Regarding to redirecting using php, this might be helpful for your understanding


Suppose that you use AJAX, please see the answer by Matt. He suggests the use of getResponseHeader('Location') and I tried using the following webpages on my wamp server
=====>page_1.html
<html>
    <title>Page 1</title>
    <body>
        <p>This is page 1</p>
        <a href="ext.php" target="_blank">another page</a>
    </body>
</html>

=====>page_2.html
<html>
    <title>Page 2</title>
    <body>
        <p>This is page 2</p>
    </body>
</html>

=====>ext.php
<?php
header('Location: http://localhost/testing/page_2.html');
?>

=====> page_3.html
<html>
    <title>Page 3</title>
    <script>
    function loadXMLDoc(){
        var xmlhttp;
        if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        }else{// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }

        xmlhttp.onreadystatechange = function(){
            alert("Status Text: " + xmlhttp.status + "; " + xmlhttp.statusText);
            alert(xmlhttp.getAllResponseHeaders());

            if (xmlhttp.readyState==4 && xmlhttp.status==200){
                alert("Response text: " + xmlhttp.responseText);
            }
        }
        xmlhttp.open("GET","ext.php",true);
        xmlhttp.send();
    }
    </script>

    <body>
        <p onclick="loadXMLDoc();">load</p>
    </body>
</html>

It is expected that clicking the text "load" in page_3.html results in accessing ext.php, and I would be redirected to page_2.html. According to Matt, if my work is correct, I can get the "Location" attribute from header.

In this case, I use firefox to test it and I can get the html content in page_2.html, but it fails if I use opera. In both cases, I cannot see "Location" attribute from response header, and I believe this would be related to how a server write response headers. That means, again, that it would be a server side matter. Good Luck!

Community
  • 1
  • 1
chunchiu Chan
  • 199
  • 3
  • 14