Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 4th, 2012  |  syntax: None  |  size: 7.38 KB  |  hits: 37  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?
  2. session_start(); # Make sure the session is set, otherwise nothing else can be registered, destoryed, unset etc. This is used for the login part.
  3. date_default_timezone_set('GMT'); # Default thing for the date.
  4. # Start variables
  5. $sqlh = "fdb2.eu.pn"; # SQL Host
  6. $sqlu = "638119_638119"; # SQL Username
  7. $sqlp = "robd123"; # SQL Password
  8. $sqldb =  "638119_638119"; # SQL Database
  9. # End variables
  10. $sqlc = mysql_connect($sqlh,$sqlu,$sqlp); # Connect to database
  11. $seldb = mysql_select_db($sqldb, $sqlc); # Select database
  12. if (!$sqlc){
  13. die("Couldn't connect to the SQL server.<br>Possibly host, username, or password incorrect?<br><br>"); # If it can't connect to MYSQL Server display the msg
  14. }
  15. if (!$seldb){
  16. die("Couldn't select the database<br>Did you type it correctly?<br><br>"); # If it can't connect to database display the msg
  17. }
  18. $x = $_GET['id']; # Gets something after ID - e.g ?id=home
  19. $x = mysql_real_escape_string($x); # Protect from SQL injections; such as ' nd shit.
  20. ?>
  21. <html>
  22. <head>
  23. <title>WUS Problem Manager</title>
  24. <style type="text/css">
  25. body {
  26. font-family: verdana, arial, helvetica, sans-serif;
  27. color: white;
  28. background-color: black;
  29. }
  30. a {
  31.         text-decoration: none;
  32.         font-weight: bold;
  33.         color:  #ccc;
  34.         outline: none;
  35.         }
  36. a:visited {
  37.         color:  #ccc;
  38.         }
  39. a:active {
  40.         color:  #ccc;
  41.         }
  42. a:hover {
  43.         color: #ccc;
  44.         text-decoration: underline;
  45.         }
  46. </style>
  47. </head>
  48. <Center>
  49. <body>
  50. <?
  51. switch($x) {
  52. default: # if not defined..
  53. case "login"; # go to the login case
  54. if (isset($_POST['login'])){ # if the form is submitted then...
  55. # Check to see if things were left empty..
  56. if (empty($_POST['username'])){
  57. die("You left the username space empty.");
  58. }
  59. if (empty($_POST['password'])){
  60. die("You left the password space empty.");
  61. }
  62. # End checking to see if it's empty.
  63. # Assuming its not, lets see if it's correct..
  64. $username = $_POST['username']; # Make it a variable, makes it easier.
  65. $pass = sha1($_POST['password']); # Encrypt the password with SHA1
  66. $query = "select * from user where username='$username' and password='$pass'"; # Selects based off the info given
  67. $result = mysql_query($query); # Executes query
  68. $numrows = mysql_num_rows($result); # Sees if any results pop up
  69.  
  70. if ($numrows == 1){ # If there is one..
  71. $_SESSION['user'] = $username;
  72. $_SESSION['l0gg3d'] = $pass . $username;
  73. # Log it in two sessions, to make it nice and friendly :)
  74. echo("You logged in successfully, please click <a href='?id=main'>here</a>"); # Display the correct login thing
  75. }else{ # Otherwise
  76. die("The username / password combination was incorrect."); # It's not correct.
  77. }
  78. }else{ # If its not submitted, print the form out.
  79. echo "Login";
  80. print'
  81. <form action="" method="POST">
  82. <table>
  83. <tr>
  84. <td>Username</td>
  85. <td>-</td>
  86. <td><input type="text" name="username"></td>
  87. </tr>
  88. <tr>
  89. <td>Password</td>
  90. <td>-</td>
  91. <td><input type="password" name="password"></td>
  92. </tr>
  93. <tr>
  94. <td></td>
  95. <td></td>
  96. <td><input type="submit" name="login"></td>
  97. </tr></table></form>';
  98. echo "<a href='problem.php'>Click here to add a problem</a>";
  99. } # end the if statement
  100.  
  101. break; # Nothing else for login
  102.  
  103. case "main";
  104. if (!isset($_SESSION['l0gg3d']) && ($_SESSION['username'])) { # If someone who isn't logged in turns up...
  105. die("You're not authorized to use this page."); # Stop the rest of the page from loading.
  106. }
  107. # If they are logged in... then display the contents.
  108.  
  109. echo "Control Area";
  110. print '
  111. <br>
  112. <br>
  113. <a href="?id=add">Add a problem</a><br>
  114. <a href="?id=view">View the problems</a><br>
  115. <a href="?id=search">Search through the problems</a><br>
  116. <a href="?id=logout">Logout</a>';
  117. break;
  118.  
  119. case "logout";
  120. session_unset(); # Unset all sessions
  121. session_destroy(); # Destroy them!
  122. print'
  123. <a href="?id=login">You have been logged out.</a>'; # Say they've been logged out.
  124. break;
  125.  
  126. case "add";
  127. if (!isset($_SESSION['l0gg3d']) && ($_SESSION['username'])) { # If someone who isn't logged in turns up...
  128. die("You're not authorized to use this page."); # Stop the rest of the page from loading.
  129. }
  130. if (isset($_POST['add'])){
  131. # If its submitted...
  132. # I CBF to add "if empty" stuff. By all means, please do.
  133. # Syntax:
  134. # if (empty($_POST['*name here*'])){
  135. # die("You left something empty");
  136. # }
  137. $email = $_POST['email'];
  138. $name = $_POST['name'];
  139. $type = $_POST['type'];
  140. $problem = $_POST['problem'];
  141. $cpu = $_POST['computer'];
  142. $date = date("F j, Y, g:i a");
  143. $ip = $_SERVER['REMOTE_ADDR'];
  144. # end more variables
  145. # structure and insert into the db
  146. $query = "insert into problems (email, name, type, problem, computer, date, ip) values ('$email', '$name', '$type', '$problem', '$cpu', '$date', '$ip')";
  147. mysql_query ($query) or die ('Could not enter the problem.'); # die if error
  148. echo("Problem has been inserted."); # otherwise, its fine.
  149. echo("Click <a href='?id=view'>here</a> to view all the problems, or <a href='?id=main'>here</a> to go back.");
  150. # otherwise, form not submitted..
  151. # print it out
  152. }else{
  153. print'
  154. <form action="" method="POST">
  155. <table cellpadding="8">
  156. <tr valign="top">
  157. <td>Email:</td>
  158. <td><input type="text" name="email"></td>
  159. </tr>
  160. <tr valign="top">
  161. <td>Name:</td>
  162. <td><input type="text" name="name"></td>
  163. </tr>
  164. <tr valign="top">
  165. <td>Hardware or Software:</td>
  166. <td><select name="type"><option value="Hardware">Hardware</option><option value="Software">Software</option></select></td>
  167. </tr>
  168. <tr valign="top">
  169. <td>Problem:</td>
  170. <td><textarea cols="40" rows="20" name="problem"></textarea></td>
  171. </tr>
  172. <tr valign="top">
  173. <td>Computer:</td>
  174. <td><input type="text" name="computer"></td>
  175. </tr>
  176. <tr valign="top">
  177. <td><input type="submit" name="add"></td>
  178. <td><a href="?id=main">Click here to go back</a></td>
  179. </tr>
  180. </table>';
  181. }
  182. # end the if
  183. break;
  184.  
  185. case "view";
  186. if (!isset($_SESSION['l0gg3d']) && ($_SESSION['username'])) { # If someone who isn't logged in turns up...
  187. die("You're not authorized to use this page."); # Stop the rest of the page from loading.
  188. }
  189. # If they are logged in... then display the contents.
  190. $query = "SELECT * FROM problems ORDER BY ID DESC";  # Select all the problems, from the problems table. Order it by ID, descending.
  191. $result = mysql_query($query) or die(mysql_error()); # Insert the query; otherwise, it'll die and reveal the error
  192. $numrows=mysql_num_rows($result); # Grab the number of rows in the table from the query above
  193. if ($numrows == 0){  # If there are no problems...
  194. echo("There are no problems, yay!"); # No problems are there :)
  195. } # End the if
  196. echo "<a href='?id=main'>Click here to go back</a>"; # Always offer a go back menu
  197. # Echo the table first
  198. print'<table cellpadding="10" cellspacing="10">
  199. <tr>
  200. <td><b>ID</b></td>
  201. <td><b>Email</b></td>
  202. <td><b>Name</b></td>
  203. <td><b>Type</b></td>
  204. <td><b>Problem</b></td>
  205. <td><b>Computer</b></td>
  206. <td><b>Date</b></td>
  207. <td><b>IP</b></td>
  208. </tr>';
  209. while($row = mysql_fetch_array($result)){ # Select the rows via table names nd stuff.
  210. print'
  211. <tr>
  212. <td>' . $row['ID'] .'</td>
  213. <td>' . $row['email'] .'</td>
  214. <td>' . $row['name'] .'</td>
  215. <td>' . $row['type'] .'</td>
  216. <td>' . $row['problem'] .'</td>
  217. <td>' . $row['computer'] .'</td>
  218. <td>' . $row['date'] .'</td>
  219. <td>' . $row['ip'] .'</td>
  220. </tr>';
  221. # echo all the problems out in the table, using data within the table.
  222. }
  223. echo"<table></p>";
  224. break;
  225. # end the switch statement
  226.  
  227. case "search";
  228. <html>
  229. <head>
  230. <meta  http-equiv="Content-Type" content="text/html;  charset=iso-8859-1">  
  231. <title>Search  Contacts</title>  
  232. </head>
  233.  
  234.  
  235. </html>
  236.  
  237. }
  238.  
  239. ?>
  240. </center>