Jump to content

petroz

Members
  • Posts

    180
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

petroz's Achievements

Member

Member (2/5)

0

Reputation

  1. Try something like this SELECT `name`, `text` FROM `table` WHERE `name` = 'peter' ORDER BY RAND() LIMIT 2;
  2. Im sorry... kind of working in the dark with the amount of code your providing. If you can give me a bigger picture (More of your code....) I can problem write in a method there for you.
  3. <form action="index-5.php" method="post"> does not redirect to the index-5.php, it simply tells the form where to submit. So if your form is on the same page as your PHP script that processes it then you can use <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
  4. Have you looked at your session cookie to see if there is any data in it?
  5. This is untested, but header is the method for redirect. if ($number == "scuba") { //echo "CORRECT"; header('Location: success.php'); }
  6. Totally agree with you on the database.... but I think OP needs to get a more clear understanding for forms and how PHP works with them...
  7. I dont see where you are setting $userid, but you can try inserting the session data directly into the query... Not recommended, but it should work. mysql_query("UPDATE users SET dogs = '$breed' WHERE userID = '".$_SESSION['userid']."'");
  8. Something like this might help... <?php $file = 'mytextfile.txt'; $data = $_POST['content']; if($_SERVER['REQUEST_METHOD'] == "POST") { //update the text file $fp = fopen($file, 'w+'); fwrite($fp, $data); fclose($fp); ?> <form action = "<?php echo $_SERVER['PHP_SELF'];?>" method="post"> <textarea name="content" cols="" rows="" wrap="virtual" class="textarea1"> <?php include $file; ?> </textarea> <br /> <input type="submit" value="Save"> </form> <? } else { ?> <form action = "<?php echo $_SERVER['PHP_SELF'];?>" method="post"> <textarea name="content" cols="" rows="" wrap="virtual" class="textarea1"> <?php include $file; ?> </textarea> <br /> <input type="submit" value="Save"> </form> <? }
  9. I find it easier to work with an array for check boxes. Look at the example below. <?php if($_SERVER['REQUEST_METHOD'] == "POST") { $box = $_POST['myCheckBox']; foreach($box as $checked) { //delete($checked); print_r($checked); echo "<hr>"; } } else { //do something get ?> <form target="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <input type="checkbox" name="myCheckBox[]" value="1"> <input type="checkbox" name="myCheckBox[]" value="2"> <input type="checkbox" name="myCheckBox[]" value="3"> <input type="submit"> </form> <? }
  10. Can you show some of your code? I might be able to point you in the right direction...
  11. First... If you truly want to protect the file, you need to move it out of a public web directory. Second... Whitelisting IP's is very easy. Here is a rough example. <?php class Files { function __construct() { include 'db.php'; //start your database connection $this->mydir = "/var/protectedFiles/"; //note how it is not in the web directory $this->ip = $_SERVER['REMOTE_HOST']; //gets the IP address of the user //build an array of the url, then pickout the file they are looking for $request = parse_url($_SERVER['HTTP_REFERER']); $path = $request['path']; $path_parts = explode('/', $path); //seperate the path string into an array $this->myfile = $path_parts[1]; //if the url is like so... http://example.com/files/myfile.zip //run through the authorization process and give them what they deserve! $auth = $this->check_IP(); if($auth === "TRUE") { $file_exists = $this->check_file(); if($file_exists === "TRUE") { $file = file_get_contents($this->mydir.$this->myfile); //set an optional header header('HTTP/1.1 200 OK'); header('Content-Type: application/zip'); //print the file! print_r($file); } else { echo "We could not find the file you are looking for!"; die; } } else { echo "Access Denied"; die; } } private function check_IP() { //check your IP database for an IP $sql = "SELECT * FROM `ip_whitelist` WHERE `ip` = '".$this->ip."'"; $query = mysql_query($sql); $valid = mysql_num_rows($query); if($valid === 1) { return "TRUE"; //if the IP exists in your database } else { return "FALSE"; // if the IP does not exist in your database } } private function check_file() { if(file_exists($this->mydir.$this->myfile)) { return "TRUE"; // I found a file!!! } else { return "FALSE"; //I could not find what you are looking for! } } }
  12. Another note... Switch is an old school method for for dealing with conditions.. here is an example. $sql = "SELECT * FROM airplanes WHERE ama='$ama'"; $query = mysql_query($sql); $rows = mysql_num_rows($query); switch ($rows) { case 0: echo "Error!!!!"; break; case 1: include 'display.php'; break; default: echo "we found more than one!"; break; }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.