Jump to content

criostage

Members
  • Posts

    42
  • Joined

  • Last visited

Everything posted by criostage

  1. Wow tyvm guys this have been very usefull, i always look foward to keep learning
  2. hi, i dont know what to say but wierdly enough ... it does help, the connection is nearly instant using 127.0.0.1. In terms of networking i know localhost is the same as 127.0.0.1, do you mind explaining why with localhost takes 'way longer'? The reason why i m asking is mainly for self study ... and tyvm for your reply, i will mark as solved if anyone can explain me ...
  3. Hello all, this is just one of those questions that i think that have an rather quick awnser. I m concerned about the PDO connection i made witch takes some time to stablish, i was using an self made class where dynamicly i create the dsn get the values etc etc .. when i stabilish the connection takes up to 1.5 seconds to finish (where without the line that makes the connection takes 0.01s for the script to finish), so i tested out with just these 4 lines of code and i get the same result as my class. $dsn = 'mysql:host=localhost;port=3306;dbname=MyDatabase;charset=UTF8'; $username = 'root'; $passwd = ''; $sqlhandler = new PDO($dsn, $username, $passwd); The code i m using to mesure the the finish time (i found this in the php website): function convert($size){ $unit=array('b','kb','mb','gb','tb','pb'); return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i]; } echo '<b>Memory used</b>: '. convert(memory_get_usage(true)).'<br>'; My "development" Enviroment is Windows 8.1 with EasyPHP 13.1 Dev Server (with PHP 5.5). My question is it's normal that just the connection takes this much to get completed? Thanks in advance
  4. As the title say's i need an critic opinion on the code i did, as i m learning all by my "self" sometimes i miss some feedback on what is best to do or not, so if anyone could throw a couple of tips or warnings please fell free to. This is the code i have: if( !defined('COREPATH') ) die('Accessing this file directly is not allowed'); defined( 'PS' ) or define( 'PS', PATH_SEPARATOR ); class autoloader{ private $_includePath = null; public function __construct() { $this->_includePath = get_include_path(); } public function register(){ spl_autoload_register( array( __CLASS__, 'loadClass' ) ); } public function unregister(){ spl_autoload_unregister( array( __CLASS__, 'loadClass' ) ); } public function addClassPath( $path ){ $this->_includePath .= PS . $path; } private function setIncludePaths(){ set_include_path( $this->_includePath ); } public function loadClass( $name ){ if( $this->_includePath != get_include_path() ){ $this->setIncludePaths(); } include $name.'.php'; } } $autoloader = new autoloader(); $autoloader->register(); $autoloader->addClassPath( CORECLASSES ); $madb = new database(); Thank you in advance.
  5. tyvm for the requinix that was very helpfull.
  6. I m using this magic method to create an function to avoid creating diferent set and get functions within this class for each variable example: class MyClass{ protected static $name; protected static $age; public static function __callStatic($name, $arguments) { $methodPrefix = substr($name, 0,3); $methodProperty = strtolower(substr($name, 3)); self::$name = 'Allan'; self::$age = '20'; #echo self::$name; switch( $methodPrefix ) { case 'get': return self::${$methodProperty}; break; } } } echo 'Hello my name is '. MyClass::getName() . ' and i m ' . MyClass::getAge() .' years old'; The output will be "Hello my name is Allan and i m 20 years old", and btw this code have already the code that i got from requinix reply, so it's working. Tyvm that did the trick , would you mind pointing me out the logic behind it?
  7. Hello, i m trying to learn magic method's and i have an small question on something that probably it's extremely easy, but i m not getting there ... Here's the "simple" code i got: class MyClass{ protected static $name; public static function __callStatic($name, $arguments) { $methodPrefix = substr($name, 0,3); $methodProperty = strtolower(substr($name, 3)); self::$name = 'Allan'; echo self::$name; switch( $methodPrefix ) { case 'get': return self::$methodProperty; break; } } My objective is to remove all the get and set's we you usually use in the code so i m using the __callStatic in order to retrieve or set variables inside the class, for example setName('John'). My question is if i want get the value of the protected static variable called name, usually you would just do return self::name, but let's say i have an more evolved class and i have several protected static variables (like age, genre), so here an small issue comes into my mind, how can i use the the content of the variable $methodProperty to return the proper protected static variable? My attempts resulted in the following error: Fatal error: Access to undeclared static property: MyClass::$methodProperty i understand the error but i have no idea how to work it arround... Thanks in advance.
  8. Hi thank you for your response, i did a couple of tests (including installing php 5.3.3) i get the same result as i described. I further found that mdbtools (the driver that was installed in the unixODBC) last version is from the year 2004, at this point i have no idea what to do ... thank you very much for your reply tho.
  9. Hello all, i m doing this small piece of code to test out how can i get some data out of an mdb file, so i can peridicly check it and import new data into something easier to work with ... example MySQL. This script is to runned as a cron job, so i m running it using the php cli, this is the code i have so far: <?php error_reporting(E_ALL); ini_set( 'display_errors', 1 ); $mdbfile = "/var/www/html/db.mdb"; if( file_exists( $mdbfile ) ){ try { $dbh = new PDO("odbc:DRIVER={MsAccess};DSN=mdbtest;"); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); }catch (PDOException $e) { echo $e->getMessage(); } }else{ die('File does not exist!'); } foreach ( $dbh->query("SELECT * FROM MY_TABLE") as $row ){ echo $row['Row1']; } if(isset($dbh)){ $dbh = null; } ?> when i run "php -f /var/www/html/php-pdo-odbc.php", i get the error "Segmentation fault", if i try to open the file from the web browser i get an error "The connection was reset". Commenting out some code i figured out that the error is in the foreach, but i dont see any issue with it .. could anyone give me an though why is this happening? I m using CentOS 6.4 with Apache 2 and PHP5.5.6. Thanks in advance
  10. So i guess i was right on my first bunches, tyvm for the information and sorry for the newbish question i was only used to do small scripts this will help me in the future.
  11. The $AppOptions is set in the Main.php File: <?php /** * Array that contains the application settings to be applied at it's startup. */ $appOptions = array ( 'Developer' => TRUE, 'Timezone' => 'Europe/Lisbon', ); The idea would be to apply this array to the bootstrap, in the furure i would like to add more options to that file
  12. Hello, I would like to request a little of help in my code, I m trying to do an database for my movies in php, instead of using an framework or just do code without any structure, i decided to try adventure my self into higher grounds and try to make the application as a little framework that i could use for future projects the main reason behind this is mainly to learn proper PHP programing skills. In the past few weeks i have read online and changed my code so many times but or i m not understanding the class programing style or i m missing something. Here's my Work so far: Index.php <?php defined( 'DS' ) or define( 'DS', DIRECTORY_SEPARATOR ); defined( 'ABSPATH' ) or define( 'ABSPATH', dirname(__DIR__) ); defined( 'SYSPATH' ) or define( 'SYSPATH', ABSPATH . DS . 'System' ); defined( 'WEBPATH' ) or define( 'WEBPATH', ABSPATH . DS . 'Public' ); defined( 'PKGPATH' ) or define( 'PKGPATH', ABSPATH . DS . 'Packages' ); defined( 'APPPATH' ) or define( 'APPPATH', PKGPATH . DS . 'Application'); defined( 'COREPATH' ) or define( 'COREPATH', PKGPATH . DS . 'Framework' ); require ( PKGPATH . DS . 'Bootstrap.php'); Bootstrap.php <?php class Bootstrap{ static protected $_appConfig; static public function init ( ){ self::$_appConfig = APPPATH . DS . 'Config' . DS . 'Main.php'; require self::$_appConfig; var_dump($appOptions); } static private function setEnv( $appOptions ){ /** Set application enviroment to developer or 'production' */ Switch( is_bool( $appOptions['Developer'] ) ? $appOptions['Developer'] : FALSE ){ case TRUE: error_reporting( E_ALL ); ini_set( 'display_errors','On' ); break; default: error_reporting( E_ALL ); ini_set( 'display_errors', 'Off' ); ini_set( 'log_errors' ); ini_set( 'error_log', SYSPATH . DS . 'logs' . DS . 'errors.log' ); break; } /** Set's default timezone for this application */ date_default_timezone_set($appOptions['Timezone']); } } Bootstrap::init(); var_dump($appOptions); The Main.php file only contains the array appOptions (for now), i m thinking in the future adding the Database connection and Application requirements (example if you need mysql or gd modules installed). Okay now focusing on my question a little the output of the code above delivers the follow: array(2) { ["Developer"]=> bool(true) ["Timezone"]=> string(13) "Europe/Lisbon" } Notice: Undefined variable: appOptions in C:\EasyPHP\data\localweb\Framework\Packages\Bootstrap.php on line 33 NULL Note: 1st line is from the var_dump inside the init and 2nd is from outside the bootstrap class. With this i assume that the require i do in the init function only includes the file for the class and not for the application over all? is this the best way of doing an bootstrap or there's an better way? Thanks in advance,
  13. Got it i will read a little bit more on the internet about this, passing the object from class to class seen's a bit painful but like you said, if i use it this way there's no point in using classes. TYVM for the explanation =)
  14. yeah that worked, tyvm. just a question tho, if i use it this way (with the objects) i will have always to pass the object so it can be used inside the class, for example: <?php include (class.authentication.php); include (class.mysql.php); $authobj = new authentication(); $mysqlobj = new mysql(); $login = authobj->login( $username, $password, $mysqlobj) then inside the class.authentication.php <?php class authentication{ protected $loginquery = ''; public function login( $username, $password, $mysqlobj ){ $querylogin = $mysqlobj->checkauth( $username,$password ); } } This way things wont become a little more complicated to manage? or there's an easier way to accomplish this? thanks again in advance =)
  15. Hi thanks for the reply, i already had that in other file (called init.php), sorry for not mention it this is the content of the file: <?php # The PHP extention files are usually protected by the webserver, but abit of # extra protection never hurted anyone. if( !defined('abspath')){die("Accessing this file directly is not allowed." );} # This file will initialize all classes so they will be usable for the remaining # PHP script files. require_once( classes.'class.mysql.php'); require_once( classes.'class.authentication.php' ); # Start the classes as an object $mysqlobj = new mysql($dbhost, $dbport, $dbname, $dbuser, $dbpass); $authobj = new authentication(); ?> I didnt mention it because i have some files already and post them all is kinda ... but if needed let me know i will try to post it some where.
  16. I would like some expertise of some one that could help me on this i m getting the following error, on the code i m developing: these are the lines of code (not completed ofc ..) login.php <?php # The PHP extention files are usually protected by the webserver, but abit of # extra protection never hurted anyone. if( !defined('abspath')){die("Accessing this file directly is not allowed." );} # The login sequence for the user is made by the following steps: # Uppon entering this file (login.php) the POST variables 'username' and 'password' # are tested to see if the user entered any data to be authenticated this test is # made by checking if both variables are set (by using isset). if they are set this # means the user is trying to authenticate if( isset( $_POST['username'] ) && isset( $_POST['password'] ) ){ $login = authentication::login( $_POST['username'], $_POST['password'] ); }else{ ?> <form action="?go=login" method="post"> <table align="center"> <tr> <td><font size="2">Username</font></td> <td><input type="text" name="username" /></td> </tr> <tr> <td><font size="2">Password</font></td> <td><input type="password" name="password" /></td> </tr> <tr> <td colspan="2" align="center"><input type="submit" value="Login" /></td> </tr> </table> </form> <? } ?> class.authentication.php <?php # The PHP extention files are usually protected by the webserver, but abit of # extra protection never hurted anyone. if( !defined('abspath')){die("Accessing this file directly is not allowed." );} class authentication{ protected $loginquery = ''; # Uppon class declaration, this class will start an php session function __construct(){ session_start(); } # Main function on the autentication class, this function will be triggered # out site de class and will carry out all the necessary steps to authenticate # an user. public function login( $username, $password ){ echo "Username: ". $username ." | Password: ". $password; } # Clean's up the user session variables by unsetting the $_SESSION array, # destroying the session and regenerate an new ID if the user comes wants # to stay on the page but not logged in. public function logout(){ session_unset(); session_destroy(); session_regenerate_id(); } } ?> I started to learn PHP not so long ago where some of the time i couldnt do much or learn due to work and rl, so i know probably i m not doing things the right way, if possible please let me know what i m doing wrong. Thanks in Advance
  17. Hi, I m doing some work for my self an because of that i been reading a lot arround about PHP, and theres something that i would like to ask a bit of enlightenment. So my question is as the title says about html form's using php to insert data into mysql, i been reading tutorials arround the interwebs and even made afew successful tests, but pretty much all tutorials use 2 files to accomplish this the html file with the form and an insert.php where the actual code is stored so this made me think is this how usually it's done? in over all you will have 1 file for the form, 1 for the insert, 1 for the edit php code and 1 for delete. How do you guys usually do it? PS: one of the tests i did was making 1 single file with all these using an switch. My interest in making this question is solo to learn how other people do it to see if i m in the right way. Thanks in advance.
  18. The page i gave you contain's examples on what you need to change please figure out your self ....
  19. Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'talos342c'@'localhost' (using password: YES) in C:\wamp\www\myNewweb\storescripts\connect_to_mysql.php on line 19 <- Wrong user name or password, the username doesnt have access to connect to the server (MySQL Permitions) one of the both Read this article: http://dev.mysql.com/doc/refman/5.0/en/access-denied.html
  20. http://php.net/manual/en/function.ereg.php This function is obsolete and should not be used as the php site say you might find this page usefull -> http://devthought.com/2009/06/09/fix-ereg-is-deprecated-errors-in-php-53/
  21. try do this: $sql="UPDATE application SET Status = '$status' WHERE Name= '$member'"; if(mysql_query($sql,$con) or die(mysql_error())) { echo 'Status Changed.<br /><a href="../applications.php">Return To Members List</a>'; } Adding the "or die(mysql_error())" will tell you if there's any error on MySQL part. I had this issue on my "learning project", i work on 2 machines at work and at home, and when i set up the site at work i didnt gave permitions to the user to modify the database data result the site was working except for the writing into the mysql i couldnt see any changes and all the code was working t home. Hope this helps you out
  22. Well usually i dont like to use symlinks in apache due but its an diferent point of view. Thanks guys =)
  23. I been wondering how to protect all the files that contain classes, functions and forms in php to prevent direct access to something that the user shouldnt be able to without the proper check's (typing http://server/inc/login.php insteand of http://server/), and i came to this small idea of checking if an object is set or not but i m wondering if this is really the best idea here's what i have (the case bellow will protect an login form to be accessed directly): <?php if(!isset($mysqlobj)) die(); if( isset( $_POST['username'] ) && isset( $_POST['password'] ) ){ $login = authentication::login( $_POST['username'], $_POST['password'] ); if( $login == true ){ header( 'location:?go=home' ); }else{ $_SESSION['message'] = 'loginfailed'; header( 'location:?go=login' ); } }else{ if( !empty($_SESSION['logged'] ) && $_SESSION['logged'] == true ){ header( 'location:?go=home' ); }else{ ?> <div id="loginform"> <form action="?go=login" method="post"> <table align="center"> <tr> <td><font size="2">Username</font></td> <td><input type="text" name="username" /></td> </tr> <tr> <td><font size="2">Password</font></td> <td><input type="password" name="password" /></td> </tr> <tr> <td colspan="2" align="center"><input type="submit" value="Login" /></td> </tr> </table> </form> </div> <?php } } ?> Just looking for an "best practice" i tried google for it but i couldnt get to an straight awnser any enlightment is appreciated.
  24. Hello, i been making a site to learn some PHP. I been always searching about what's the best way of using the PHP functions, classes and objects but i have a small question that i couldnt found the awnser by my self. so far i m inicializing an PHP class like this: 1st case $themeobj = new theme(); Today i found an tuturial that used an other way of calling an function inside the class: 2nd case theme::loadTheme; I understand that the way i m doing, your iniciating the variable $themeobj as an object of the class theme and that the theme:loadTheme just calls the function loadTheme inside the theme class (please correct me if i m wrong), but here's where is where i need abit of enlightment. Using the 2nd case will "skip" the loading of the __construct function? when should you use the 1st case or the 2nd case? Every time i needed an function from theme i would use $themeobj->loadTheme($param) its safe to use theme::loadTheme($param)? Thanks in advance
×
×
  • 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.