newb question: why php?

Everything related to the visual and coding aspects of websites.
User avatar
Sophia
Posts: 126
Joined: Sun Nov 27, 2016 12:30 pm
Contact:

Wed Dec 07, 2016 8:12 pm

I promise I have done some googling, but still feel a bit lost. (Largely it took me to this robotic anime explanation.) I do notice that most folks around here have their sites coded in PhP. My understanding is that PhP is more about user customization, which doesn't seem obviously in play in shrine making to me, though obviously I am new to this and may be wrong.

Is it because many of you are designers? What is the stronger features that php has over html that you find useful for shrining / personal collectives?

... to be totally honest a smidgen of this is intimidation in learning it. I've wanted to code forever and am looking forward to the challenge, and will probably plod along anyway. Just wondering if anyone had thoughts as to the possible rewards.

RAY GUN SUE

User avatar
Masao
Host
Posts: 589
Joined: Thu Jun 16, 2011 12:29 am
Contact:

Wed Dec 07, 2016 11:11 pm

I think most of us use it for its "dynamic" features, specifically the include/require functions. That way, we can include our "header" and "footer" files and not have to individually change each page whenever there's an edit of the layout.

On our domain collectives, it's not a huge deal, but this can come in really handy if we wanted to change the layout of a 10+ page shrine. We can just edit the header and footer files, and the change will reflect on all the pages that include those files.

Code: Select all

<?php include 'header.txt'; ?>

(html/content of your specific page)

<?php include 'footer.txt'; ?>
and your header and footer files can be:

Code: Select all

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div id="header></div>
<div id="content">

Code: Select all

</div><!-- end #content -->
</body>
</html>
Other benefits include adding conditions so that if something is true, we can specifically code our layout display something. Like how a lot of wordpress blog themes have their current page highlighted through a class="current" in the navigation html, which is dynamically inserted with PHP.

I hope that makes sense :ack:
THE FATE OF DESTRUCTION IS ALSO THE JOY OF REBIRTH.

User avatar
Stefi
Administrator
Posts: 281
Joined: Tue Oct 16, 2012 10:55 pm
Location: WEST COAST BEST COAST
Contact:

Thu Dec 08, 2016 1:09 am

I use PHP for the exact reason Masao gave. I basically just have to go in and edit the header and footer one time if I need to switch the layout or make minor changes.

This is a really good question though! I had been coding for a good couple of years before I was taught the benefits of using PHP. I also didn't understand why at first since it wasn't something I can right click, 'view source' on. If you follow Masao's template though, making the transition is actually really, really easy.

If you do decide to use PHP, just be aware that there are a few vulnerabilities, but they are pretty easy to avoid. For example, using a file.php extension is considered a generally safe practice.

User avatar
Masao
Host
Posts: 589
Joined: Thu Jun 16, 2011 12:29 am
Contact:

Thu Dec 08, 2016 2:15 am

Stefi wrote:If you do decide to use PHP, just be aware that there are a few vulnerabilities, but they are pretty easy to avoid. For example, using a file.php extension is considered a generally safe practice.
Yeah, the one drawback with PHP, since it is a scripting language, is you could go wrong if you follow random really out-of-date tutorials.

Generally though, for the file extensions of your header and footer files, it can be any text file (from .php to .inc or .txt) as long as you don't have any sensitive information, for example, if you were to include a file that had login and password for your database. If you want to keep it private, name the file with a .php, so that your server will interpret the file not as plain text (and display everything), but process it as PHP, so that only want you want to print out, will in fact show.

The other easy vulnerability is if you dynamically include files (like a page.php?name or a page.php?x=name), if you don't check that it's only including files on your server, someone could try to load an external file by typing it in the browser page.php?[insert full url of a malicious file]
THE FATE OF DESTRUCTION IS ALSO THE JOY OF REBIRTH.

User avatar
Lethe
Posts: 1366
Joined: Thu Jul 19, 2012 1:20 pm
Contact:

Thu Dec 08, 2016 4:11 am

(wtf @ robotic anime explanation OMG I DON'T EVEN UNDERSTAND IT)

Yeah, I'm pretty sure the majority of us "only" use PHP as Masao and Stefi described, as it makes our lives easier. 8D /doesn't actually know much about PHP aside from a few snippets...

I hope I'm not derailing the topic, but this might be handy to know for shrines: The dynamic inclusion that Masao mentioned in the last paragraph is something I (and others, I assume) often use so that I don't have to make a new file for each page. I find it easier to keep an overview and edit pages when I only have to load a few files, rather than open a bunch of them, and then I can just search them with ctrl+f.

Say you have a file called section1.php:

Code: Select all

<?php include("header.php"); if (!$_SERVER["QUERY_STRING"]) { ?>

(HTML content of section1.php)

<?php } elseif ($_SERVER["QUERY_STRING"] == "page1") { ?>

(HTML content of section1.php?page1)

<?php } elseif ($_SERVER["QUERY_STRING"] == "page2") { ?>

(HTML content of section1.php?page2)

<?php } include("footer.php"); ?>
That makes three pages in one file. I use it here, for example (note the URLs).

I also include this snippet Masao wrote for me in the footer so that I don't have to manually update the year in copyright notes:

Code: Select all

<?php $y="2016";echo (date('Y')==$y)?($y):($y.'-'.date('Y')); ?>
(2016 here is the start date of a site. Once it's 2017, the snippet on the sites will automatically change to display "2016-2017".)

... Just a few neat things to share. <_< >_>
Both despair and ecstasy are part of the elements that compose a person.

User avatar
Robin
Events Staffer
Posts: 3161
Joined: Thu Aug 07, 2014 3:15 pm
Location: North Carolina, USA
Contact:

Thu Dec 08, 2016 1:37 pm

Joining with the "PHP Includes Layout Brigade," LOL! It helps SO MUCH not to have to include all the layout info on every page, and sometimes I've even used includes to keep files from getting too long as well (such as this type of character page to keep the sidebar content separate from the main content).

Also @Lethe omg that is so cool!
~ a dream is a wish your heart makes ~
withinmyworld.org

User avatar
dubiousdisc
Administrator
Posts: 2602
Joined: Thu Jun 21, 2012 5:49 pm
Contact:

Thu Dec 08, 2016 3:32 pm

Hee hee, I saw this being posted and was like "I'll wait until Masao writes it better than I ever could" and then there it is! Thank you Masao :D

User avatar
Sophia
Posts: 126
Joined: Sun Nov 27, 2016 12:30 pm
Contact:

Thu Dec 08, 2016 4:53 pm

Per usual this has been immensely helpful - thank you so much everyone! I am much more clear on the utility now

RAY GUN SUE

User avatar
Eunice
Posts: 43
Joined: Tue Feb 23, 2016 6:38 am
Location: Wales
Contact:

Mon Dec 12, 2016 6:21 am

Hi Sophia! I still use html. I tend to use php if I'm making a fanlisting as I use Enthusiast, and you have to use php for that. But for a static shrine, I just use html and fiddle about with css.

User avatar
Sophia
Posts: 126
Joined: Sun Nov 27, 2016 12:30 pm
Contact:

Mon Dec 12, 2016 9:49 pm

That's fair Eunice! And probably wise for me, given I've got two HELP ME threads in the coding section. >>

RAY GUN SUE

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 2 guests