Jump to content

gizmola

Administrators
  • Posts

    5,945
  • Joined

  • Last visited

  • Days Won

    145

Everything posted by gizmola

  1. I'm not sure I follow your description in regards to "multiple files", but I will say that the "php-html" interaction you're asking about is provided by Ajax. You write javascript code which sends specific form data to a php script which can then do the validation and return a message. Your ultimate processing script should not depend on the "pre-validation" done in javascript functions or the ajax function, but it does handle common tasks like verfication that a "new" username has not been used already.
  2. There are RESTful API's, xml-rpc and SOAP among other technologies, that in general people call web services. In essence they are the solution to your requirement.
  3. What is built-in is the $_SERVER['REMOTE_ADDR'] which will give you the IP address of the visitor. Store this, and you can use [m]gethostbyaddr[m] which will do a reverese dns lookup based on the IP and return you a hostname. Lookups like these can be very slow, especially when there isn't proper DNS, so you probably don't want to have your api scripts doing this lookup and storage during the api calls. You're better off writing a seperate script that goes through your database of visitor IP's, does the gethostbyaddr calls and updates a hostname field in the db. Keep in mind that there is no guarantee that an IP has a hostname associated with it, nor is there a guarantee that the hostname you get from the reverse is going to tell you what you want to know. For example, a shared hosting server could have hundreds of companies sharing the same IP address, and the reverse DNS if it has been set, will only point you to the hosting company.
  4. The string you provided has no body tag. Now that I'm clear on what you were doing, I'm going to hazard a guess that if you reorder your preg_replace so that you do the menu replacement first, you might not have the current issue you're facing.
  5. Really need to see code, and the string that you're trying to do this conversion on.
  6. There is no good reason to use a regex when you have an exact match like this. Use str_replace instead.
  7. I'm a big fan of the Symfony2 documentation. It's a component framework (a framework made up of a number of components, any one of which can be used independently of the framework) which has become THE framework/library trend in the last year. It also has a micro framework based on it named Silex, which is more minimal/library based yet shares the same components as the full stack Symfony2, and microframeworks are cool for learning the pieces of a framework without all the complexity (see trq's Proem for another example). I personally wouldn't advise you spend a minute with any framework that isn't already using Composer. With that said, any of these frameworks comes with a fair amount of complexity, unless you have a good idea what MVC, Validators, Forms, ORM's, Templates etc. fit into the mix. Often what I find is that the frameworks have good introduction to the surface level, but as soon as you want to do something that veers from the simplistic, you're quickly in over your head, and this is why many framework people don't even try to have much in the way of documentation.
  8. A couple of obvious things: - Check your syntax... there is a php end block in the middle of your code. - The line $info = mysql_fetch_array( $data )) is incorrect in several ways. It should be $info = mysql_fetch_array($data); -The $_POST superglobal array name must be uppercase. In several places you attempt to access $_Post. PHP variable names are case sensitive ($Foo is not the same as $foo!). Of course you probably have not noticed the issue at this point because you aren't doing anything with the $_POST variables in the script. -Your current query doesn't work because you try and do 2 queries in a row, where the first result is stored to $data, and the 2nd query attempts to use a $query variable that doesn't exist. It's a bit of a mess, and doesn't do much at present. A better intermediary test would be something like this: $result = mysql_query("SELECT * FROM users") || die(mysql_error()); if ($result) { } else { echo "No users found."; } $rows = array(); while ($row = mysql_fetch_assoc($result)) { $rows[] = $row; } foreach ($rows as $row) { echo "Email: {$row['email']} <br> Username: {$row['username']} <br> Age: {$row['age']} <br><br>\n"; }
  9. In case it's not clear, "php" has several flavors. There is the php that most people think of as being part of the webserver, and then there is the "Command line interface (CLI)" php that is a seperate executable program. In a shell you can typically run the CLI by typing php -h or php.exe -h and you should see something like this: [david@penny ~]$ php -h Usage: php [options] [-f] <file> [--] [args...] php [options] -r <code> [--] [args...] php [options] [-B <begin_code>] -R <code> [-E <end_code>] [--] [args...] php [options] [-B <begin_code>] -F <file> [-E <end_code>] [--] [args...] php [options] -- [args...] php [options] -a -a Run as interactive shell -c <path>|<file> Look for php.ini file in this directory -n No php.ini file will be used -d foo[=bar] Define INI entry foo with value 'bar' -e Generate extended information for debugger/profiler -f <file> Parse and execute <file>. -h This help -i PHP information -l Syntax check only (lint) -m Show compiled in modules -r <code> Run PHP <code> without using script tags <?..?> -B <begin_code> Run PHP <begin_code> before processing input lines -R <code> Run PHP <code> for every input line -F <file> Parse and execute <file> for every input line -E <end_code> Run PHP <end_code> after processing all input lines -H Hide any passed arguments from external tools. -s Output HTML syntax highlighted source. -v Version number -w Output source with stripped comments and whitespace. -z <file> Load Zend extension <file>. args... Arguments passed to script. Use -- args when first argument starts with - or script is read from stdin --ini Show configuration file names --rf <name> Show information about function <name>. --rc <name> Show information about class <name>. --re <name> Show information about extension <name>. --ri <name> Show configuration for extension <name>. You can write a php script that does all the work needed as described by Kicken and Socialcloud, and since there is no web server needed, it can be run by the CLI using php -f scriptname.php Combine this with the windows scheduler or cron, so that the program runs periodically, and you have a simple functional offline system. I personally would set it up to run every minute, as 5 minutes is a long time to wait. If you do set it up in linux with cron, you can utilize http://linux.die.net/man/1/flock to insure that only one of your cron jobs is running at a particular time, which can help you safely decrease the periodicity with which you run a script. With cron, you can run scripts every minute if you want.
  10. I'm guessing that webmin creates seperate vhost files for each of these entries, which are then read in. I don't know if webmin does this automatically, but anytime you change sometthing in an apache configuration file, apache has to be restarted for those changes to take effect. Make sure you restart it manually just to be sure. With port based vhost, the variation is the port. With named based vhosts, the variation is the name of the host. There's very little reason to mix them, so I'm confused about why you would be changing ports. Named based vhosts look at the HTTP header and read the "host" field the browser sends along (part of the HTTP 1.1 specification) and route to a specific vhost based on matching the hostname. Hence whatever your browser sends along is what needs to match your vhost config. Ultimately, the best way to determine what is going on is to find the vhost file/section that webmin makes, and take a look at it. If you copy it into a replay (and something else I wrote did not help you determine the problem) then we might be able to aid you further.
  11. It seems you have a couple problems here. The first one is that it looks like your schema supports multiple instruments per musician. So your sortation is inherently flawed because you are checkng the equivalence of arrays rather than the strings that contain the instruments themselves. If you're alright with checking the first instrument then you should probably change your cmp function to compare $a->instrument[0] vs $b->instrument[0] for both comparisons. I also noticed a subtle bug you have: function cmp($a, $B){ Notice that $B should be $b. PHP variable names are case sensitive, so the compare function currently is not working at all if that is your real code, although as I said, it's also not going to work the way you want unless you get down to the string comparison of a specific array element in each array. Assuming all that is working, you can effectively add the catagory headers by using a variable that you initialize before the output loop, and that you check to see if it has changed just prior to doing the member block output. $category = ''; foreach ($members as $member ) { // get all the user's data $member_info = get_userdata($member->ID); //did category change? if ($category !== $member_info->instrument[0]) { $category = $member_info->instrument[0]; echo "<h1>$category</h1>\n"; }
  12. Yes, I do know how to fix this, but I have no intention of doing that work for you, as there's nothing in it for me or this community to just change the code of a library you didn't write to your specifications. That is not what this community exists to do. Perhaps you'll sucker one of the other 20 forums you cross posted this question to into getting an answer, or you could actually dig into javascript and learn a little bit. By the way it doesn't help to obfuscate your source as you did here, which only makes you come off as deceptive and underhanded.
  13. What operating system is the server you are running this code on?
  14. The way people do this currently is to utlize javascript/dhtml in the client that dynamically alters the form on the clientside. Libraries like jquery have greatly decreased the complexity of doing this type of development, and making it highly likely the resulting solution will work across browsers. Kicken has demonstrated a nice trick that facilitates this greatly on the serverside.
  15. Is there a reason beyond the academic that you are reinventing phpMyAdmin, Adminer and several other similar tools? As MuddyFunster stated, you only get results on SELECTS. There are also seperate api calls to show you information on rows affected by insert/update/delete queries, but aside from that it sounds like you want the equivalent of a tabular interface, and that's already been done quite well in other existing tools.
  16. @scm22ri, Looking at your function, it seems that what you were trying to do is combine a few different things. It's best to try and break things down into individual functions that do 1 thing well. In the case where you have one set of data (login credentials) and you want to do a few different things like: -Check if a user is already logged in -check credentials against database and determine if username/password match -Store most of the user information in the session along with a "loggedIn" variable. These are all things you want to do at some point, but the flow and combination of when you need to do these things is varied. Let's say you tried this: function isLoggedIn() { if (/*something */) { return true; } else { return false; } } Then the only thing that function should do is return true/false. Then at the top of your scripts you could have this, perhaps in a header() include. if (!isLoggedIn()) { header('Location: login.php'); exit(); } If you try and break your code into smaller pieces, it will be more robust, easier to debug and easier to reuse.
  17. I disagree.. that is far from a good practice. No Salt being used, and a single encryption is far from good practice. However, probably the worst thing about your comment, is that he was already doing a SHA1 hash on the password. Anyone can have a screed of procedural code in a script. Just because you can, doesn't mean that you should. Functions are a good idea, even if the OP hasn't entirely figured out how and where it's best to use them. For something that is done repeatedly, and typically in a number of different places, having a function that can be called is a good idea.
  18. Aside from the IP checks, I realized there are additional hurdles. I don't really have enough information in regards to what you're trying to do. FTP servers do not implement the HTTP protocol. Many browsers however, will work with ftp:// as a scheme. What this means is that they'll pass ftp commands back and forth to a server because they have scheme handling functions that facilitate this. Conversely, ftp clients aren't web browsers. All they know how to do is talk to web servers. An ftp client doesn't understand HTTP protocol, so a php script that does HTTP Location header redirects isn't going to work for an ftp client.
  19. The remote_addr is not going to = the server's address. What you really want is to do is just compare the network portion of the numbers. There's a few different ways to do this, but here's one that mimics the way netmasks work. Yours needs to match whatever subnet your workstations actually use... I'm assuming it's a class C standard here, and also assuming your internal network is 192.168.2. $netmask = ip2long('255.255.255.0'); $internal = ip2long('192.168.2.0'); $remote = ip2long($_SERVER['REMOTE_ADDR']) & $netmask; if ($internal == $remote) { // Intranet client } else { // External client }
  20. I have to admit, this gave me a bit of a chuckle: if(intval($num) == $num){ $num = intval($num); } Let's see... so if intval($num) already == $num, let's go ahead and set it = to what it was already equal to? There's some code that will never execute. I'm picky about this, but typecasting to an int (when you need to) is much faster than calling the intval function. Of course intval does more than casting to an int does, but in most cases you can use a cast to int and achieve the same goal. For example: $num = (int)$num; I'm guessing you probably figured out that we didn't get the posted image, but perhaps that's a security issue on our end? Ok I looked at the link. Image shack is basically a website that stores images and lets you view them in a web page... it's not actually an image that you can reference in an image tag. I editted your post to be a link instead.
  21. My recollection is that likes don't register immediately. As the owner of the "liked" page, you get a notification whenever someone likes the page.
  22. Here's the thing about functions... they don't really help if you never call them. There's also the question of DRY. You have a function and a script that seem to be 90% repeated code. Hard to tell what you're after here. In terms of the function itself: Functions should return something, yours does not. That makes it more of a procedure, but you should rewrite it to return a value that can then be acted upon. There's no need to escape the password since you're sha1 hashing it. Don't store the user's password in the session. It's bad practice at best, security hole at worst. Why are you querying the user data 2x? You don't need to do that just to call mysql_num_rows(). You can call mysql_num_rows and still fetch the result set (or not) afterwards. You want to check for the match 1st, then only if its mysql_num_rows > 0 will you fetch the row. Probably the function should return false otherwise, and true when the user is found by name/password match. You really want your database to insure that 'name' is unique. Usually you do this by adding a unique constraint(or unique index) on the name column. That way, there is no possibility for there to ever be more than 1 row in the database for a given user. The possibility of your inserting 2 rows with the same username is a major bug that your system should never allow.
×
×
  • 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.