Jump to content

mallen

Members
  • Posts

    316
  • Joined

  • Last visited

Everything posted by mallen

  1. Ok I am getting close. Now I have this <?php if ($_SERVER['REQUEST_METHOD']=="POST"){ // we'll begin by assigning the To address and message subject $to="me@you.com"; $subject="E-mail with attachment"; // get the sender's name and email address // we'll just plug them a variable to be used later $from = stripslashes($_POST['fromname'])."<".stripslashes($_POST['fromemail']).">"; // generate a random string to be used as the boundary marker $mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x"; // store the file information to variables for easier access $tmp_name = $_FILES['filename']['tmp_name']; $type = $_FILES['filename']['type']; $name = $_FILES['filename']['name']; $size = $_FILES['filename']['size']; // here we'll hard code a text message // again, in reality, you'll normally get this from the form submission $message = "Here is your file: $name"; // if the upload succeded, the file will exist if (file_exists($tmp_name)){ // check to make sure that it is an uploaded file and not a system file if(is_uploaded_file($tmp_name)){ // open the file for a binary read $file = fopen($tmp_name,'rb'); // read the file content into a variable $data = fread($file,filesize($tmp_name)); // close the file fclose($file); // now we encode it and split it into acceptable length lines $data = chunk_split(base64_encode($data)); } // now we'll build the message headers $headers = "From: $from\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: multipart/mixed;\r\n" . " boundary=\"{$mime_boundary}\""; // next, we'll build the message body // note that we insert two dashes in front of the // MIME boundary when we use it $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; // now we'll insert a boundary to indicate we're starting the attachment // we have to specify the content type, file name, and disposition as // an attachment, then add the file content and set another boundary to // indicate that the end of the file has been reached $message .= "--{$mime_boundary}\n" . "Content-Type: {$type};\n" . " name=\"{$name}\"\n" . //"Content-Disposition: attachment;\n" . //" filename=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; define ("MAX_SIZE","50"); function file_extension($filename) { $path_info = pathinfo($filename); return $path_info['extension']; } $errors=0; $filename = stripslashes($_FILES['filename']['name']); $type = strtolower( file_extension( $filename)); if (($type != "jpg") && ($type != "jpeg") && ($type != "png") && ($type != "pdf") && ($type != "dwg") && ($type != "gif")) { echo 'Unknown file extension. Only .gif, .jpg, .png, pdf and dwg and files are allowed to be uploaded </a>.'; echo $path_parts['extension'], "\n"; $errors=1; die (); } $size=filesize($_FILES['image']['tmp_name']); if $size = $_FILES['filename']['size']; { echo 'You have exceeded the size limit!'; $errors=1; die (); } // now we just send the message if (@mail($to, $subject, $message, $headers)) echo "Message Sent"; else echo "Failed to send"; } } else { ?> <p>Send an e-mail with an attachment:</p> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" name="form1"> <p>From name: <input type="text" name="fromname"></p> <p>From e-mail: <input type="text" name="fromemail"></p> <p>File: <input type="file" name="filename"></p> <p><input type="submit" name="Submit" value="Submit"></p> </form> <?php } ?> And I get this error Parse error: syntax error, unexpected T_VARIABLE, expecting '(' in .....on line 109 Which is this line if $size = $_FILES['filename']['size'];
  2. Now I get: Fatal error: Call to undefined function getExtension() in .....
  3. Thanks for the reply. I am using PHP 5. Anything you can help me get this working is appreciated.
  4. return $path_info['extension']; I don't understand this part. Where is it getting 'extension' ?
  5. I echoed $filename and it didn't return anything. ???
  6. Now I have define ("MAX_SIZE","50"); function file_extension($filename) { $path_info = pathinfo($filename); return $path_info['extension']; } $errors=0; $filename = stripslashes($_FILES['image']['name']); $type = file_extension($name); $type = strtolower($extension); if (($type != "jpg") && ($type != "jpeg") && ($type != "png") && ($type != "pdf") && ($type != "dwg") && ($type != "gif")) { echo 'Unknown file extension! Only .gif, .jpg, .png, pdf and dwg and files are allowed to be uploaded </a>.'; $errors=1; die (); } $size=filesize($_FILES['image']['tmp_name']); if ($size > MAX_SIZE*1024) { echo 'You have exceeded the size limit!'; $errors=1; die (); } And I still get "Unknown file extension! Only .gif, .jpg, .png, pdf and dwg and files are allowed to be uploaded ."
  7. I put echo $type; and tried uploading a Word doc and it returned : application/msword
  8. Unknown file extension! Only .gif, .jpg, .png, pdf and dwg and files are allowed to be uploaded How would I know its returning the right value?
  9. I have this script that allows a user to email an attachment. I'm trying to check the file size and type of file. See the section I added in the middle. Keeps giving e the message "wrong file type" and won't send the email. <?php if ($_SERVER['REQUEST_METHOD']=="POST"){ // we'll begin by assigning the To address and message subject $to="me@you.com"; $subject="E-mail with attachment"; // get the sender's name and email address // we'll just plug them a variable to be used later $from = stripslashes($_POST['fromname'])."<".stripslashes($_POST['fromemail']).">"; // generate a random string to be used as the boundary marker $mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x"; // store the file information to variables for easier access $tmp_name = $_FILES['filename']['tmp_name']; $type = $_FILES['filename']['type']; $name = $_FILES['filename']['name']; $size = $_FILES['filename']['size']; // here we'll hard code a text message // again, in reality, you'll normally get this from the form submission $message = "Here is your file: $name"; // if the upload succeded, the file will exist if (file_exists($tmp_name)){ // check to make sure that it is an uploaded file and not a system file if(is_uploaded_file($tmp_name)){ // open the file for a binary read $file = fopen($tmp_name,'rb'); // read the file content into a variable $data = fread($file,filesize($tmp_name)); // close the file fclose($file); // now we encode it and split it into acceptable length lines $data = chunk_split(base64_encode($data)); } // now we'll build the message headers $headers = "From: $from\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: multipart/mixed;\r\n" . " boundary=\"{$mime_boundary}\""; // next, we'll build the message body // note that we insert two dashes in front of the // MIME boundary when we use it $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; // now we'll insert a boundary to indicate we're starting the attachment // we have to specify the content type, file name, and disposition as // an attachment, then add the file content and set another boundary to // indicate that the end of the file has been reached $message .= "--{$mime_boundary}\n" . "Content-Type: {$type};\n" . " name=\"{$name}\"\n" . //"Content-Disposition: attachment;\n" . //" filename=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; //Added content here****************************************** define ("MAX_SIZE","50"); function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $type = substr($str,$i+1,$l); return $ext; } $errors=0; $filename = stripslashes($_FILES['image']['name']); $type = getExtension($name); $type = strtolower($extension); if (($type != "jpg") && ($type != "jpeg") && ($type != "png") && ($type != "pdf") && ($type != "dwg") && ($type != "gif")) { echo 'Unknown file extension! Only .gif, .jpg, .png, pdf and dwg and files are allowed to be uploaded </a>.'; $errors=1; die (); } $size=filesize($_FILES['image']['tmp_name']); if ($size > MAX_SIZE*1024) { echo 'You have exceeded the size limit!'; $errors=1; die (); } //End Added content********************************** // now we just send the message if (@mail($to, $subject, $message, $headers)) echo "Message Sent"; else echo "Failed to send"; } } else { ?> <p>Send an e-mail with an attachment:</p> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" name="form1"> <p>From name: <input type="text" name="fromname"></p> <p>From e-mail: <input type="text" name="fromemail"></p> <p>File: <input type="file" name="filename"></p> <p><input type="submit" name="Submit" value="Submit"></p> </form> <?php } ?>
  10. Just as I thought the script works fine. It always has. Something was not right on the clients server. Now my client's host is telling him "In the php script I should add and stipulate a “from line” or a referrer so that it doesn’t default to www user." Why would I need this? It always worked and it just stopped working. It works fine on other servers or hosts
  11. This form is not sending the email. It doesn't give any error. If you miss a field it will tellyou. But if you fill them out it still says The following required fields have not been filled in: Is there any missing here? I know I had this form and others working for a client and maybe something got changed. // process the email if (array_key_exists('send', $_POST)) { $to = 'me@you.com.com'; // use your own email address $subject = 'Register'; // list expected fields $expected = array('firstname','lastname','email','company','address','city','state','zipcode','country','phone', 'cellphone','fax','status','password','interests'); // set required fields $required = array('firstname','lastname','email'); // create empty array for any missing fields $missing = array(); // assume that there is nothing suspect $suspect = false; // create a pattern to locate suspect phrases $pattern = '/Content-Type:|Bcc:|Cc:/i'; // function to check for suspect phrases function isSuspect($val, $pattern, &$suspect) { // if the variable is an array, loop through each element // and pass it recursively back to the same function if (is_array($val)) { foreach ($val as $item) { isSuspect($item, $pattern, $suspect); } } else { // if one of the suspect phrases is found, set Boolean to true if (preg_match($pattern, $val)) { $suspect = true; } } } // check the $_POST array and any sub-arrays for suspect content isSuspect($_POST, $pattern, $suspect); if ($suspect) { $mailSent = false; unset($missing); } else { // process the $_POST variables foreach ($_POST as $key => $value) { // assign to temporary variable and strip whitespace if not an array $temp = is_array($value) ? $value : trim($value); // if empty and required, add to $missing array if (empty($temp) && in_array($key, $required)) { array_push($missing, $key); } // otherwise, assign to a variable of the same name as $key elseif (in_array($key, $expected)) { ${$key} = $temp; } } } // validate the email address if (!empty($email)) { // regex to ensure no illegal characters in email address $checkEmail = '/^[^@]+@[^\s\r\n\'";,@%]+$/'; // reject the email address if it doesn't match if (!preg_match($checkEmail, $email)) { array_push($missing, 'email'); } } // go ahead only if not suspect and all required fields OK if (!$suspect && empty($missing)) { // set default values for variables that might not exist $subscribe = isset($subscribe) ? $subscribe : 'Nothing selected'; $interests = isset($interests) ? $interests : array('None selected'); $characteristics = isset($characteristics) ? $characteristics : array('None selected'); // build the message $message = "First Name: $firstname\n\n"; $message .= "Last Name: $lastname\n\n"; $message .= "Email: $email\n\n"; $message .= "Company: $company\n\n"; $message .= "Address: $address\n\n"; $message .= "City: $city\n\n"; $message .= "State/Providence: $state\n\n"; $message .= "Zipcode: $zipcode\n\n"; $message .= "Country: $country\n\n"; $message .= "Phone: $phone\n\n"; $message .= "Cell Phone: $cellphone\n\n"; $message .= "Fax: $fax\n\n"; $message .= 'Interests: '.implode(', ', $interests)."\n\n"; // limit line length to 70 characters $message = wordwrap($message, 70); // create additional headers $additionalHeaders = 'From: me@you.com>'; if (!empty($email)) { $additionalHeaders .= "\r\nReply-To: $email"; } // send it $mailSent = mail($to, $subject, $message, $additionalHeaders); if ($mailSent) { // $missing is no longer needed if the email is sent, so unset it unset($missing); //$query = "INSERT INTO members (id, firstname, email) //VALUES (0,'{$_POST['firstname']}','{$_POST['email']}')"; $query = "INSERT INTO members (id, firstname, lastname, email, company, address, city, state, zipcode, country, phone, cellphone, fax, status, password) VALUES (0,'{$_POST['firstname']}','{$_POST['lastname']}','{$_POST['email']}','{$_POST['company']}','{$_POST['address']}','{$_POST['city']}','{$_POST['state']}','{$_POST['zipcode']}','{$_POST['country']}','{$_POST['phone']}','{$_POST['cellphone']}','{$_POST['fax']}','{$_POST['status']}','{$_POST['password']}')"; if (@mysql_query ($query)) { print ''; } else { print "<p>Could not enter data becuase: <b>" . mysql_error() ."</b>. The query was $query.</p>"; } mysql_close(); } } } ?> <?php if (isset($missing)) { echo '<p>The following required fields have not been filled in:</p>'; echo '<ul>'; foreach($missing as $item) { echo "<li>$item</li>"; } echo '</ul>'; } elseif ($_POST && $mailSent) { echo '<p><strong>Your message has been sent. Thank you for your feedback.</strong></p>'; } ?> <form id="feedback" method="post" action=""> <table border="0"> <tr> <td height="35" colspan="2" class="subheader">Register Form</td> <td height="25"> </td> <td height="25"> </td> </tr> <tr> <td height="25"> </td> <td height="35"> </td> <td height="25"> </td> <td height="25"> </td> </tr> <tr> <td width="98" height="25"> <label for="firstname">First Name: </label></td> <td width="195" height="35"><input name="firstname" id="firstname" type="text" class="formbox" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['firstname']).'"';} ?>/> </td> <td width="72" height="25"><label for="lastname">Last Name:</label></td> <td width="247" height="25"><input name="lastname" id="lastname" type="text" class="formbox" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['lastname']).'"';} ?>/></td> </tr> <tr> <td height="35"> <label for="Email">Email:</label></td> <td height="10"> <input name="email" id="email" type="text" class="formbox" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['email']).'"';} ?>/></td> <td height="10"><label for="company">Company: </label></td> <td height="10"> <input name="company" id="company" type="text" class="formbox" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['company']).'"';} ?>/></td> </tr> <tr> <td height="35"><label for="address">Address: </label></td> <td> <input name="address" id="address" type="text" class="formbox" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['address']).'"';} ?>/></td> <td> <label for="city">City:</label> </td> <td> <input name="city" id="city" type="text" class="formbox" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['city']).'"';} ?>/></td> </tr> <tr> <td height="35"><label for="state">State / Providence: </label></td> <td> <input name="state" id="state" type="text" class="formbox" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['state']).'"';} ?>/></td> <td> <label for="zipcode">Zip code:</label></td> <td> <input name="zipcode" id="zipcode" type="text" class="formbox" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['zipcode']).'"';} ?>/></td> </tr> <tr> <td height="35"><label for="country">Country:</label></td> <td> <input name="country" id="country" type="text" class="formbox" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['country']).'"';} ?>/></td> <td><label for="phone">Phone:</label></td> <td><input name="phone" id="phone" type="text" class="formbox" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['phone']).'"';} ?>/></td> </tr> <tr> <td height="35"><label for="cellphone">Cell Phone:</label></td> <td><input name="cellphone" id="cellphone" type="text" class="formbox"<?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['cellphone']).'"';} ?> /></td> <td><label for="fax">Fax Number:</label></td> <td><input name="fax" id="fax" type="text" class="formbox" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['fax']).'"';} ?>/></td> </tr> <tr> <td height="35"><label for="password">Choose Password:</label></td> <td><input name="password" id="password" type="password" class="formbox" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['password']).'"';} ?>/> </td> <td><input type="hidden" name="status" value="1"></td> <td> </td> </tr> </table> <table> <tr> <td colspan="2" valign="top" class="subheader"> </td> <td valign="top"> </td> </tr> <tr> <td colspan="2" valign="top" class="subheader">Additional Info Requested:</td> <td valign="top"> </td> </tr> <tr> <td width="198" valign="top"><div> <p> <input type="checkbox" name="interests[]" value="NLP Practitioner Program" id="NLPPrac" <?php $OK = isset($_POST['interests']) ? true : false; if ($OK && isset($missing) && in_array('NLPPractitionerProgram', $_POST['interests'])) { ?> checked="checked" <?php } ?> /> <label for="anime">NLP Practitioner Program</label> </p> <p> <input type="checkbox" name="interests[]" value="Hypnosis & NLP Intensive" id="HYPnos" <?php $OK = isset($_POST['interests']) ? true : false; if ($OK && isset($missing) && in_array('Hypnosis & NLP Intensive', $_POST['interests'])) { ?> checked="checked" <?php } ?> /> <label for="Hypnosis">Hypnosis & NLP Intensive</label> </p> <p> <input type="checkbox" name="interests[]" value="NLP ChangeMastery" id="NLPChange" <?php $OK = isset($_POST['interests']) ? true : false; if ($OK && isset($missing) && in_array('NLP ChangeMastery', $_POST['interests'])) { ?> checked="checked" <?php } ?> /> <label for="Hypnosis">NLP ChangeMastery ™</label> </p> <p> <input type="checkbox" name="interests[]" value="Meta-Programs Mastery" id="MetaChange" <?php $OK = isset($_POST['interests']) ? true : false; if ($OK && isset($missing) && in_array('Meta Programs Mastery', $_POST['interests'])) { ?> checked="checked" <?php } ?> /> <label for="Hypnosis">Meta-Programs Mastery™</label> </p> <p> <input type="checkbox" name="interests[]" value="Conversational Trance" id="ConvTrance" <?php $OK = isset($_POST['interests']) ? true : false; if ($OK && isset($missing) && in_array('Conversational Trance', $_POST['interests'])) { ?> checked="checked" <?php } ?> /> <label for="Hypnosis">Conversational Trance™</label> </p> </td> <td width="207" valign="top"><div> <p> <input type="checkbox" name="interests[]" value="Conversational NLP" id="ConvNLP" <?php $OK = isset($_POST['interests']) ? true : false; if ($OK && isset($missing) && in_array('ConversationalNLP', $_POST['interests'])) { ?> checked="checked" <?php } ?> /> <label for="Conversational NLP">Conversational NLP™</label> </p> <p> <input type="checkbox" name="interests[]" value="Identity Compass Training" id="IdentityCompass" <?php $OK = isset($_POST['interests']) ? true : false; if ($OK && isset($missing) && in_array('Identity Compass Training', $_POST['interests'])) { ?> checked="checked" <?php } ?> /> <label for="Hypnosis">Identity Compass® Training</label> </p> <p> <input type="checkbox" name="interests[]" value="Trance-Forming Identity" id="Trance" <?php $OK = isset($_POST['interests']) ? true : false; if ($OK && isset($missing) && in_array('Trance Forming Identity', $_POST['interests'])) { ?> checked="checked" <?php } ?> /> <label for="Hypnosis">Trance-Forming Identity ™ </label> </p> <p> <input type="checkbox" name="interests[]" value="Identity-Coaching" id="Identity" <?php $OK = isset($_POST['interests']) ? true : false; if ($OK && isset($missing) && in_array('IdentityCoaching', $_POST['interests'])) { ?> checked="checked" <?php } ?> /> <label for="Hypnosis">Identity-Coaching ™ </label> </p> <p> <input type="checkbox" name="interests[]" value="IMNLP & Hypnosis Membership" id="IMHypMem" <?php $OK = isset($_POST['interests']) ? true : false; if ($OK && isset($missing) && in_array('IMNLPHypnosisMembership', $_POST['interests'])) { ?> checked="checked" <?php } ?> /> <label for="Hypnosis">IMNLP & Hypnosis Membership</label> </p> </td> <td width="209" valign="top"><div> <p> <input type="checkbox" name="interests[]" value="ETC WebEx Online Courses" id="ETCWebEx" <?php $OK = isset($_POST['interests']) ? true : false; if ($OK && isset($missing) && in_array('ETC WebEx Online Courses', $_POST['interests'])) { ?> checked="checked" <?php } ?> /> <label for="anime">ETC™ WebEx Online Courses</label> </p> <p> <input type="checkbox" name="interests[]" value="NLP Master Practitioner Program" id="NLPPrac" <?php $OK = isset($_POST['interests']) ? true : false; if ($OK && isset($missing) && in_array('NLP Master Practitioner Program', $_POST['interests'])) { ?> checked="checked" <?php } ?> /> <label for="Hypnosis">NLP Master Practitioner Program</label> </p> <p> <input type="checkbox" name="interests[]" value="NLP In Hypnosis Immersion" id="NLPHyp" <?php $OK = isset($_POST['interests']) ? true : false; if ($OK && isset($missing) && in_array('NLP In Hypnosis Immersion', $_POST['interests'])) { ?> checked="checked" <?php } ?> /> <label for="Hypnosis">NLP In Hypnosis Immersion</label> </p> <p> <input type="checkbox" name="interests[]" value="ExecuSkills" id="ExecSkill" <?php $OK = isset($_POST['interests']) ? true : false; if ($OK && isset($missing) && in_array('ExecuSkills', $_POST['interests'])) { ?> checked="checked" <?php } ?> /> <label for="Hypnosis">ExecuSkills™</label> </p> </td> </tr> </table> <p> <input name="send" id="send" type="submit" value="Send message" /> </p> </form>
  12. Thanks I tried that and it still won't work.
  13. But it works in Firefox. Strange. And I have to have the code at the top and the form at the bottom or I get headers sent errors.
  14. My login form works ok in Firefox but fails in IE. It sends the user to the index page. Any ideas? <?php session_start(); $query= "SELECT id, email, password, status FROM `members` " ."WHERE `email`='".$_POST["email"]."' " ."AND `password`= '".$_POST["password"]."' " ."LIMIT 1"; $result= mysql_query($query) OR die( mysql_error() ); if ( mysql_num_rows($result) == 1 ) { // retrieve the resultset as an associative array $userRecord= mysql_fetch_assoc($result); $_SESSION['id']= $userRecord['id']; $_SESSION['status']= $userRecord['status']; // redirect based on the $userRecord['status'] value here switch ($userRecord['status']) { case 1: $location= "page1.php"; break; case 2: $location= "page2.php"; break; case 3: $location= "page3.php"; break; } header("Location: $location"); } ?> HTML HERE..... <form action="" method="post"> <label>Email <input type="text" name="email" id="email" /> </label> <label>Password <input type="password" name="password" id="password" /> </label> <label> <input type="submit" name="submit" id="submit" value="submit" /> </label> </form>
  15. I found some script to use and I modified it. Does anything here look incorrect? Becuase it gives me the message "Sorry, could not log you in. Wrong login information." All I am doing is checking for "email" and "password" <?php session_start(); require_once('./Connections/....'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php if ($_GET["op"] == "login") { if (!$_POST["email"] || !$_POST["password"]) { die("You need to provide a username and password."); } // Create query $q = "SELECT * FROM `members` " ."WHERE `email`='".$_POST["email"]."' " ."AND `password`= PASSWORD('".$_POST["password"]."') " ."LIMIT 1"; // Run query $r = mysql_query($q); if ( $obj = @mysql_fetch_object($r) ) { // Login good, create session variables $_SESSION["valid_id"] = $obj->id; $_SESSION["valid_user"] = $_POST["email"]; $_SESSION["valid_time"] = time(); // Redirect to member page Header("Location: members.php"); } else { // Login not successful die("Sorry, could not log you in. Wrong login information."); } } else { //If all went right the Web form appears and users can log in echo "<form action=\"?op=login\" method=\"POST\">"; echo "Username: <input name=\"email\"><br />"; echo "Password: <input name=\"password\"><br />"; echo "<input type=\"submit\" value=\"Login\">"; echo "</form>"; } ?>
  16. ....yeah..... that's what I was trying to get help with. I think it would be easier if I had one page. Where it checked if you were signed in. If not show the sign in form. Then once signed in show the content on the page.
  17. I am creating a simple log in form to protect a "member" page. What i have done is assigned a "1" or a "2" to each subscriber. Only people with "2" can view the member page. Here is what I have so far. Its rough I know. I have some pseudo code in there just to get the outline right. There are three pages. The member page that I am protecting, the login page that takes the submitted data, and the register page they get directed to if the log in fails. ---------------------------------------------------- member page ---------------------------------------------------- <?php session_start(); $status = $status[0]; //member or not. If status "1" direct to register.php, if "2" show page. session_register ('email'); session_register ('password'); session_register ('status'); if (isset ($POST['submit'])) { if ((!empty ($_POST['email'])) if email and user name are a match when sent to login.php //show content on page below// //All content will go here...../// else //print form to sign in print '<p>Please sign in using your email address and your password</p>'; print '<form action=login.php" method="post"><p>Email: <input type="text" name="email" size="20" /><br/> Password: <input type="password" name="password" size="20" /><br /> <input type="submit" name="submit" value=Log in /></p> </form>'; ?> --------------------------------------------- The login.php page --------------------------------------------- <?php $username=$_POST['email'];//get data posted from members form $password=$_POST['password']; $success = "members.php"; $failed = "register.php"; //check user's email and password. Also if status is "1" redirect to register.php //if status is "2" redirect to members.php and show the page. SELECT email, password, and status FROM members if email and password are ok and status is "2" then go to members page. Show as logged in. else if status is "1" redirect to register page.
  18. I have never used MS SQL database. I usually create my database with phpMyadmin. But my clinet doesn't have this tool. And they don't have MySQL instead they have MS SQL. Could I create the data base with phpMyadmin and output that? Then import the data into MS SQL? There is no GUI tool on the server to create tables and data entry.
  19. Thanks for the help. I didn't see that. Now I have a new issue. I want to only return results if one of the fields is not null. Such as is if there is a price, an image, description then display the results. I just can't figure it out. $query = 'SELECT * FROM phpbb_users WHERE price or image or description IS NOT NULL';
  20. Trying to display this simple query. Everything works but i can't get the image path correct. Its just displaying the image name. while ($row = mysql_fetch_array ($r)) { print "<p>{$row['title']} <br /> {$row['address']} <br /> {$row['description']} <br /> {$row['price']} <br /> <img src= "./uploads/images".{$row[['images']}"/> <br /> {$row['contact']} <br /> {$row['phone']} </p>";
  21. I got it to work with a few changes. It uploads the files, renames the file and stores the thumbnails. Now I want to change the name of the thumbnail. Such as add a prefix to it like th_12345.jpg <?php define ("MAX_SIZE","50"); function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } $errors=0; //checks if the form has been submitted if(isset($_POST['Submit'])) { $image=$_FILES['image']['name']; //if it is not empty if ($image) { $filename = stripslashes($_FILES['image']['name']); $extension = getExtension($filename); $extension = strtolower($extension); if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { echo 'Unknown file extension! Only .gif, .jpg, and .png files are allowed to be uploaded </a>.'; $errors=1; die (); } $size=filesize($_FILES['image']['tmp_name']); if ($size > MAX_SIZE*1024) { echo 'You have exceeded the size limit!'; $errors=1; die (); } $image_name=time().'.'.$extension; $newname="uploads/images/".$image_name; $copied = copy($_FILES['image']['tmp_name'], $newname); if (!$copied) { echo 'Copy unsuccessfull!'; $errors=1; } $query = "UPDATE users SET title='{$_POST['title']}' , description='{$_POST ['description']}' , images='{$image_name}', address='{$_POST ['address']}', price='{$_POST ['price']}', contact='{$_POST ['contact']}', phone='{$_POST ['phone']}' WHERE user_id='{$userdata['user_id']}'"; // Execute the query. if (mysql_query ($query)) { print '<p>Your property entry has been added.</p>'; } else { print "<p>Could not add the entry because: <b>" . mysql_error() . "</b>. The query was $query.</p>"; } mysql_close(); } } if(isset($_POST['Submit']) && !$errors) { echo "File Uploaded Successfully."; echo($query); //*********Begin to generate thumbnails**************************************************************** function createThumbs( $pathToImages, $pathToThumbs, $thumbWidth ) { // open the directory $dir = opendir( $pathToImages ); // loop through it, looking for any/all JPG files: while (false !== ($fname = readdir( $dir ))) { // parse path for the extension $info = pathinfo($pathToImages . $fname); // continue only if this is a JPEG image if ( strtolower($info['extension']) == 'jpg' ) { echo "Creating thumbnail for {$fname} <br />"; // load image and get image size $img = imagecreatefromjpeg( "{$pathToImages}{$fname}" ); $width = imagesx( $img ); $height = imagesy( $img ); // calculate thumbnail size $new_width = $thumbWidth; $new_height = floor( $height * ( $thumbWidth / $width ) ); // create a new temporary image $tmp_img = imagecreatetruecolor( $new_width, $new_height ); // copy and resize old image into new image imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height ); // save thumbnail into a file imagejpeg( $tmp_img, "{$pathToThumbs}{$fname}" ); } } // close the directory closedir( $dir ); } createThumbs("uploads/images/","uploads/images/thumbnails/",50); } ?>
  22. So its possible to put all that on one page? I figured I could do some re-direct where it went to the page that processed the thumbnails, then forwarded to another page.
  23. I am using this tutorial http://icant.co.uk/articles/phpthumbnails/ to generate thumbnail images. I got it working but wanted to improve on it. Currently if I want to run it, I have to open the page in the browser. Is there a way to call this page after I upload the images with another page? This way thumbnails are generated as soon as they are uploaded.
×
×
  • 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.