Jump to content

AGuyWithAthing

Members
  • Posts

    42
  • Joined

  • Last visited

    Never

Everything posted by AGuyWithAthing

  1. Well if you have ever worked in a development team where you have masses of procedural files making changes becomes "messy" and if unique functionality is required you have one hell of a bloated switch statement. Basically heading towards Spaghetti Code or a Loop-switch sequence. I'm not saying it's at that state but going down this path usually ends up this way.
  2. Either, you could make php print out a set of javascript variables representing the nested values or on each creation of the form elements kick off an ajax request to check if it should be set.
  3. Please elaborate why a factory pattern is not cleaner than a switch statement. As procedural code is less maintainable than object orientated code. If a switch statement reaches 100 clauses it's a complete mess and a total joke, where a factory design pattern maintains its composure of cleanliness and maintainability. Also, if a factory pattern is not for use of variable object representation please tell me what it's for?
  4. Code indentation doesn't have a name but variable naming style does have a name such as Camel Case e.g. myVar.
  5. Well technically a switch statement in most languages is a integer only function. Being dynamically typed PHP threw this into the mixed function group. A "Cleaner" way would be to use a Factory design pattern if you don't want to make multiple comparisons. e.g. <?php $myThing = MyInit::init( $_POST ); $myThing->doSomthing(); class MyInit() { public static function init( $postedVars ) { $initClass = sprintf( 'Thing%s', $postedVars[ 'letter' ] ); if( class_exists( $initClass ) ) return new $initClass(); } // Factories shouldn't be instantiated private function __construct(){} } abstract class DoThings { abstract public function doSomething(); } class ThingA extends DoThings { function doSomething() { // Thing A } } class ThingB extends DoThings { function doSomething() { // Thing A } } class ThingC extends DoThings { function doSomething() { // Thing A } }
  6. Do you have an example of your code not working? I am not sure what you mean by "My issue is when i refresh it cancels my session!" as <?php $is_ajax = $_REQUEST['is_ajax']; if(isset($is_ajax) && $is_ajax) { $username = $_REQUEST['username']; $password = $_REQUEST['password']; if($username == 'demo' && $password == 'demo') { echo "success"; } } ?> Doesn't store a session and there is no initial ajax request fired off to see if there is a session active. You would have to modify the javascript to look something like: <script type="text/javascript"> var ajaxPage = 'doLogin.php'; function checkLoggedIn() { $.ajax({ url: ajaxPage + '?event=checkLogin', success: function(response) { if( 1 == response ) $("#form1").slideUp('slow', function() { $("#message").html("<p class='success'>You have logged in successfully!</p>"); }); } }); } $(document).ready(function() { checkLoggedIn(); // Fire off a check to see if this user is logged in $("#login").click(function() { var form_data = { username: $("#username").val(), password: $("#password").val(), is_ajax: 1 }; $.ajax({ type: "POST", url: ajaxPage + '?event=doLogin', data: form_data, success: function(response) { if( 1 == response ) $("#form1").slideUp('slow', function() { $("#message").html("<p class='success'>You have logged in successfully!</p>"); }); else $("#message").html("<p class='error'>Invalid username and/or password.</p>"); } }); return false; }); }); Change the doLogin.php to something along the lines of : <?php session_start(); switch( $_GET[ 'event' ] ) { case 'checkLogin' : echo ( 1 == $_SESSION[ 'active' ] ) ? 1: 0; break; case 'doLogin' : if( isset( $_POST['is_ajax'] ) && $_POST['is_ajax'] ) { if( 'demo' == $_POST['username'] && 'demo' == $_POST['password'] ) { session_register( 'active', 1 ); echo 1; } } break; } That should work. Note: I haven't tested this so I have no idea if there are syntax or logical errors.
  7. Cake PHP uses an extraordinary amount of memory from my experiences with it and would advise the use of Code Igniter instead unless you have a lot of resources to throw at the server(s). Basically to answer no it would not require much work to develop a CMS as all you would need to do is use an Authentication module along with a simple content system with something like a WYSIWYG editor to make it user friendly.
  8. I've never had to search an application config. Also, MySQL has this function called LIKE and REGEXP which allows searching of strings which I wouldn't use if this had searchable properties as it is not efficient but is more efficient for fast loading and dumping of data sets.
  9. You need to learn to handle these code rollouts better. I work for a company that has over a dozen applications. We make database changes on an almost daily basis. There are ways of managing this easily. No I am not, I work for a software house which manages large systems and this is a technique which is used frequently (mostly in application configurations). Mistakes are made by everyone and this is one way to cull mistakes. I am not saying this is perfect for every solution, I'm just saying telling people this is a bad technique is wrong as everything can serve its purpose. Some of the most efficient and reliable solutions can often be the easiest.
  10. put <input name="alias" type="text" id="alias"> inside your form tags as the form submit will only send the values within your form e.g. <form action="alias.php" method="post"> <p> <input name="alias" type="text" id="alias"> </p> Do you wish to use an alias? <input type="checkbox" name="formAlias" value="Yes" /> <input type="submit" name="formSubmit" value="Submit" /> </form>
  11. Usually if the mail function has worked it's an issue with your MTA (most likely sendmail, postfix or exim) If so check your /var/log/mail.log, exim log, postfix log etc and see what the MTA is doing with the email. In your shell run the following command if using sendmail : tail -f /var/log/mail.log Then run your script and usually you will see the email appear in that and give an error if it fails.
  12. Restful JSON service here is a simple little tutorial if you're interested . With my experience in iPhone development the iPhone has a great JSON library TouchJSON Well you will have to decide what the iPhone needs to do and what it will relay on from the API. Usually some level of authentication is a good starting place, then add some functionality around it. Merry Christmas.
  13. $username = $_SESSION['Username'] Simple one $username = $_SESSION['Username'] ; //<<<<<< Semicolon
  14. As part of my dissertation I wrote a memory efficient, extensible, secure and fast development PHP framework which used less memory but still had all the necessary functionality of all the major PHP frameworks. I did it and it worked and got me a first class honors I was supposed to make it open source but I've never got round to releasing it due to my other projects and work. I did write a small part of it in C which I felt wasn't a suitable task for PHP. A dissertation is usually something which contributes to the field you are working in. So something like an API/Framework, ORMS or anything that you feel will make a difference to computing.
  15. What does it not do apart from create tables and pagination links? If you want to test the pagination append "?page=2" to the end of the url
  16. In php a string in single quotes is a constant value ( is exactly what you write ) and a string in double quotes is a dynamic string ( checks for variables and escaping values ). so mysql_query('UPDATE table SET Status=1,Sending=Done,SentAt='$date' WHERE ID IN ('.implode(',', $done).')'); Won't work as the value of '$date' is breaking the syntax as you have closed the string had no operation then added a variable then opened a new constant string. To fix this you can simply do : mysql_query('UPDATE table SET Status=1,Sending=Done,SentAt=' . $date . ' WHERE ID IN ('.implode(',', $done).')'); Notice the . either side of the $date variable which concatenates string values. Another way would have been to use double quotes e.g. : mysql_query( "UPDATE table SET Status=1,Sending=Done,SentAt='$date ' WHERE ID IN ( " . implode(',', $done) . ')' ); Both should work.
  17. Actually, entirely incorrect. I and many others often store JSON or other serialized sets of data in fields in databases as the data gets modified regularly and therefore the database requires no modification when new code roll outs are made. It's a very robust way to store ever changing sets of data and to maintain clean and simple databases to prevent error and allow for efficient flexibility. The last thing I used it on was a browser state recorded where headers, referrers, cookies and various browser information which changed frequently.
  18. This will do what you want: <?php $dir = 'del_contents'; $ext = 'jpg'; recursiveDeletion( $dir, $ext ); function recursiveDeletion( $dir, $ext ) { $directoryResource = opendir( $dir ); while( false !== ( $fs = readdir( $directoryResource ) ) ) { if( in_array( $fs, array( '.', '..' ) ) ) continue; $file = sprintf( '%s/%s', $dir, $fs ); if( is_dir( $file ) ) recursiveDeletion( $file, $ext ); else if( preg_match( sprintf( '/^.*\.%s$/', $ext ), $file ) ) printf( "File %s has %sbeen deleted.\n", $file, ( @unlink( $file ) ) ? '' : 'not ' ); } closedir($directoryResource); } It will delete everything in a directory and all its sub directories.
  19. Not sure exactly what you mean but the following should work: <?php $array = array( 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1 ); $rangeMatches = array(); $rangeFlag = 0; $rangeMatch = false; foreach( $array AS $key => $val ) { if( $val === $rangeFlag && !$rangeMatch ) { $rangeMatches[] = $key; $rangeMatch = true; } if( $val !== $rangeFlag && $rangeMatch ) { $rangeMatches[ sizeof( $rangeMatches ) - 1 ] .= sprintf( '-%d', $key ); $rangeMatch = false; } } foreach( $rangeMatches AS $key => $val ) printf( "Range %s\n", $val ); Not tested this just cobbled it together.
  20. you could set the host to "127.0.0.1:3307" or w/e port you want to use? Dunno if that will work but it "should".
  21. Then show the query you would use. This should be for a one-time operation so I wasn't interested in efficiency. I did above ^^
  22. I think if you knowledge of PHP is limited then I wouldn't dive so far in. With PHP there are some basic things you need to take into account such as character matching so you could take a look at strcmp which does match case sensative letters. Instead of making two arrays you could just make one and use strtolower or strtoupper I'm not sure what you mean by "other details" so you will have to elaborate.
  23. Oh, I didn't see that those two queries were from two different tables. No matter, you can still run just one query. I'm just not sure of the exact syntax. I'll post back shortly with a solution. EDIT: Here you go UPDATE jos_vm_user_info AS i SET i.first_name = (SELECT u.name FROM jos_users AS u WHERE u.id = i.user_id) Subqueries should never be used when you can do a join as subquery will be executed on every iteration of the query where as a join will only execute the once.
  24. With regexp it's very much trial and error. What I find easier is throwing in $matches after content which will show you what you've matched (anything wrapped in curly brackets e.g. () will show in matches ). And if your regexp is not matching just keep making your match simpler until you get a match then work forward from there. Also, * is not a wildcard in perl regexp it means many or none. The '.' is a wildcard so if you wanted a wild match you would use (.*) but this can be sketchy as it will match anything and everything so it's better using a not equal to match like stated before ([^"]+).
×
×
  • 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.