Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8399377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:17:20+00:00 2026-06-09T21:17:20+00:00

For example I have a website that points to a page like this: http://www.mysite.com/folder/file

  • 0

For example I have a website that points to a page like this:

http://www.mysite.com/folder/file

How can I get determine /folder so that I can go further an quote an if statement like

if /folder then echo something

Why do I need this?

I am trying to tell facebook which image to pick from a page. Actually I have a pretty simple page structure and the image that facebook should take is always at first but somehow it does choose another one from time to time. I guess because the other images are loaded faster. And the old way to rel=”img_src” doesn’t seem to work anymore as that I could just add it to the wanted image.

So well of course I use the open graph protocol to tell facebook which Image it should use.

I am working with a cms were I can output the path of the image depending on the id the image has. I have two different id’s for the different kind of pages living in two different folders.

This leads to:

if index --> echo meta og for index img
else if /folderone (with id1) --> echo meta og for id1
else if /foldertwo (with id2) --> echo meta og for id2

This is why I need to know the foldername.

Now with the answer I have following setup, just that you know:

<?php $folder = dirname($_SERVER['SCRIPT_NAME']); ?>

<?php if (dirname($_SERVER['SCRIPT_NAME']) == "/") echo "<meta property='og:image' content='http://www.mysite.com/img/img.jpg'/>" ;?>
<?php if (dirname($_SERVER['SCRIPT_NAME']) == "/folderOne") echo "<meta property='og:image' content='http://www.mysite.com/img/{$img_id1}'/> " ;?>
<?php if (dirname($_SERVER['SCRIPT_NAME']) == "/folderTwo") echo "<meta property='og:image' content='http://www.mysite.com/img/{$img_id2}'/> " ;?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T21:17:21+00:00Added an answer on June 9, 2026 at 9:17 pm
    $script = $_SERVER['SCRIPT_NAME'];
    echo dirname($script);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have updated my website. Previously there were links like these: http://example.com/bla-bla-bla?language=de . After
I was already running a sub-website under following path http://example.com/sub-site/ Now, I have created
I have two websites: http://example.com http://example.com/sub I have a page, let's say: http://example.com/sub/page1 Is
Many websites have very good looking pop-up window. For example checkout http://www.myntra.com and when
I have a PHP5/Zend Framework 1.8.1 web site which is located at: http://www.example.com/foo The
I have a websites www.example.com which is a druapal 6 site. Works well, never
I'm building a website which has a page that users can add content to,
I have an example of some code that I see often in websites that
For example, I have a website which has a dynamically-generated segment of its dom
I have 2 websites, lets say - example.com and example1.com example.com has a database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.