Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Self-referencing a webpage using php

  • 10-03-2005 06:44PM
    #1
    Closed Accounts Posts: 38


    I'm extracting the contents of the keyword meta tag in current document and saving it to a variable as follows:

    // This extracts the house name from the keywords meta tag
    // and inserts it into a variable ($housename)
    // for use in the subject line of the enquiry form
    $meta_tags = get_meta_tags('current-document-name.php');
    //echo "The name of the house is {
    $housename = $meta_tags[keywords];

    I then dynamically write the contents of the resulant variable into the subject line of a form as follows:

    <input type="hidden" name="subject" value="<?php echo $housename . " enquiry";?>" />
    This works perfectly if I know the name of the file (current-document-name.php), but what if I don't. How do I reference the current document filename from within itself?
    I've googled and ransacked the php manuals but to no avail.

    Any ideas? :confused:


Comments

  • Registered Users, Registered Users 2 Posts: 68,173 ✭✭✭✭seamus


    use $PHP_SELF as your document name.


  • Registered Users, Registered Users 2 Posts: 654 ✭✭✭DS


    $_SERVER


  • Closed Accounts Posts: 38 PixelPixie


    seamus wrote:
    use $PHP_SELF as your document name.

    I can't use $PHP_SELF as the document name as it is a template document that will be used to create other documents (for a CMS solution).


  • Closed Accounts Posts: 38 PixelPixie


    DS wrote:
    $_SERVER

    I did come across this, DS, but thought it would only work if I was using it in a form (for submission to itself).
    I'll have a go and see.
    Thanks


  • Closed Accounts Posts: 38 PixelPixie


    PixelPixie wrote:
    I did come across this, DS, but thought it would only work if I was using it in a form (for submission to itself).
    I'll have a go and see.
    Thanks

    I'm getting the following error:

    get_meta_tags(/current-document-name.php): failed to open stream: No such file or directory in [path from server root] on line xx.


  • Advertisement
  • Closed Accounts Posts: 38 PixelPixie


    PixelPixie wrote:
    I'm getting the following error:

    get_meta_tags(/current-document-name.php): failed to open stream: No such file or directory in [path from server root] on line xx.

    I've solved the problem as follows:

    $path_parts = pathinfo($_SERVER);
    $currentfile = $path_parts;
    $meta_tags = get_meta_tags($currentfile);
    $housename = $meta_tags[keywords];

    Thanks for your input.
    :)


Advertisement