
ignace
Moderators-
Posts
6,448 -
Joined
-
Last visited
-
Days Won
25
Everything posted by ignace
-
this manner is called "variable variables" just so you know
-
you should be using sprintf() especially when using queries, also *_real_escape_string() is recommended or something along those lines like addslashes()
-
[SOLVED] uploading images through php form
ignace replied to soycharliente's topic in PHP Coding Help
1. nope, you don't have to change the filename, but when it exists it will be overwritten (btw: when using file_exists() results are cached, use clearstatcache() to clear the buffer) 2. time() gives the current time and will never be the same because it keeps counting up... (unless you can time travel) 3. done. -
[SOLVED] uploading images through php form
ignace replied to soycharliente's topic in PHP Coding Help
add the current time after your image, this way the image never will have the same name and never will be overwritten // 1. seperate the file to: array ( 'file', 'ext' ) // 2. gleu it together using: _123456. // 3. result: file_123456.ext $file = implode('_'.time().'.', explode('.', $_FILES['uploadname']['name'])); // only usable under file.ext condition, if you need a more complicated version pm me -
// recommended suggestion $time = time() - 60 * 15; $members = sprintf("SELECT * FROM members WHERE last_activity <= %d", (int) $time); // polymorphism ftw? // $members = mysql_query($members); $result = mysql_query($members); $i = 0; if (mysql_num_rows($result) > 0) { while (false != ($row = mysql_fetch_assoc($result)) { echo($row['username']); ++$i; } printf('There are <b>%d</b> users online.', (int) $i); } session_name("sid"); session_start(); include("database.php"); $user = $_SESSION['username']; // UPDATE phpbb2_users SET lastseen=NOW() WHERE username = '{$user}' // lastseen? // SELECT * FROM members WHERE last_activity <= $time // last_activity? // using last_activity don't know which one is correct $q = "UPDATE phpbb2_users SET last_activity=NOW() WHERE username = '%s'" mysql_query(sprintf($q, $user)) or die(mysql_error());
-
LiamProductions means he fixed some errors.. forgot the $to issue though so here it is with all errors fixed according to adrianphp <?php error_reporting(E_ALL); $msg = "We would like you to come see our site!\nThis is why:\n\n"; $msg .= "Your friend " . $_POST['FullName'] . " thought you might like Somewhere.com\n"; $msg .= "So comeon " . $_POST['FriendName'] . " and join us now!\n"; $msg .= "Someplace.com is a site for investors and people\n who want to sell their homes quickly\n"; $msg .= "So what are you waiting for?\n Come see what your friend is talking about!\n"; $to = $_POST['Email']; $subject = "Your friend " . $_POST['FullName'] . " wants you to check this out!"; $headers = "From: register@Somewhere.com\n"; $headers .= "Reply-To: noreply@Somewhere.com\n\n"; if (mail($to, $subject, $msg, $headers)) { echo "Thanks For Telling Your Friend About Us!"; } else { // mail not send... } ?> more about mailing in php: http://www.php.net/manual/en/ref.mail.php
-
no thx, we are only here to do just this
-
in addition to what grimmier wrote: instead of step 3 where you would delete all rows out of a table you will probably not use anymore, use: DROP TABLE your_table this will delete the complete table
-
we all can help, but would it be possible to be a bit more specific? If you want to hire someone, then you are posting in the wrong section...
-
i'm gonna answer a lot more then you originally asked for (don't know if this is a good thing though): first of all, i do not recommend using sessions like they where originally implemented, but using a db instead, much easier using the session_set_save_handler() function implemented in php (dl: http://www.php.net/manual/en/function.session-set-save-handler.php) you will still be able to use the session_* functions as you would normally afterwards but your application would be much secure. Also you are using the following query: SELECT username, password FROM accounts or something along those lines afterwards you do something like: if ($user==$row['username'] && $pass==$row['password']) i know where you are pushing to.. but then i would suggest using sprintf("SELECT username, password FROM accounts WHERE username = '%s'", $user); sprintf (if not familiar): http://www.php.net/manual/en/function.sprintf.php because your situation would go through the complete table (what mysql also does) until it reaches the row which contains the username & password as requested, not a problem if you only have 2 rows, but imagine a few million? and you happen to be the latest registered user... by the time the user is logged in he would be reaching his 99th birthday (just joking). so make sure you atleast narrow it down by using atleast a where clause afterwards you check if the provided password equals the one stored in the database, however make sure the password stored is encrypted.. useful encryption links: http://www.php.net/manual/en/function.md5.php (32 character length) http://www.php.net/manual/en/function.sha1.php (40 character length, recommended) check if it equals using: if (sha1($pass) == $row['password']) now for your question in how to build a logout button, is quite simple you just check if the user is logged in, like you already did, there are more advanced ways so go ahead and have a look at: http://pear.php.net/package/Auth documentation can be found here: http://pear.php.net/package/Auth/docs hope it helps, ignace
-
if (is_integer($decimal_or_integer)) { // integer (normal) } else { // decimal (not normal ) } usefull links: http://www.php.net/manual/en/function.is-float.php http://www.php.net/manual/en/function.is-integer.php
-
using mysql and php as offline inventory manager for a shop
ignace replied to ryks's topic in PHP Coding Help
there are always security risks, but i don't really understand what you are planning to do? So mysql is located on your comp? And you want to use it as a storage for an online application? Or do you mean that you are developing an entire application offline? -
I have a file like this: [database] type=mysql server=localhost user= pass= name= [website] title= description="a long description" keywords="a, long, description, in, short" i load this file throught file() which gives me an array where every key is a line from the file. Now, what i want to do through regular expressions is finding the lines which contain a word between the [ and ], so as the backslash is the escape character i tried the following: ^(\[[a-z]\])$ but nothing turns up, probably you guys know why, but i don't, so pls fill me in, i already read a book about regular expressions without any success i also have a cheat sheet doesn't work for me neither thanks in advance, Ignace
-
You are experienced with cron so just call this snippet, buf before you do use this, add the absolute folder path in sFolder! <?php // Folder !!!NO TRAILING SLASH!!! $sFolder = '[folder comes here]'; // Delete all files within the folder DeleteRecursive($sFolder); // Function function DeleteRecursive($sFolder) { // open folder $pFolder = opendir($sFolder); // read through folder while (false != ($sFile = readdir($pFolder))) { $sAbsolute = $sFolder . "/" . $sFile; if ($sFile != "." && $sFile != "..") { if (is_file($sAbsolute)) { unlink($sAbsolute); } else { // Directory assumed DeleteRecursive($sAbsolute); // Remove all files within the folder rmdir($sAbsolute); // Remove the folder } } } } ?>
-
1) yes just use the _POST superglobals 2) b is recommended, c is even better 3) sessions, are cookies on the server, you should only be worried about session hijacking etc... more about session security, can be found within the source code of: http://pear.php.net/package/Auth 4) yes, your job is done, however i do not recommend to put secure files into the web root, i mainly put them in the real root now, this is my advise, and it is solely supported by my current knowledge so i sincerely recommend consulting other persons, who are more advanced in SSL greetz, Ignace
-
seems not but you are encouraged to make your own, so someone some day may call upon your pre built function
-
yes that is possible, however i am not really experienced into cron, however after asking my friend google for some advise, he gave me these results: http://www.unixgeeks.org/security/newbie/unix/cron-1.html http://www.aota.net/Script_Installation_Tips/cronhelp.php3 greetz, Ignace
-
[SOLVED] Having slight problems with a piece of code
ignace replied to JoelRocks's topic in PHP Coding Help
well, then i would suggest you use my best friend called debug, and do: echo($answer . " == " . $input); if (strcasecmp($answer, $input) == 0) ... -
if it says that DIRECTORY_SEPERATOR does not exist, then add the following code just above that snippet: (normally it is implemented into php) define('DIRECTORY_SEPERATOR', (substr(PHP_OS, 0, 3) == 'WIN') ? "\\" : "/"));
-
// The mistake you make, is very common // you forgot to include the path, because the file 1.jpg does not exist // in your current directory, but it exists in your upload_folder/1.jpg while ($file = readdir($dir_handle)) { if ($file <> "." && $file <> "..") { $full = $path . DIRECTORY_SEPERATOR . $file; rename($full, strtoupper($full)); } }
-
If you wanna program your own, i suggest reading about MVC (model-view-controller) framework, and starting by using CakePHP and CodeIgniter
-
ob_start(); on the top of your index.php page afterwards right before the ob_end_clean(); you put: $BUFFER = ob_get_contents(); and at the very bottom of your index.php page echo $BUFFER;
-
Table Pictures have Space between the Rows in FF!
ignace replied to anybody99's topic in PHP Coding Help
<table style="border-collapse: collapse;" table border="0" img { margin: 0; padding: 0; } bordercolor="#111111" cellpadding="0" cellspacing="0" width="760"> that is a wrong implementation of what i suggested, it should be (if you want it to be inline with your element): <table border='0' style='border-collapse: collapse;' bordercolor=... and for every image of you: <img style='margin: 0; padding: 0;' /> -
how i would code this? using smarty: login.tpl {include file = 'header.tpl'} <form action='{$action}' method='post'> <table border="0"> <tr> <td><label for='{$lblUsername}'>{$txtUsername}</label></td> <td><input type='text' id='{$lblUsername}' name='{$lblUsername}' maxlength='25' /></td> </tr> <tr> <td><label for='{$lblPassword}'>{$txtPassword}</label></td> <td><input ... </tr> </table> </form> {include file='footer.tpl'} login.php $oSmarty = new Smarty; $oSmarty->assign('action', ''); $oSmarty->assign('lblUsername', 'username'); // If you are using PEAR packages like Auth, this would be something like: // $oSmarty->assign('lblUsername', $oAuth->getPostUsernameField()); $oSmarty->assign('txtUsername', 'Username:'); ... $oSmarty->display('login.tpl');
-
[SOLVED] Having slight problems with a piece of code
ignace replied to JoelRocks's topic in PHP Coding Help
// leave out the single quotes around variables if ($answer == $input) // using strcmp() and strcasecmp(); // these functions return 0 when equal, < 0 when one is shorter then the other, > 0 when one is longer then the other // case sensitive if (!strcmp($answer, $input)) // case insensitive if (!strcasecmp($answer, $input)) // check: http://be.php.net/manual/en/function.strcmp.php http://be.php.net/manual/en/function.strcasecmp.php