Note that there are some explanatory texts on larger screens.

plurals
  1. POpreg_replace for username and e-mail as one field
    text
    copied!<p>I'd like to use a preg_replace for my username/e-mail login.<br/> I store it in a SESSION and want to check if that data is inside <br/> the database. Since I'd like to give the user the opportunity to log <br/> in with username OR e-mail this expression gets a little freaky and <br/> I have no clue how to manage it. Can anyone help?</p> <p>So the "$loginusername" is username (A-Za-z0-9) and ALSO e-mail! So it should <br/> not replace that special characters...I have found this as the expression of <br/> the e-mail:<br/><br/></p> <pre><code>([A-Za-z0-9._-]+)@([A-Za-z0-9-]+)([A-Za-z0-9.-]*[A-Za-z0-9-]+)*\.([A-Za-z){1,4} </code></pre> <p>and want to add this as preg_replace to the already existing: <br/></p> <pre><code>preg_replace('#[^A-Za-z0-9]#i','', $_SESSION["username"]); </code></pre> <p>I can't get this to work, always getting syntax error.<br/></p> <p>My code right now is: <br/><br/></p> <pre><code>if ( !isset ($_SESSION['X5636gYGWEHidwWLOGIN'] ) ) { header("Location: login.php"); exit(); } include("includes/connectdatabase.php"); $loginusername = preg_replace('#[^A-Za-z0-9]#i','', $_SESSION["username"]); $loginpassword = sha1(preg_replace('#[^A-Za-z0-9]#i', '', $_SESSION["password"])); $sessionvalidation= mysql_query(" SELECT * FROM gebruikers WHERE username = '$loginusername' AND password = '$loginpassword' OR email = '$loginusername' AND password = '$loginpassword' "); $existCount = mysql_num_rows($sessionvalidation); if ($existCount == 0) { header("Location: login.php"); exit(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload