Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi all,
Vanilla are planning an update to the site on April 24th (next Wednesday). It is a major PHP8 update which is expected to boost performance across the site. The site will be down from 7pm and it is expected to take about an hour to complete. We appreciate your patience during the update.
Thanks all.

Learn php tutor needed

24

Comments

  • Registered Users Posts: 880 ✭✭✭raher1


    Will Apache MySQL work on a apple or is it just windows. Alternatives is always considered.


  • Moderators, Society & Culture Moderators Posts: 17,642 Mod ✭✭✭✭Graham


    raher1 wrote: »
    Will Apache MySQL work on a apple

    Yes, I have it running here permanently.


  • Registered Users Posts: 880 ✭✭✭raher1


    Graham wrote: »
    Yes, I have it running here permanently.

    You haven't got a link. I lost my link and keep getting other not links.


  • Moderators, Society & Culture Moderators Posts: 17,642 Mod ✭✭✭✭Graham


    MAMP or MAMP Pro is one of the easiest ways to get it configured/running.

    http://www.mamp.info/en/index.html


  • Registered Users Posts: 5,999 ✭✭✭Talisman


    BitNami MAMP Stack provides a complete PHP, MySQL and Apache environment for Mac OS X. It also has phpMyAdmin, SQLite, Varnish, ImageMagick, ModSecurity, XDebug, Xcache, OAuth, Memcache, FastCGI, APC, GD, OpenSSL, CURL, openLDAP, PEAR, PECL and development frameworks: Zend Framework, Symfony, CodeIgniter, CakePHP, Smarty, Laravel.

    Versions of software included in the current release:
    Apache 2.4.3
    MySQL 5.5.28
    PHP 5.4.9

    You can install the stack directly from the App Store or alternatively download the installer from the BitNami website.


  • Advertisement
  • Registered Users Posts: 5,999 ✭✭✭Talisman


    Aptana is Eclipse-based and is going to be pretty heavy-weight if you are just getting started in development. Tackling PHP/MySQL and coming to terms with a full IDE might put you off the whole experience. My recommendation would be to start with a simple text editor that has syntax highlighting to aid your progress and once you're over the PHP learning curve then move to an IDE.

    Sublime Text is a very good text editor for working with code, it's also free for as long as you wish to use it without buying a license. Package Control simplifies the process of finding plugins for the editor which come in handy.

    NetBeans IDE is an alternative option to Aptana as it is not Eclipse based and is a simpler environment to learn.


  • Registered Users Posts: 880 ✭✭✭raher1


    My problem Lyes in the fact I can't get my php login to work and add session Id.


  • Registered Users Posts: 5,999 ✭✭✭Talisman


    Can you post your code? Here's some simple code to get the session_id value.

    [PHP]<?php
    session_start();
    $my_session_id = session_id();
    ?>
    <html>
    <head>
    <title>session_id</title>
    </head>
    <body>
    <?php
    print "session_id(): " . $my_session_id;
    ?>
    </body>
    </html>[/PHP]


  • Registered Users Posts: 5,999 ✭✭✭Talisman


    raher1 wrote: »
    My problem Lyes in the fact I can't get my php login to work and add session Id.

    See if you can this to work for you it's a very simple login example using a PDO database connection. The code may not be perfect but I've commented it well enough for you to see how it should be done. :)

    There's a nice NetTuts tutorial explaining why you should use PHP’s PDO for Database Access.

    db.php:
    [PHP]
    <?php

    // Variables for the database connection string
    $config = array(
    'host' => 'localhost',
    'username' => 'user_example',
    'password' => 'pass_example',
    'dbname' => 'db_example'
    );

    $db = new PDO('mysql:host=' . $config . ';dbname=' . $config, $config, $config);
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    [/PHP]

    users.php: A class for our users
    [PHP]<?php
    class Users{

    private $db;

    // The __construct() method is used to make the database connection variable available to the class
    // Functions inside a class cannot use variables that are defined outside of the class unless the variable is global

    public function __construct($database) {
    $this->db = $database;
    }

    public function login($username, $password) {
    // query selects the password and id for the provided username
    // Assumption :: your database table contains the fields: id, username, password
    $query = $this->db->prepare("SELECT password, id FROM users WHERE username = ?");
    $query->bindValue(1, $username);

    try {
    $query->execute();
    $data = $query->fetch();
    $stored_password = $data;
    $id = $data;

    // Hashing the supplied password and comparing it with the stored hashed password.
    // NOTE: sha1() isn't the best option for hashing passwords as it does not produce a very secure hash
    // bcrypt() is a better method but is more involved so sha1() will suffice for here
    if($stored_password === sha1($password)){
    return $id;
    } else {
    return false;
    }

    } catch (PDOException $e) {
    // This should be more graceful but will do for a demo
    die($e->getMessage());
    }
    }
    }[/PHP]

    init.php:
    [PHP]
    <?php
    // starting the users session
    session_start();
    // include our database and users files
    require 'db.php';
    require 'users.php';

    // Instantiate the Users class
    $users = new Users($db);
    // $errors will be used for returning login errors
    $errors = array();
    [/PHP]

    login.php:
    [PHP]
    <?php
    require 'init.php';

    // 'a === b' operator evaluates to true if a and b have the same value and type
    if (empty($_POST) === false) {
    $username = trim($_POST);
    $password = trim($_POST);

    if (empty($username) === true || empty($password) === true) {
    $errors[] = 'Sorry, but you need a username and password.';
    } else if ($users->user_exists($username) === false) {
    $errors[] = 'Sorry the username doesn\'t exists.';
    } else {
    $login = $users->login($username, $password);
    if ($login === false) {
    $errors[] = 'Sorry, that username/password is invalid';
    } else {
    // username/password is correct and the login method of the $users object returns the user's id
    // which is stored in $login.

    // The user's id is now set into the user's session
    $_SESSION = $login;

    // Redirect the user to session.php.
    header('Location: session.php');
    exit();
    }
    }
    }
    ?>
    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Login</title>
    </head>
    <body>
    <h1>Login</h1>
    <div id="container">
    <?php
    if(empty($errors) === false) {
    echo '<p>' . implode('</p><p>', $errors) . '</p>';
    }
    ?>
    <form method="post" action="">
    <h4>Username:</h4>
    <input type="text" name="username" value="<?php if(isset($_POST)) echo htmlentities($_POST); ?>" >
    <h4>Password:</h4>
    <input type="password" name="password">
    <br>
    <input type="submit" name="submit">
    </form>
    </div>
    </body>
    </html>
    [/PHP]

    logout.php: A basic logout script
    [PHP]
    <?php
    session_start();
    session_destroy(); // Destroy the user's session
    header('Location:session.php'); // Redirect user to the session page
    ?>
    [/PHP]

    session.php: This just dump the session variables in the browser
    [PHP]
    <?php
    session_start();
    ?>
    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Session Variables</title>
    </head>
    <body>
    <h1>Session Variables</h1>
    <div id="container">
    <?php
    var_dump($_SESSION);
    ?>
    </div>
    </body>
    </html>
    [/PHP]


  • Registered Users Posts: 880 ✭✭✭raher1


    getting back into now,thank you,keep the code coming.
    Talisman wrote: »
    Can you post your code? Here's some simple code to get the session_id value.

    [PHP]<?php
    session_start();
    $my_session_id = session_id();
    ?>
    <html>
    <head>
    <title>session_id</title>
    </head>
    <body>
    <?php
    print "session_id(): " . $my_session_id;
    ?>
    </body>
    </html>[/PHP]


  • Advertisement
  • Registered Users Posts: 5,999 ✭✭✭Talisman


    raher1 wrote: »
    getting back into now,thank you,keep the code coming.
    Did you try out the code? Did it work? If not did you try to get it working?


  • Moderators, Society & Culture Moderators Posts: 17,642 Mod ✭✭✭✭Graham


    Talisman wrote: »
    There's a nice NetTuts tutorial explaining why you should use PHP’s PDO for Database Access

    Are there any speed advantages/disadvantages to using PDO over mysqli?


  • Registered Users Posts: 5,999 ✭✭✭Talisman


    I remember reading a benchmark article some years ago saying PDO is faster at inserts, MySQLi is faster at selects - the difference in both cases was within 1%. Both use the native MySQL driver so similar performance levels should be expected.

    What initially drew me to PDO was the fact that it supports many more databases than MySQL due to the fact that it's an abstraction layer so it's possible to migrate a project to a different database (e.g. MS SQL, Oracle, PostgreSQL, SQLite, etc.) without too much of a headache. By knowing PDO, the developer is also not tied to MySQL which makes getting work on other projects which don't use that particular database much easier.

    MySQLi is fine for people who will only ever work with MySQL - A few years ago I had a client whose marketing department got a product developed in India. It never occurred to them to consult with the IT department before procuring the system. When delivered the only issue was that it was written in PHP and used MySQL - the client is a complete MS house. I was asked if it was possible to 'fix' the issues as the company who developed the app wasn't interested in porting it to a MS environment. Convincing the IT department to host the application in a standalone virtual server running IIS 7.5 and PHP wasn't too difficult but under no circumstances was MySQL being allowed on the network so the application was abandoned - it was developed using MySQLi instead of PDO and the company were unwilling to bring in a developer to do the conversion.


  • Registered Users Posts: 880 ✭✭✭raher1


    Talisman wrote: »
    Did you try out the code? Did it work? If not did you try to get it working?
    Sorry,it's being crazy for the last week. One question, can I use text wrangler with php and xamp?


  • Registered Users Posts: 5,999 ✭✭✭Talisman


    Yes you can use TextWrangler - it's a text editor and that's all php files are.


  • Registered Users Posts: 2,709 ✭✭✭MyPeopleDrankTheSoup


    Talisman wrote: »
    A few years ago I had a client whose marketing department got a product developed in India. It never occurred to them to consult with the IT department before procuring the system. When delivered the only issue was that it was written in PHP and used MySQL - the client is a complete MS house.

    Idiots. They deserved everything they got. I hope you charged them loads!


  • Registered Users Posts: 880 ✭✭✭raher1


    Would people look at code when I get stuck,I was ill so on,y starting now. I got no help when I tried this before.


  • Registered Users Posts: 6,999 ✭✭✭witnessmenow


    raher1 wrote: »
    Would people look at code when I get stuck,I was ill so on,y starting now. I got no help when I tried this before.

    I know a small bit of PHP (checkargos is mainly written in it, but im self thought). If you post stuff up I'll try to help


  • Registered Users Posts: 5,999 ✭✭✭Talisman


    raher1 wrote: »
    Would people look at code when I get stuck,I was ill so on,y starting now. I got no help when I tried this before.
    Que? To date you haven't posted any code or given any feedback as to whether or not you you tried that which was provided to you.


  • Registered Users Posts: 880 ✭✭✭raher1


    Talisman wrote: »
    Que? To date you haven't posted any code or given any feedback as to whether or not you you tried that which was provided to you.
    your right,i am fooling myself. i did a dslr photo course to get some work and add to my skills levels. i got a bug so now hitting form now.
    http://www.mamp.info/en/index.html
    is this a bit heavy for a mac 10.6 system i am downloading bitnami for sql is that ok.


  • Advertisement
  • Registered Users Posts: 5,999 ✭✭✭Talisman


    MAMP already contains MySQL so there is no need for the additional Bitnami install.

    MAMP = Mac, Apache, MySQL, PHP


  • Registered Users Posts: 880 ✭✭✭raher1


    Talisman wrote: »
    MAMP already contains MySQL so there is no need for the additional Bitnami install.

    MAMP = Mac, Apache, MySQL, PHP

    Ok, that's brillant. Mama will use. Bitnami looks heavy on my system. Thanks tail man


  • Registered Users Posts: 880 ✭✭✭raher1


    Ok, cake php or php? What's the difference? Is it worth doing code acedemy or Lynda .com


  • Registered Users Posts: 26,556 ✭✭✭✭Creamy Goodness


    raher1 wrote: »
    Ok, cake php or php? What's the difference? Is it worth doing code acedemy or Lynda .com
    CakePHP is a php framework, php is just php. cakePHP is essentially still php.

    Cake's lead developer left to start on http://lithify.me/ which is quite good.

    However, I suggest you get to grips with php/programming language basics before you get yourself knee deep in frameworks. Frameworks make things a hell of a lot easier when you know what you're doing but otherwise you're a deer in the headlights, in my opinion of course.


  • Registered Users Posts: 4,898 ✭✭✭paulbok


    For a beginner I found PHP Academy very good.


  • Registered Users Posts: 880 ✭✭✭raher1


    i am used to dreamweaver and notepad but tryiny textwrangler as it is complatable with mac but i cant open my hello world file from my hdoc folder in mamo


  • Registered Users Posts: 880 ✭✭✭raher1


    I am enjoying textwrangler ! Hate messing with dreamweaver setting, not sure can it be rest the folders.


  • Registered Users Posts: 880 ✭✭✭raher1


    Ok. I am back. Just a few problems there. I will be posting soon enough.


  • Moderators, Science, Health & Environment Moderators, Social & Fun Moderators, Society & Culture Moderators Posts: 60,082 Mod ✭✭✭✭Tar.Aldarion


    I recommend Chrome as a tutor.


  • Advertisement
  • Registered Users Posts: 2,021 ✭✭✭ChRoMe


    I recommend Chrome as a tutor.

    :D


Advertisement