Results 1 to 11 of 11

Thread: Getting the title in the webbrowser?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    190

    Getting the title in the webbrowser?

    I know how to get the URL of what site they're at but not the site title, does anyone know how? This is how I do the URL.

    Code:
    if (!isset($_SERVER['HTTP_REFERER'])) {  
      $url = "Unknown"; 
      }
    else { 
      $url = $_SERVER['HTTP_REFERER']; 
      }

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Getting the title in the webbrowser?

    You will have to load the contents of the URL into an XML document and extract the title element. You must first ensure the Referrer is a url:
    PHP Code:
    if (parse_url($_SERVER['HTTP_REFERER'])) {
        
    $page = new DOMDocument('1.0');
        
    $page->loadHTML(file_get_contents($_SERVER['HTTP_REFERER']));
      
        
    $title $page->getElementsByTagName('title')->item(0)->nodeValue;

    Last edited by visualAd; May 20th, 2007 at 05:50 AM. Reason: Penagates knit picking...
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    190

    Re: Getting the title in the webbrowser?

    This is what I've done:-

    Code:
    if (!isset($_SERVER['HTTP_REFERER'])) {  // Check the url they came from
      $url = "Unknown"; // If no URL then show the words Unknown
      }
    else { 
      $url = $_SERVER['HTTP_REFERER']; // Shows the URL
        $page = new DOMDocument(1.0);
        $page->loadHTML(file_get_contents($url));
      
        $title = $pages->getElementsByTagName('title')->item(0)->nodeValue;
      }
    And where it shows:

    Code:
    ImageString ($back, 5, 170, 100, "$title", $textcolor);
    But it doesn't work.

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Getting the title in the webbrowser?

    It doesn't work? Well without more information I could only speculate on why
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Getting the title in the webbrowser?

    BTW, you have changed the code. I explained that you MUST check the referer is a URL. Otherwise someone could forge the header and have your script open files on the web server instead of the URL
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Getting the title in the webbrowser?

    You should get the message "Call to member function on a non-object". Don't suppress error messages; it makes debugging impossible and wastes your time.

    I think opening the referring URL in such a manner is a bad practice, because it results in double the amount of requests for the server hosting the page containing the image (one from the client, and one from the server hosting the dynamic image).

    Also, the quotes around $title are superfluous, since $title is a string anyway.
    Quote Originally Posted by iamme2007
    ImageString ($back, 5, 170, 100, "$title", $textcolor);

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    190

    Re: Getting the title in the webbrowser?

    When I remove the quotes around the string I get this "The image “http://localhost:2000/stat%20sig/sig.php” cannot be displayed, because it contains errors." thats why its there.

    And I've found a script that can get the page title but I'm having trouble finding the code that does it, the link:-

    http://www.planetsourcecode.com/vb/s...d=356&lngWId=8

  8. #8
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Getting the title in the webbrowser?

    The quotes around the string make NO difference. What error does you script produce, how does it not work?
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  9. #9
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Getting the title in the webbrowser?

    Quote Originally Posted by penagate
    You should get the message "Call to member function on a non-object". Don't suppress error messages; it makes debugging impossible and wastes your time.

    I think opening the referring URL in such a manner is a bad practice, because it results in double the amount of requests for the server hosting the page containing the image (one from the client, and one from the server hosting the dynamic image).

    Also, the quotes around $title are superfluous, since $title is a string anyway.
    Defiantly, you should at the very least be caching the results.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    190

    Re: Getting the title in the webbrowser?

    I've uploaded the complete source, its what I've done so far, I'm new to PHP.

    Can someone see why its giving me the error when I remove the strings from the quotes, also try adding the current site title?
    Attached Files Attached Files

  11. #11
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Getting the title in the webbrowser?

    Why would you want to remove the quotes? You should not have quotes if you are using a single variable. I.e: "$text" is identical to $text.

    If you want someone to do it for you then hire someone. You've been given some example code and some advice on how to do it. So how about you tell us what error you are getting and we go from there?

    Tip: remove the Content-Type header from the top of the script while debugging, so you can see the error messages.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width