home
Guest Signup/Login to unlock all features

Menu

Views: 1876

Replies: 3

Share this post
facebook twitter wa-ico

avatar

ADMIN

eaweb

how to design/run php websites on Android

Mar 08 2017 at 06:33pm

I will be showing you a fun app that let's you run php on Android just like wamp on pc.

First download the app (Bit Web server) from http://www35.zippyshare.com/v/88741667/file.html

Additional apps that can make experience for fun and smooth include:

  • DroidEdit

  • Es Explorer


  • You can download them for free from Playstore

    If you have everything then let's get started with writing our first PHP app.

    Steps
    1. Launch Bit Web server, a few seconds after that you should be greated with this screen:
    Image

    2. Next tap on goto app and if everything is fine you should get the following screen:
    Image
    Got that? Then you are ready to roll.

    3. Next tap on localhost, if you don't have a default browser set, your device will ask you to select a browser. I recommend you use Chrome as your browser. After selecting a browser app you should have something like this:
    Image
    If you got that, then you are ready for step 4.

    4. Before we continue I will like you to know that "Bit Web server" created a "www" folder on the root of your sdcard. This folder is very important and we will be saving our php file(s) to this folder or to sub folders in "www". You can use es Explorer or your favourite file manager locate "www".

    5. Open DroidEdit and type the following code:
    Example 1

    <?php
    echo "hello world projectnaija.com is awesome";
    ?>

    Now follow the image below:
    Image
    Tap on the icon in the red rectangle at the bottom, then tap on save as. On the save as screen name your file hello.php then save it.
    Note!Make sure you are saving your file to the "www" folder I made reference to earlier.

    6. Now we are ready to run our first php program. Simply type http://localhost:8080/hello.php into the address bar of your browser (Chrome preferred). If Bit Web server is running and you followed the instructions you should see I white page with the message "hello world projectnaija.com is awesome". If you got that then you are awesome and you might just be the next big thingSC

    Last edited 09 Mar 2017

    avatar

    ADMIN

    eaweb

    Re: how to design/run php websites on Android

    Mar 09 2017 at 09:31am

    From here on I will be posting code examples. Let's look at our second code example.

    Example 2
    We will be doing a static vs dynamic web page app. Our app will be displaying today's date on the screen when we run it. Now let's look at the code:

    code updated on 22-03-17 (reason: syntax error)


    <p>Today's date is: Thur, 09-March-2017</p>
    <?php
    echo "<p>Today's date is: {date(\"D, d-M-Y\")}</p>";
    ?>

    Type the above code and save the same way you did earlier. You can choose any filename you like or just name it today.php then goto your browser and enter http://localhost:8080/today.php (replace today.php with whatever name you saved your file with).

    So the about program should output

    Today's date is: Thur, 09-March-2017
    Today's date is: Thur, 09-March-2017

    The first line on the output uses static design while the second line uses dynamic design. The major difference between these outputs is that after 24hrs if you run today.php again the second line output will change from Thursday 09-march... To the current date of running.

    The beauty of dynamic design is that values can change on your image without you updating your code manually.


    quote ()
    avatar

    ADMIN

    eaweb

    Re: how to design/run php websites on Android

    Mar 16 2017 at 11:33am

    Hello, and happy ThursdaySC
    Time for example 3.

    Example 3
    We will be working with forms today. This isn't a html tutorial so I will be doing only a surface explanation about forms.

    Forms allow users of our Web app to make input while using our app. Inputs include, typing text, select options, check items, upload files etc.

    So your sample code will ask a user to enter his/her name and year of birth and on click of the submit button the app will display the current age of the users. Type the following code:


    <form action="brain.php" method="post">
    <label>Please Enter your name</label>
    <input type="text" name="user">

    <label>Please enter your year of birth</label>
    <input type="text" name="year">

    <input type="submit" value="Submit">
    </form>


    Next create another file (brain.php) in the same folder as the last file. Type in the following codes into it:

    <?php
    if(isset($_POST['submit'])) {
    $name = $_POST['user'];
    $year = $_POST['year'];

    $age = date("Y") - $year;
    echo "{$name} is {$age} year(s) old";
    }


    If you got everything right your output should be what ever name you entered and the corresponding age for the date of birth. EG, Mike is 27 year(s) old. Will be the output if I entered Mike and 1990 for name and year of birth respectively.


    quote ()
    avatar

    ADMIN

    eaweb

    Re: how to design/run php websites on Android

    Mar 27 2017 at 04:57pm

    Example 4

    We will be working with session functionality of php in this example.

    Sessions are used for storing data in php. The beauty of sessions include the ability to access saved data on multiple files/pages. For example in example 3 we had a form that collects our name and year of birth (data), we can use session to save these data and have an even cooler app. Get set, let's go.

    Create a file (call it write.php) and type in the following:

    <?php
    session_start();
    $_SESSION['country'] = "Nigeria";
    $_SESSION['state'] = "Benue";

    echo "session activated! <a href='read.php'>View data</a>";
    ?>


    Save and then create another file (call it read.php)

    Type in the following:
    <?php
    session_start();
    $country = $_SESSION['country'];
    $state = $_SESSION['state'];

    echo "<p>country: {$country}</p>";
    echo "<p>state: {$state}</p>";

    ?>

    Save and run write.php then read.php on your browser.


    quote ()

    Quick reply


    + files BBCode

    Sponsored