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 there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Script to display SU Card balance

  • 18-07-2012 2:26pm
    #1
    Closed Accounts Posts: 3,689 ✭✭✭


    I know there's a good few IT heads here that might find this handy.

    Thanks to a bit of procrastination I put together a PHP script to easily pull up the balance of free teas and coffees from your SU Card on the mobile.

    su_app.jpg

    I could link to the script that accepts login details through the URL but couldn't really prove I'm not storing passwords, so here it is instead! :p

    Instructions
    1. Copy PHP code from below and paste into new php file on your own hosting. You'll need cURL enabled hosting.
    2. Enter your login details at the top of the file and save.
    3. Create a cookie.txt file in the same folder and make it writeable (CHMOD 777).
    4. Bookmark the page URL on your mobile - done!

    I added a NFC tag to my SU Card so it'll load the webpage directly when swiped. :cool: :cool:

    Excuse the messy HTML, feel free to tidy. Cash balance and points appear to be broken on the SU site at the moment, easy update to include them when they're back.

    [PHP]<?php

    //Replace with your student ID and password
    $id = '12345678';
    $password = 'yourpassword';

    login('http://www.su.nuigalway.ie/users/login','data[UserSecurityKey][student_username]=' . $id . '&data%5BUserSecurityKey%5D%5Bstudent_password%5D=' . $password . '');

    $raw_data = grab_page("http://www.su.nuigalway.ie/loyalty/account/");
    $raw_data = str_replace(";", "", $raw_data);
    $snippet = get_string_between($raw_data, '<tr>
    <td>&euro</td>', '</tr>');
    $teas = get_string_between($snippet, '<td>', '</td>');
    $dinners = get_string_between($snippet, '</td>
    <td>','</td>');

    echo '<html>
    <head>
    <meta name="viewport" content="width=device-width" />
    </head>
    <body>
    <center>
    <img src="http://omg.wthax.org/sulogo.jpg"&gt;
    <br>
    <table>
    <tr><td><strong style="font-size: 700%;">' . (int)$teas . '</style> </td><td> <img src="http://omg.wthax.org/coffee.png"></td><tr&gt;
    <tr><td><strong style="font-size: 700%;">' .(int)$dinners . '</strong></td><td> <img src="http://omg.wthax.org/food.png"></td></tr&gt;
    </table>
    <br>
    <h3>' . 10*($teas-((int)$teas)) . '/10 next free drink.
    <br>' . 10*($dinners-((int)$dinners)) .'/10 next free dinner.
    </h3>
    </center>
    </body>
    </html>';

    function get_string_between($string, $start, $end){
    $string = " ".$string;
    $ini = strpos($string,$start);
    if ($ini == 0) return "";
    $ini += strlen($start);
    $len = strpos($string,$end,$ini) - $ini;
    return substr($string,$ini,$len);
    }

    //Upload a blank cookie.txt to the same directory as this file with a CHMOD/Permission to 777
    function login($url,$data){
    $fp = fopen("cookie.txt", "w");
    fclose($fp);
    $login = curl_init();
    curl_setopt($login, CURLOPT_COOKIEJAR, "cookie.txt");
    curl_setopt($login, CURLOPT_COOKIEFILE, "cookie.txt");
    curl_setopt($login, CURLOPT_TIMEOUT, 40000);
    curl_setopt($login, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($login, CURLOPT_URL, $url);
    curl_setopt($login, CURLOPT_USERAGENT, $_SERVER);
    curl_setopt($login, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($login, CURLOPT_POST, TRUE);
    curl_setopt($login, CURLOPT_POSTFIELDS, $data);
    ob_start();
    return curl_exec ($login);
    ob_end_clean();
    curl_close ($login);
    unset($login);
    }

    function grab_page($site){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER);
    curl_setopt($ch, CURLOPT_TIMEOUT, 40);
    curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
    curl_setopt($ch, CURLOPT_URL, $site);
    ob_start();
    return curl_exec ($ch);
    ob_end_clean();
    curl_close ($ch);
    }

    ?>[/PHP]


Comments

  • Registered Users, Registered Users 2 Posts: 9,034 ✭✭✭Ficheall


    Almost completely useless, yet I find myself impressed nonetheless...


  • Closed Accounts Posts: 11,924 ✭✭✭✭RolandIRL


    And if only I had a mobile with internet...ta all the same :)

    Though when did the points/cash balance go down? I've got a good few saved up and hate to lose their priceless value!


  • Closed Accounts Posts: 3,689 ✭✭✭joeKel73


    I'm sure it's still on your account, just not showing up on the SU site at the moment.


Advertisement