
AGuyWithAthing
Members-
Posts
42 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Not Telling
AGuyWithAthing's Achievements

Newbie (1/5)
0
Reputation
-
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.
-
how to retain the values in the sub process?
AGuyWithAthing replied to tayys's topic in PHP Coding Help
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. -
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?
-
Code indentation doesn't have a name but variable naming style does have a name such as Camel Case e.g. myVar.
-
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 } }
-
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.
-
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.
-
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.
-
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.
-
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>
-
mail($to,$sub,$body1, $headers); DOESNT work
AGuyWithAthing replied to megetron's topic in PHP Coding Help
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. -
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.
-
$username = $_SESSION['Username'] Simple one $username = $_SESSION['Username'] ; //<<<<<< Semicolon
-
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.