Jump to content


Mr-Chidi

Member Since 20 May 2008
Offline Last Active Feb 27 2015 08:58 AM

Posts I've Made

In Topic: Add Admin Access to All Accounts

27 February 2015 - 02:30 AM

It can be done. The site will be role based. Admin from his dashboard can control everything. You need to create a proper database table structure for doing this.


how can it b done with my login code? that's d issue

In Topic: Add Admin Access to All Accounts

26 February 2015 - 10:25 PM

While I don't fully understand what your code is doing, I do not see anything regarding your initial question. In what way are you currently controlling who accesses what with this code?

 

The code is my login page. currently only the user is able to login from there, but was wondering if i could modify it so that an admin can login into any of the account with a master password


In Topic: login into two different areas on one login form

21 February 2015 - 02:43 PM

 


This is because this else is in the wrong place.

else{    echo '<div class="signals"><p class="bg-warning text-center warning"><button type="button" class="close" aria-label="Close"><span aria-hidden="true">×</span></button>INVALID USERNAME OR PASSWORD again</div></p>';}
You have have after the if/elseif strcmp statements. It should be after the  if (password_verify($password, $hash))  block.
if(isset($_POST['login'])){    $username = stripslashes($_POST['username']);    $password = stripslashes($_POST['password']);    $stmt = $pdo->prepare("SELECT password FROM table WHERE username=:username");    $stmt->bindValue(':username', $username, PDO::PARAM_STR);    $stmt->execute();    if($stmt->rowCount()<1)    {        echo '<div class="signals"><p class="bg-warning text-center warning"><button type="button" class="close" aria-label="Close"><span aria-hidden="true">×</span></button>INVALID USERNAME OR PASSWORD</div></p>';    }    else    {        $password = $_POST['password'];        list($hash) = $stmt->fetch(PDO::FETCH_NUM);        if (password_verify($password, $hash))        {            $_SESSION['username'] = $username;            $status1 = "COMPLETED";            $status2 = "UNCOMPLETED";            $stmt = $pdo->query("SELECT status FROM table WHERE username ='$_SESSION[username]'");            $check = $stmt->fetch(PDO::FETCH_ASSOC);            $status = $check['status'];            if(strcmp($status, $status1) == 0)            {                header("location: completed/index.php");                exit();            }            elseif(strcmp($status, $status2) == 0)            {                header("location: uncompleted/index.php");                    exit();            }          }        else        {             echo '<div class="signals"><p class="bg-warning text-center warning"><button type="button" class="close" aria-label="Close"><span aria-hidden="true">×</span></button>INVALID USERNAME OR PASSWORD again</div></p>';        }     }}
 

Thanks

In Topic: notification badge in php

03 February 2015 - 04:22 AM

Finally this is what worked for me. I've tested it several times and it worked. mac_gyver was right but in my own case only the admin visits the site and not multiple users.

 

Had to device my own means. Thanks mac_gyver and cronix for the inspiration!!!

 
    $stmt = $pdo->query("SELECT * FROM $tbl_name");
    $stmt->execute();
    $num_rows = $stmt->rowCount();
    print "<p>$num_rows Record(s) Found.</p>";
 
echo "<table width='100%' border='1' bordercolor='#0cc' cellspacing='0' cellpadding='2'>";
echo "<tr>
    <th bgcolor='#444444' align='center'><font color='#fff'>Surname</font></th>
    <th bgcolor='#444444' align='center'><font color='#fff'>Firstname</font></th>
    <th bgcolor='#444444' align='center'><font color='#fff'>Email / Username</th>
    <th bgcolor='#444444' align='center'><font color='#fff'>Phone</th>
    <th bgcolor='#444444' align='center'><font color='#fff'>Date Registered</th>
    <th bgcolor='#444444' align='center'><font color='#fff'>Status</th>
    <th bgcolor='#444444' align='center'><font color='#fff'>Create Account</th>
    <th bgcolor='#444444' align='center'><font color='#fff'>Delete Account</th>
    </tr>";
// keeps getting the next row until there are no more to get
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {

    $clas = $row['entry'];
    if($clas == 'NEW'){
        $style = " style='font-weight:bold'";
    }else{
    $style = " style='font-weight:normal'";    
    }
  
    // Print out the contents of each row into a table
    echo "<tr{$style}><td>";
    echo ucfirst($row['surname']);
    echo "</td><td>";
    echo ucfirst($row['firstname']);
    echo "</td><td>";
    echo $row['email'];
    echo "</td><td>";
    echo $row['phone'];
    echo "</td><td>";
    echo $row['today'];
    echo "</td><td>";
    echo $row['status'];
    echo "</td><td>";
    echo "<a href='create-account.php?id={$row['id']}'>Create Account</a>";
    echo "</td><td>";
    echo "<a href='account-delete.php?id={$row['email']}'>Delete Account</a>";
    echo "</td></tr>";
}
echo "</table>";

In Topic: notification badge in php

02 February 2015 - 10:42 AM

by storing the 'NEW' value in with the data, you will have two problems -

 

1) this can only be used by one visitor to your site. when the 'NEW' values are cleared, due to that one visitor viewing the entries, no other visitor will ever see any bold entries. you must store the value that tells your code what has been viewed or not, separately for each visitor.

 

2) by not using the id of the highest row at the time you displayed the data, you can have a race condition where new entries can be  inserted at the same time you are getting and display the data, that won't be displayed on that visit to your page, and that your display logic will clear the 'NEW' value for. they will be displayed the next time you visit the page without being in bold, but they are new rows that where not displayed the last time you visited the page.

 

edit: also, your 'css' isn't css. you are using in-line styling and typing it for each element you are styling. to use css, you define styling rules, that you then apply to elements on your page using a selector, typically a class selector, so that multiple same elements can be styled without repeating the actual styling every place it is used. this allows you to make a change in one place, rather than to go through all your code and change every instance of the in-line styling. it also reduces the amount of markup and clutter you have in the code on your page.

On the css rule, i just used that as an example but on the actually page i used a i did not use an in-line styling.

I do not know how else to get it done, but this seem to work for me. Since i do not have an alternative, guess i'll stick with what i have and what i did was once the link is clicked, it updates the 'NEW' to 'OLD' thereby allowing only the clicked link to appear as normal text and not-clicked link always appear bold regardless of the number of views. Once it's not clicked it stays bold forever.

I've tested it so many times and it didnt work-short of what i wanted. What's left is the notification stuff.,

 

 

Thanks


Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com