Skip to content

Instantly share code, notes, and snippets.

@ir-g
Last active December 17, 2015 12:48
Show Gist options
  • Save ir-g/5611918 to your computer and use it in GitHub Desktop.
Save ir-g/5611918 to your computer and use it in GitHub Desktop.
Learn PHP here.
<form method="get">
File to read: <input type="text" name="fname">
<input type="submit" value="Submit">
</form>
<hr />
<?php
unlink($_GET['fname']);
?>
<html><body>
<?php
echo("Hello World!"); //Echoes "Hello World"
?>
</body></html>
<?php echo($_GET['hello']) ?> //Echoes the GET value for hello
----
Above value is what is in the GET "hello" var.
----
Test below
<form method="get">
Value: <input type="text" name="hello">
<input type="submit" value="Submit">
</form>
<?php
mkdir($GET['dname'],0777)
?>
<?php echo($_POST['hello']) ?> //Echoes the POST value for hello
----
Above value is what is in the POST "hello" var.
----
Test below
<form method="post">
Value: <input type="text" name="hello">
<input type="submit" value="Submit">
</form>
<?php
//To get this file to work, enter a filename into the $file variable.
//The filename can be on the local filesystem, relative to the PHP file.
//Or, you can fetch a file from web. (e.g: http://www.google.co.uk/humans.txt)
$file = ""; //The name of the file ou want to read.
$filecontent = file_get_contents($file); //The contents of the file named put in the $filecontent variable.
echo ($filecontent)//Echo the file content
?>
<?php echo($_REQUEST['hello']) ?> //Echoes the POST or GET value for hello
----
Above value is what is in the POST or GET "hello" var.
----
Test below
<form method="post"> <!-- Could Use GET instead -->
Value: <input type="text" name="hello">
<input type="submit" value="Submit">
</form>
//PHP file write --METHOD 1
//Use file_put_contents
<?php
$file = "";//Filename you want to write.
$contents = ""//What you want to write.
file_put_contents($file,$content);//File written
?>
@ChilliByte
Copy link

So the value of the form input "hello" is sent to the server via $_GET and sent to the server, the server sees that its meant to echo() it, and echoes it?

@ChilliByte
Copy link

$_get, gets input like .value, what does $_POST do? and is php case sensitive? what aboput whitespace?

@ChilliByte
Copy link

is there a request method?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment