如何根据登录者更改图像

时间:2011-09-03 15:00:23

标签: php image login

我需要有关如何在用户登录后进行图像更改的帮助。'因为我正在创建一个在线广播电台,我希望我的听众能够根据该图像查看当前播出的DJ是谁。该图像存储在php页面(djonair.php)中,该页面内的图像(djonair.php)将在用户登录后更改。然后使用iframe在主页面(index.html)中调用该页面。我正在使用iframe来调用该页面,因为我的主页面是一个HTML页面(index.html)。

这是我的login.php代码:

    <?
    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>

这是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>Go back to <a href="login.php">log-in</a> page.';
    }
    ?>

1 个答案:

答案 0 :(得分:0)

更改数据库中的某些记录,其中存储带有图像URL的djs,然后在每次用户访问页面时选择它,这样他/她就可以在空中。例如

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