开发者

How to change image based on who logged in

I need help on how to make image change after a user logged in. 'coz i'm creating a online radio station and i want my listeners to see who's DJ is currently on-air based on that image. that image is stored in a php page(djonair.php), the image inside that page(djonair.php) will change after the user logged in. then that page is called in the main page(index.html) using iframe. I'm using iframe to call that page because my main page is a HTML page(index.html).

here's my login.php code:

    <?
    session_start();
    if(session_is_registered(myusername)){
    header("location:djmain.php");
    }
    ?>

    <font face="calibri" color="white" size="6">: DJ Log In :</font><br>
    <table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
    <tr>
    <form name="form1" method="post" action="checklogin.php">
    <td>
    <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#005180">
    <tr>
    <td colspan="3"><strong>Member Login </strong></td>
    </tr>
    <tr>
    <td width="78">Username</td>
    <td width="6">:</td>
    <td width="294"><input name="myusername" type="text" id="myusername"></td>
    </tr>
    <tr>
    <td>Password</td>
    <td>:</td>
    <td><input name="mypassword" type="password" id="mypassword"></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><input type="submit" name="Submit" value="Login"></td>
    </tr>
    </table>
    </td>
    </form>
    </tr>
    </table>

here's the code for my checklogin.php:

    <?php
    $host="sqlhostname"; // Host name
    $username="sqlusername"; // Mysql username
    $password="sqkpassword"; // Mysql password
    $db_name="dbname"; // Database name
    $tbl_name="tablename"; // Table name

    // Connect to server and select databse.
    mysql_connect("$host", "$username", "$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");

    // username and password sent from form
    $myusername=$_POST['myusername'];
    $mypassword=$_POST['mypassword'];

    // To protect MySQL injection
    $myusername = stripslashes($myusername);
    $mypassword = stripslashes($mypassword);
    $myusername = mysql_real_escape_string($myusername);
    $mypassword = mysql_real_escape_string($mypassword);

    $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
    $result=mysql_query($sql);

    // Mysql_num_row is counting table row
    $count=mysql_num_rows($result);
    // If result matched $myusername and $mypassword, table row must be 1 row

    if($count==1){
    // Register $myusername, $mypassword and redirect to file "login_success.php"
    session_register("myusername");
    session_register("mypassword");
    header("location:djmain.php");
    }
    else {
    echo "Wrong Username or Password";
    echo '<br&开发者_C百科gt;Go back to <a href="login.php">log-in</a> page.';
    }
    ?>


change some record in database where you store djs with image url and then select it everytime user access page so he/she can she who's in air. For example

$q = "UPDATE statistics SET on_Air_image_url = '".mysql_real_Escape_string($_SESSION['djname']).".png'";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜