Jump to content
Hak5 Forums

Recommended Posts

Hoi!

So, I've been looking more into PHP and I'm really into the idea of integrating webpages and server code. Obviously, possibilites are quite endless, but I'm more into the idea of configuring and executing from a webpage. For example, if I ran a website on a Pi (or even my phone) then I could have buttons on the website that did things like change the IP of the device, launch an app or a service and view RAM/CPU usage. The fun stuff.

So I really want to get into some fast-learning-curve PHP applications but not sure where to start. I've been having a look around for lightweight frameworks (I prefer lightweight so it can run on minimal resources smoothly) but many seem too hard for the time I have on my hands. I'm kinda learning in-between day-to-day work, so nothing "wall-of-texty". ? 

Anyone got any recommendations or even example code of where I could get started?

I know some readers may cry when they read that I have had minimal dealings with PHP...I've edited it before (more specifically, edited HTML embedded in it, ha), but I've never written it from scratch.

Share this post


Link to post
Share on other sites
Posted (edited)

Well, I started working with PHP before the frameworks came out. So I am a bit biased when it comes to using frameworks (I hate them lol). But you might want to take a look at the following PHP function:

http://php.net/manual/en/function.shell-exec.php
 

This allows you to run a shell command, and it will return the results that you then can integrate in the page. ?

You better secure that page very well though ?

EDIT: Also here is a good example and explanation of the shell-exec and exec functions:

https://stackoverflow.com/questions/7093860/php-shell-exec-vs-exec

Edited by GrineUlf

Share this post


Link to post
Share on other sites
On ‎5‎/‎29‎/‎2018 at 1:19 AM, Dave-ee Jones said:

if I ran a website on a Pi (or even my phone) then I could have buttons on the website that did things like change the IP of the device, launch an app or a service and view RAM/CPU usage.

Regarding the above, just wanted to clarify; why use PHP? It appears you want to create and use a HTML GUI client-side, but PHP is a server-side language.

You'd probably be better with a client-side language such as JavaScript, VBScript, etc.

Share this post


Link to post
Share on other sites
On 6/9/2018 at 12:30 AM, haze1434 said:

Regarding the above, just wanted to clarify; why use PHP? It appears you want to create and use a HTML GUI client-side, but PHP is a server-side language.

You'd probably be better with a client-side language such as JavaScript, VBScript, etc.

It would use front-end script like HTML/Java but that script would run PHP script on the server. JavaScript doesn't really allow you to change stuff on the client because of security reasons, obviously. Not sure about VBS though.

Share this post


Link to post
Share on other sites

VBScript can do both client side and server side scripting if you use something like ASP. But ASP is... not great imo.

You could exercise/develop your software development skills by using creating a responsive front-end using something like Angular or AngularJS, and writing a back-end to connect to in PHP or Go, or any language really. Would give an opportunity to practice high cohesion and low coupling.

Eitherway, I'd suggest just using AJAX if you're not interested in using any frameworks.

Share this post


Link to post
Share on other sites
Posted (edited)
On 6/12/2018 at 11:06 AM, Foxtrot said:

You could exercise/develop your software development skills by using creating a responsive front-end using something like Angular or AngularJS, and writing a back-end to connect to in PHP or Go, or any language really. Would give an opportunity to practice high cohesion and low coupling.

I had a brief look at AngularJS, and it looks alright but I don't think I'll dig into it.

I'm currently making a NAS-like GUI and I'm trying to figure out how I would reference a file (video, mp3, photo etc) that's in another folder.

For example, my web files are hosted in "this/is/a/directory/www", but I want to load videos, images and music from "this/is/a/directory/users/<user>/" (where each user has their own files). I've created a handler php script that handles GET requests like so:

# User wants to access "this/is/a/directory/users/fred/video.mp4"
URL: this/is/a/directory/www/video.php?user=fred&file=video.mp4

The handler file has this in it (I have a handler file for each file type - video, music, photo - I'm lazy):
*Bear in mind the handler script is located in "this/is/a/directory/www/handler/", that's why there's 2 sets of "...". Correct me if it doesn't need 2 sets.

<?php
	header('Content-type: video/mp4');
	if ($_SESSION["USERNAME"] == $_GET['user']) { # Yes, I'm using SESSION-based user control access
		readfile("../../users/".$_GET['user']."/".$_GET['file']);
	}
?>

But it doesn't seem to be working. It can grab the name of the file easily (which means the server-side script can see the file), but it won't show the contents of the file on the page (which means that the server-side code isn't passing the information to the client-side code).

I knew I couldn't reference it with client-side code so I was trying to get the server-side code to pass it through, like any other website does with their videos and stuff, but it ain't workin'.

Any ideas?

Edited by Dave-ee Jones

Share this post


Link to post
Share on other sites
Posted (edited)

I figured it out. I forgot to start the session on the page which meant $_SESSION was empty.

Whoops. ?

It's working quite nicely now ? My phone is now a baby NAS.

Edited by Dave-ee Jones
  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×