0

We are migrating a php application from 5.4 to 7.2 and we have a warning we'd like to get rid of:

Warning: Illegal string offset 'save_username'

I already tried removing the quotes, adding double quote, setting the variable as string (instead of 1 just "1") with no luck.

Here's the code we're using, the warning is in this line in the code below: if ($vars['save_username'] == 1)

function login_form($vars = "") {
    if ($vars == "") {
        // check if the username is saved via cookie
        if ($_COOKIE["username"] != "") {
            $username = $_COOKIE["username"];
            $save_username = true;
        }
    } else {
       $username = $vars['username'];
    }
    
    if ($vars['save_username'] == 1) {
        $save_username = true;
    }
    ?>

<br><br>
    <form action="login.php?op=login" method="post">
    <table cellspacing="3" cellpadding="3" border="0" align=center>
    <tr>
        <td colspan=2 align=center><font class=title><b>Login</b></font>
        <br><br><br>
        </td>
    </tr>
    <tr>
        <td width=80 nowrap valign=baseline>Email:</td>
        <td width=240><input type="text" name="username" size=30 value="<?php  echo stripslashes($username) ?>" /><br>
            <font class=smallest_font>ie. user@user.com</font>
        </td>
    </tr>
    <tr>
        <td>Password:</td>
        <td><input type="password" name="password" size=30/></td>
    </tr>
    <tr>
        <td></td>
        <td><input type="checkbox" name="save_username" value=1 <?php  if ($save_username) echo "checked" ?>> Remember my login</td>
    </tr>
    <tr>
        <td colspan=2 align=center><br><input type="submit" name="login" value="Login" class="button"/>
           &nbsp;&nbsp;&nbsp;<input type="reset" value="Reset" class="button" /></td>
    </tr>
    <tr>
        <td colspan=2 align=center><br>
        <?php  if(isset($err)) {
            echo "<br />\n<span class=\"dark_red\">$err</span><br />";
        } ?>
        </td>
    </tr>
    </table>
    </form>
    <br />
Matias
  • 539
  • 5
  • 28
  • looks like `$vars` is not an array. You dont show where you actually call this function – RiggsFolly Aug 31 '21 at 10:22
  • Hi, thanks for your answer, I already solved this by looking into the resolution. I changed this: function login_form($vars = array()) – Matias Aug 31 '21 at 10:35

0 Answers0