0

Is that possible to find the location of a specific code using a web browser?

I am using an open source script and i want to edit some parts of the code but i am unable to find the location.

for example, in the image below you can see the div i want to find. I want to find the copyright section location inside the script.

enter image description here

2
  • Click on the tiny arrow head to open that div tag. You can use Ctrl+F to find text.
    – Biswapriyo
    Aug 5, 2017 at 8:27
  • I want the file location, where to find the file in the website folder.
    – csandreas1
    Aug 5, 2017 at 9:19

1 Answer 1

2

Is [it] possible to find the location of [...] specific code using a web browser?

The contents of a Web page are often copies of data directly from a file but are also often a synthesis of things.

If your browser downloads all the files used to represent something in-browser, it may be possible to locate code (at least on your computer).

If your browser doesn't download all the files (as is the case with scripts since the end user is only sent the output of that script), then you often cannot.

I want the file location, where to find the file in the website folder.

URL structures are not the same as directory structures and are often not representative of the actual underlying layout of files.

That isn't to say that you may not be able to get some idea of where a file is located, but again, with browsers, you are relying on the server output in a similar manner to scripts.

For example, in a web page, you might have:

<link rel="stylesheet" type="text/css href="some/directory/mystyle.css">

while in the server configuration you have:

ProxyPass "/some/directory"  "http://www.example.com/"
ProxyPassReverse "/some/directory"  "http://www.example.com/"

In this case, any requests which start with the /some/directory path will be proxied to "http://www.example.com/". These requests only pass through the server and the files requested aren't even likely on it.

I am using an open source script and I want to edit some parts of the code but I am unable to find the location [of what I wish to edit].

Open source projects are handy because you can download a copy of a program or script and examine that code.

In this case, you don't need to mess with the server since you can download a copy of phpBB yourself. If it is an older version, you may need dig around the net a little.

Likewise, the Green Style theme can also be obtained for examination.

For example, in the image below you can see the div I want to find. I want to find the "copyright" section location inside the script.

Looking at the source code, we find that themes are kept in a directory called "styles".

Using tools similar to grep, we can search for the text "copyright" in our source code. Importantly, grep-like utilities often have the ability to display the source files in which matches were found.

For example, a search with GNU grep might look like:

grep -w "copyright" path/to/file/direct -d recurse

which would output e.g:

path/to/file/direct/subdir/exact.file: some line with copyright in it

We discover that "copyright" appears in several files under the "styles" directory:

  • license.txt
  • style.cfg
  • colour.css
  • common.css
  • print.css
  • overall_footer.html

We can discard license.txt and, doing a bit of research, we discover style.cfg is just for giving general information about the style itself (not what is actually displayed).

So the files that seem to control the "copyright" style class directly are:

  • colour.css
  • common.css
  • print.css

Examining the last file, overall_footer.html, we find that "class=copyright" appears above a block of code that has the substitution {CREDIT_LINE}, which seems like it could be the substitution for the actual credit text.

This particular text does not appear elsewhere in the "styles" folder, so expanding out with our grep-like utility, we find {CREDIT_LINE} appears in functions.php and functions_acp.php, where it holds the actual code for printing the default credit text.

In total, these files control the look of the copyright.

Note: The total number of files matched in this section is, in reality, a bit more than listed but all were pretty easy to discard based on common sense.

Can I Change This?

For styling, you could alter the .css files.

For text, you can replace the {CREDIT_LINE} substitution in overall_footer.html with your own text (which is likely preferable to altering the default text in the function).

Note that overall_footer.html appears in a few places: the "adm" directory (which controls the administrative control panel look) and the "styles" directory for each individual style. Thus if you do choose to simply replace {CREDIT_LINE}, you may need to alter multiple files.

As a small caveat, phpBB caches files so to see any footer alterations you need to:

  • Go to the administrative control panel and under the General tab and select "Purge the cache".

  • Refresh any active pages.

Note you may also need to clear your browser cache as well.

Getting grep

There are many versions of grep and grep-like utilities to choose from. Many are OS dependent, but you will almost always have multiple choices.

If you are are on a roughly Unix-like system (e.g. Linux, Mac, FreeBSD), then a version of grep is likely already available to you from the command line.

If you are on Windows, personal suggestions include the GNUWin32 build of grep for a command line utility or if you prefer a GUI, AstroGrep, which is a nice grep-like program. Note that you can install both if you wish.

4
  • i didn't get you, how you discovered that copyright appears in 6 files? Grep link, links to green theme
    – csandreas1
    Aug 6, 2017 at 8:39
  • Sincerest apologies. Corrected the link to the Wikipedia entry. Grep is a utility to search through plain-text data for particular strings. Grep-like utilities often have the ability to display the files names in which the matches were found. Aug 6, 2017 at 8:43
  • how should i install grep?
    – csandreas1
    Aug 6, 2017 at 10:27
  • If you're on a roughly Unix-like system (e.g. Linux or Mac), a version of grep should already be available via the command line. If you are on a Windows system, my suggestion would be either GNUWin32 grep (if you want a command line program) or, if you are lazy like me and like GUI programs ;-) AstroGrep - - astrogrep.sourceforge.net (note you can have both if you like). Aug 6, 2017 at 10:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .