Friday 22 April 2011

building zpanel module session and links

Advance module making part 1 session and links

In this section we will be look at 3 main things. These sections are where people go wrong when first learning to wirte a module.
  1. sessions
  2. any kind of link


    So first of all we will be folowing on from the hello world module. You can download the file from that tuterial here . read the read me file to install the files.
    so no we are going to look into sessions. now you should all ready know php therefore know what a session is right?
    so when the user logs in a session is set with the username of the person who is login. the session name is $_SESSION['zUsername']
    Guess what now we are going it edit the index.php file. what we are going to do is make a page that says welcome {username here}
    so copy and past this into index.php. I exsplain what each line does below in the code
    <?php
    //
    /*
    shows: welcome {username}
    we do not need to set session_start(); as it is all ready set for us
    /*
    $welcome = 'Welcome '; // the start of the welcome message
    $username = $_SESSION['zUsername']; // holds the users username
    $message = $welcome . $username; // combind the two above together
    echo $message; // display the message
    ?>


     now load the module in zpanel controll panel and you could see welcome with your username after that.
    Session

    ok so now we need to know how to handle links. This is quite annoying at the start as links are not local to the file. what i mean is the index file is included into the main zpanel file.
    so for example i want to add a picture into the index.php page we just edited.
    First add a file called images in the hello folder and add this image





    and copy and past the code below into the index.php file
    <?php
    /*
    shows: welcome {username}
    we do not need to set session_start(); as it is all ready set for us
    and shows a picture below bare in mind the link
    */
    $welcome = 'Welcome '; // the start of the welcome message
    $username = $_SESSION['zUsername']; // holds the users username
    $message = $welcome . $username; // combind the two above together
    $picture_link = 'modules/account/hello/images/HelloWorld.jpg';// link to picture !important!
    $picture = '<img src="' . $picture_link . '" alt="picture">';
    echo $message; // display the message
    echo '<br/>';
    echo $picture;
    ?>



    now if you load th module you will see a picture under the welcome message
    as you can see the picture link varable that holds the link to the picture is modules/account/hello/images/HelloWorld.jpg
    now the reson why it is like that is because this file is being included into the main zpanel index file and that is located at c:\zpanel\panel\index.php
    so what to remember
    all links must be made as if they were made of the main zpanel file located at the panels root
    Genral links 

    now here is how you would include a php file into your module index file
    ok so now i want to keep all the above but at the bottom of my module i want to add my details. well lets think we already assined that infomation into the modinfo.zp.php
    copy and past the code below:
    <?php
    /*
    *shows: welcome {username}
    *we do not need to set session_start(); as it is all ready set for us
    *shows a picture below bare in mind the link
    *message of developer below
    */
    include ('modules/account/hello/modinfo.zp.php'); // look at the link it is the same as before!
    $welcome = 'Welcome '; // the start of the welcome message
    $username = $_SESSION['zUsername']; // holds the users username
    $message = $welcome . $username; // combind the two above together
    $picture_link = 'modules/account/hello/images/HelloWorld.jpg';// link to picture !important!
    $picture = '<img src="' . $picture_link . '" alt="picture">';
    echo $message; // display the message
    echo '<br/>';
    echo $picture;
    echo '<br/><br/><br/><br/><br/>';
    echo $thismod["title"] . 'was made by <a href="' . $thismod["developersite"] . '">' . $thismod["developer"] . '</a>'; // get the values we set before
    ?>




    No comments:

    Post a Comment

    i do all this for free so PLEASE NOT SPAM thanks