Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Self-referencing a webpage using php

Options
  • 10-03-2005 6: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 Posts: 68,317 ✭✭✭✭seamus


    use $PHP_SELF as your document name.


  • Registered Users 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