Add exams from exam58 to exam98
This commit is contained in:
13
exam58/timeStamps.php
Normal file
13
exam58/timeStamps.php
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
//timestamps
|
||||||
|
|
||||||
|
$time = time();
|
||||||
|
$actual_time = date('H:i:s',$time);
|
||||||
|
$actual_date = date('d.m.Y.', $time);
|
||||||
|
|
||||||
|
$modified_time = date(' H:i:s d.m.Y.', strtotime('1 week 2 hours'));
|
||||||
|
|
||||||
|
echo 'The current time is ' . $actual_time. ' '. $actual_date . '<br>';
|
||||||
|
echo 'The modified time is ' . $modified_time;
|
||||||
|
|
||||||
|
?>
|
||||||
12
exam60/RandomGenerator.php
Normal file
12
exam60/RandomGenerator.php
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
if(isset($_POST['roll'])){
|
||||||
|
$rand = rand(1,6);
|
||||||
|
echo 'You rolled a ' .$rand;
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<form action="RandomGenerator.php" method="POST">
|
||||||
|
<input type="submit" name="roll" value="Roll dice">
|
||||||
|
</form>
|
||||||
23
exam63/ServerVariables.php
Normal file
23
exam63/ServerVariables.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
|
||||||
|
<h1>My page</h1>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// include 'header.inc.php';
|
||||||
|
|
||||||
|
// $scrpit_name = $_SERVER['SCRIPT_NAME'];
|
||||||
|
// echo $scrpit_name . '<br>';
|
||||||
|
|
||||||
|
// $host_name = $_SERVER['HTTP_HOST'];
|
||||||
|
// echo $host_name;
|
||||||
|
|
||||||
|
|
||||||
|
$redirect = true;
|
||||||
|
$redirect_page = 'http://google.com';
|
||||||
|
|
||||||
|
if($redirect == true){
|
||||||
|
header('Location: '. $redirect_page);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
3
exam63/header.inc.php
Normal file
3
exam63/header.inc.php
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<form action="" method="POST">
|
||||||
|
<input type="submit" name="submit" value="Submit">
|
||||||
|
</form>
|
||||||
13
exam65/VisitorsIP.php
Normal file
13
exam65/VisitorsIP.php
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
//How to get visitor ip address
|
||||||
|
require 'config.inc.php';
|
||||||
|
|
||||||
|
foreach($ip_blocked as $ip){
|
||||||
|
if($ip == $ip_address){
|
||||||
|
die('Your ip address, ' . $ip_address . ' has been blocked');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<h1>Welcome !</h1>
|
||||||
17
exam65/VisitorsIP2.php
Normal file
17
exam65/VisitorsIP2.php
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
// Better way to get visitors IP
|
||||||
|
|
||||||
|
$http_client_ip = $_SERVER['HTTP_CLIENT_IP'];
|
||||||
|
$http_x_forwarded_for = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
||||||
|
$remote_addr = $_SERVER['REMOTE_ADDR'];
|
||||||
|
|
||||||
|
if(!empty($http_client_ip)){
|
||||||
|
$ip_address = $http_client_ip;
|
||||||
|
} else if(!empty($http_x_forwarded_for)){
|
||||||
|
$ip_address = $http_x_forwarded_for;
|
||||||
|
} else {
|
||||||
|
$ip_address = $remote_addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $ip_address;
|
||||||
|
?>
|
||||||
8
exam65/config.inc.php
Normal file
8
exam65/config.inc.php
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$ip_address = $_SERVER['REMOTE_ADDR'];
|
||||||
|
$ip_blocked = array('127.0.0.1', '100.100.100.100');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
12
exam67/VisitorsBrowser.php
Normal file
12
exam67/VisitorsBrowser.php
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$browser = get_browser(null, true);
|
||||||
|
$browser = strtolower($browser['browser']);
|
||||||
|
|
||||||
|
if( $browser != 'chrome'){
|
||||||
|
echo 'You\'re not using Google chrome. Please do!';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
22
exam69/WorkingWithGET.php
Normal file
22
exam69/WorkingWithGET.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
<?php
|
||||||
|
|
||||||
|
if(isset($_GET['day']) && isset($_GET['date']) && isset($_GET['year'])){
|
||||||
|
$day = $_GET['day'];
|
||||||
|
$date = $_GET['date'];
|
||||||
|
$year = $_GET['year'];
|
||||||
|
if(!empty($day) && !empty($date) && !empty($year)){
|
||||||
|
echo 'It is ' . $day . ' '. $date . $year;
|
||||||
|
} else {
|
||||||
|
echo 'Fill in all fields';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<form action="WorkingWithGET.php" method="GET">
|
||||||
|
Day: <br> <input type="text" name="day"><br>
|
||||||
|
Date: <br> <input type="text" name="date"><br>
|
||||||
|
Year: <br> <input type="text" name="year"><br><br>
|
||||||
|
<input type="submit" value="submit">
|
||||||
|
</form>
|
||||||
26
exam69/WorkingWithPOST.php
Normal file
26
exam69/WorkingWithPOST.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$match = 'pass123';
|
||||||
|
|
||||||
|
if(isset($_POST['password'])){
|
||||||
|
$pass = $_POST['password'];
|
||||||
|
if(!empty($pass)){
|
||||||
|
if($pass == $match){
|
||||||
|
echo 'Password is correct!';
|
||||||
|
} else {
|
||||||
|
echo 'Password is incorrect!';
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
echo 'Please enter the password!';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<form action="WorkingWithPOST.php" method="POST">
|
||||||
|
Password: <br> <input type="password" name="password"><br>
|
||||||
|
<input type="submit" value="Submit">
|
||||||
|
</form>
|
||||||
7
exam73/Cookie.php
Normal file
7
exam73/Cookie.php
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
setcookie('username', 'nikola', time() + 1500);
|
||||||
|
//ovako brisemo
|
||||||
|
//setcookie('username', 'nikola', time()-1500);
|
||||||
|
|
||||||
|
?>
|
||||||
14
exam73/Sessions.php
Normal file
14
exam73/Sessions.php
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
if( isset($_SESSION['username']) && isset($_SESSION['age'])){
|
||||||
|
echo ' Welcome , ' , $_SESSION['username'] . '. You are ' . $_SESSION['age'] . 'years old.';
|
||||||
|
} else{
|
||||||
|
echo 'Please log in.';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
6
exam73/set.php
Normal file
6
exam73/set.php
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
$_SESSION['username'] = 'alex';
|
||||||
|
$_SESSION['age'] = '21';
|
||||||
|
|
||||||
|
?>
|
||||||
8
exam73/unset.php
Normal file
8
exam73/unset.php
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
unset($_SESSION['username']);
|
||||||
|
|
||||||
|
session_destroy();
|
||||||
|
?>
|
||||||
5
exam73/view.php
Normal file
5
exam73/view.php
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
echo $_COOKIE['username'];
|
||||||
|
|
||||||
|
?>
|
||||||
45
exam77/file.php
Executable file
45
exam77/file.php
Executable file
@@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
//Writing to a file
|
||||||
|
// $handle = fopen('names.txt', 'w');
|
||||||
|
|
||||||
|
// fwrite($handle,'Alex' . "\n");
|
||||||
|
// fwrite($handle, 'Nikola');
|
||||||
|
|
||||||
|
// fclose($handle);
|
||||||
|
|
||||||
|
//Appending a file
|
||||||
|
|
||||||
|
|
||||||
|
if(isset($_POST['name'])){
|
||||||
|
$name = $_POST['name'];
|
||||||
|
|
||||||
|
if(!empty($name)){
|
||||||
|
$handle = fopen('names.txt', 'a');
|
||||||
|
fwrite($handle, $name ."\n");
|
||||||
|
fclose($handle);
|
||||||
|
|
||||||
|
echo 'Current names in file: ';
|
||||||
|
|
||||||
|
$count = 1;
|
||||||
|
$readin = file('names.txt');
|
||||||
|
$readin_count = count($readin);
|
||||||
|
foreach($readin as $fname){
|
||||||
|
echo trim($fname);
|
||||||
|
if($count < $readin_count){
|
||||||
|
echo ', ';
|
||||||
|
}
|
||||||
|
$count++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo 'Write some name!';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<form action="file.php" method="POST">
|
||||||
|
Name:<br>
|
||||||
|
<input type="text" name="name"><br><br>
|
||||||
|
<input type="submit" value="Submit">
|
||||||
|
</form>
|
||||||
17
exam77/file2.php
Normal file
17
exam77/file2.php
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$filename = 'names.txt';
|
||||||
|
$handle = fopen($filename, 'r');
|
||||||
|
|
||||||
|
$datain = fread($handle, filesize($filename));
|
||||||
|
|
||||||
|
$names_array = explode(",", $datain);
|
||||||
|
|
||||||
|
foreach($names_array as $name){
|
||||||
|
echo $name . '<br>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$string = implode(":", $names_array);
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
12
exam77/names.txt
Normal file
12
exam77/names.txt
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
Nicke,
|
||||||
|
Branko,
|
||||||
|
Steven,
|
||||||
|
Alex,
|
||||||
|
Sandra,
|
||||||
|
Sandra,
|
||||||
|
Dane,
|
||||||
|
Marko,
|
||||||
|
Krle,
|
||||||
|
Petar,
|
||||||
|
Aleksa,
|
||||||
|
Brana,
|
||||||
0
exam82/64115txt
Normal file
0
exam82/64115txt
Normal file
13
exam82/checkfile.php
Normal file
13
exam82/checkfile.php
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$filename = 'file.txt';
|
||||||
|
|
||||||
|
if(file_exists($filename)){
|
||||||
|
echo 'File already exists';
|
||||||
|
} else {
|
||||||
|
$handle = fopen($filename, 'w');
|
||||||
|
fwrite($handle, 'Nothing');
|
||||||
|
fclose($handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
1
exam82/file.txt
Normal file
1
exam82/file.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Nothing
|
||||||
1
exam82/files/firstfile.txt
Normal file
1
exam82/files/firstfile.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
First file
|
||||||
1
exam82/files/secondfile.txt
Normal file
1
exam82/files/secondfile.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Second File
|
||||||
1
exam82/files/thirdfile.txt
Normal file
1
exam82/files/thirdfile.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Third file
|
||||||
16
exam82/listingFiles.php
Normal file
16
exam82/listingFiles.php
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$directory = 'files';
|
||||||
|
|
||||||
|
if ($handle = opendir($directory.'/')){
|
||||||
|
echo 'Looking inside \'' . $directory . '\': <br>';
|
||||||
|
|
||||||
|
while($file = readdir($handle)){
|
||||||
|
if ($file != '.' && $file != '..') {
|
||||||
|
echo '<a href="'.$directory.'/'.$file.'">'.$file.'</a><br>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
22
exam82/rdfiles.php
Normal file
22
exam82/rdfiles.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$filename = 'filetodelete.txt';
|
||||||
|
|
||||||
|
if(@unlink($filename)){
|
||||||
|
echo 'File <strong>'. $filename .'</strong> has been deleted';
|
||||||
|
} else {
|
||||||
|
echo 'File cannot be deleted!';
|
||||||
|
}
|
||||||
|
|
||||||
|
$file = 'filetorename.txt';
|
||||||
|
$rand = rand(10000,99999);
|
||||||
|
|
||||||
|
if(@rename($file,$rand.'txt')){
|
||||||
|
echo 'File has been renamed successfully to ' . $rand;
|
||||||
|
} else {
|
||||||
|
echo 'File cannot be renamed!';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
46
exam86/upload.php
Executable file
46
exam86/upload.php
Executable file
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$name = $_FILES['file']['name'];
|
||||||
|
|
||||||
|
$strpos = strpos($name, '.');
|
||||||
|
$extension = strtolower(substr($name, $strpos + 1));
|
||||||
|
$type = $_FILES['file']['type'];
|
||||||
|
|
||||||
|
$size = $_FILES['file']['size'];
|
||||||
|
$max_size = 2097152;
|
||||||
|
|
||||||
|
|
||||||
|
$tmp_name = $_FILES['file']['tmp_name'];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if(isset($name)){
|
||||||
|
if(!empty($name)){
|
||||||
|
if($size <= $max_size){
|
||||||
|
if(($extension == 'jpeg' || $extension =='jpg') && $type == 'image/jpeg' ){
|
||||||
|
|
||||||
|
$location = 'uploads/';
|
||||||
|
|
||||||
|
if(move_uploaded_file($tmp_name,$location . $name)){
|
||||||
|
echo 'Uploaded';
|
||||||
|
} else {
|
||||||
|
echo 'There was some error!';
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
echo 'File must be jpeg or jpg';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo 'File must be under 2mb';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo 'Choose some file!';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<form action="upload.php" method="POST" enctype="multipart/form-data">
|
||||||
|
<input type="file" name="file"><br><br>
|
||||||
|
<input type="submit" value="Submit">
|
||||||
|
</form>
|
||||||
BIN
exam86/uploads/Screenshot from 2024-04-29 12-34-05.png
Normal file
BIN
exam86/uploads/Screenshot from 2024-04-29 12-34-05.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 99 KiB |
BIN
exam86/uploads/Untitled.jpeg
Normal file
BIN
exam86/uploads/Untitled.jpeg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.3 KiB |
36
exam92/FileBasedUniqueHC/count.php
Executable file
36
exam92/FileBasedUniqueHC/count.php
Executable file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
function hit_count(){
|
||||||
|
|
||||||
|
$ip_address = $_SERVER['REMOTE_ADDR'];
|
||||||
|
|
||||||
|
$ip_file = file('ip.txt');
|
||||||
|
foreach($ip_file as $ip){
|
||||||
|
$ip_single = trim($ip);
|
||||||
|
if ($ip_address == $ip_single){
|
||||||
|
$found = true;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
$found = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($found == true){
|
||||||
|
$filename = 'count.txt';
|
||||||
|
$handle = fopen($filename, 'r');
|
||||||
|
$current = fread($handle, filesize($filename));
|
||||||
|
fclose($handle);
|
||||||
|
$current_inc = $current + 1;
|
||||||
|
|
||||||
|
$handle = fopen($filename, 'w');
|
||||||
|
fwrite($handle,$current_inc);
|
||||||
|
fclose($handle);
|
||||||
|
|
||||||
|
$handle = fopen('ip.txt', 'a');
|
||||||
|
fwrite($handle, $ip_address."\n");
|
||||||
|
fclose($handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
1
exam92/FileBasedUniqueHC/count.txt
Executable file
1
exam92/FileBasedUniqueHC/count.txt
Executable file
@@ -0,0 +1 @@
|
|||||||
|
7
|
||||||
7
exam92/FileBasedUniqueHC/index.php
Executable file
7
exam92/FileBasedUniqueHC/index.php
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
include 'count.php';
|
||||||
|
|
||||||
|
hit_count();
|
||||||
|
|
||||||
|
?>
|
||||||
7
exam92/FileBasedUniqueHC/ip.txt
Executable file
7
exam92/FileBasedUniqueHC/ip.txt
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
127.0.0.1
|
||||||
|
127.0.0.1
|
||||||
|
127.0.0.1
|
||||||
|
127.0.0.1
|
||||||
|
127.0.0.1
|
||||||
|
127.0.0.1
|
||||||
|
127.0.0.1
|
||||||
16
exam92/NotUniqueHC/count.php
Executable file
16
exam92/NotUniqueHC/count.php
Executable file
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
function hit_count(){
|
||||||
|
$filename = 'count.txt';
|
||||||
|
$handle = fopen($filename,'r');
|
||||||
|
$current = fread($handle, filesize($filename));
|
||||||
|
fclose($handle);
|
||||||
|
|
||||||
|
$current_inc = $current + 1;
|
||||||
|
|
||||||
|
$handle = fopen($filename, 'w');
|
||||||
|
fwrite($handle, $current_inc);
|
||||||
|
fclose($handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
1
exam92/NotUniqueHC/count.txt
Executable file
1
exam92/NotUniqueHC/count.txt
Executable file
@@ -0,0 +1 @@
|
|||||||
|
5
|
||||||
7
exam92/NotUniqueHC/notuHitcounter.php
Executable file
7
exam92/NotUniqueHC/notuHitcounter.php
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
include 'count.php';
|
||||||
|
|
||||||
|
hit_count();
|
||||||
|
|
||||||
|
?>
|
||||||
27
exam96/encryption.php
Normal file
27
exam96/encryption.php
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
if (isset($_POST['password']) && !empty($_POST['password'])) {
|
||||||
|
$pass = md5($_POST['password']);
|
||||||
|
|
||||||
|
$filename = 'hash.txt';
|
||||||
|
$handle = fopen($filename,'r');
|
||||||
|
$file_pass = fread($handle,filesize($filename));
|
||||||
|
|
||||||
|
if($pass == $file_pass){
|
||||||
|
echo 'Password ok!';
|
||||||
|
}else{
|
||||||
|
echo 'Incorrect passwrod';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} else{
|
||||||
|
echo 'Please enter the password!';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<form action="encryption.php" method="POST">
|
||||||
|
Password:<input type="text" name="password"><br><br>
|
||||||
|
<input type="submit" value="Submit">
|
||||||
|
</form>
|
||||||
1
exam96/hash.txt
Normal file
1
exam96/hash.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
5f4dcc3b5aa765d61d8327deb882cf99
|
||||||
14
exam98/index.php
Normal file
14
exam98/index.php
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$to = 'random@gmail.com';
|
||||||
|
$subject = 'this is an email';
|
||||||
|
$body = 'This is a test email \n\n Hope you got it!';
|
||||||
|
$headers = 'From: noreply@gmail.com';
|
||||||
|
|
||||||
|
if(mail($to, $subject, $body, $headers)){
|
||||||
|
echo 'Mail is send successfuly!';
|
||||||
|
}else {
|
||||||
|
echo 'Error';
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
Reference in New Issue
Block a user