-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
48 lines (42 loc) · 5.55 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!--
Krish Patel and Mika Vohl
2/20/2023
Functions Page
This is the PHP code to store the functions for the website, which can be called by any website
-->
<?php
// Custom Function with Return Value
//*************************************************************************************************************************
// *
function displayLogin(){ // *
$username = $_SESSION["userFull"]; // Gets username from session and stores in variable *
if($username != ""){ // *
return $username; // Returns the username *
} // *
else{ // *
return "Not Logged In"; // If the username is empty, returns "Not Logged In" *
} // *
} // *
//*************************************************************************************************************************
// Custom Function with Parameter
//********************************************************************************************************************************************************************************************
// *
function cleanUpText($textString){ // *
$textString = trim($textString); // removes whitespace at beginning and end of string *
$message = str_replace(array("\r", "\n", " "), " ", $textString); // Replaces all new paragraph spaces with a space *
$find = array("poopy", "stupid", "bad", "crap", "poop"); // Array of profanity that is not allowed on the website *
$message = str_ireplace($find, "****", $message); // Replacing all instances of the profanity words with asterisks *
return $message; // *
} // *
//********************************************************************************************************************************************************************************************
// Custom Function
//********************************************************************************************************************************************************************************************
// *
function accessCheck(){ // *
if(displayLogin() == "Not Logged In"){ // checks if logged in *
echo "<script>window.location.href = 'https://unit1assignment1krishpatelmikavohl.krishpatel102.repl.co/chatMe/loginAndRegister/index.php';</script>"; // Redirects to login page *
} // *
} // *
// *
//********************************************************************************************************************************************************************************************
?>