cmburbul Posted August 2, 2007 Share Posted August 2, 2007 Hi, I am moving a site (from a server running PHP4 to a server running PHP5) with a simple PHP login system that sets a cookie and sends an email that someone has logged in. It is returning an error and not setting the cookie. Here is the error: PHP Warning: setcookie() expects parameter 3 to be long, string given in /home/taylor/public_html/login/login.php Here is the PHP code (the contents of the login.php page that the form calls): <?php ob_start(); include("config.php"); // connect to the mysql server $link = mysql_connect($server, $db_user, $db_pass) or die ("Could not connect to mysql because ".mysql_error()); // select the database mysql_select_db($database) or die ("Could not select database because ".mysql_error()); $match = "select id from $table where username = '".$_POST['username']."' and password = '".$_POST['password']."';"; $qry = mysql_query($match) or die ("Could not match data because ".mysql_error()); $num_rows = mysql_num_rows($qry); if ($num_rows <= 0) { echo "<html><head><link href=\"../stylelogin.css\" rel=\"stylesheet\" type=\"text/css\"></head><body class=\"login\">Sorry, there is no username $username with the specified password <a href=logorsign.html>Try again</a></body></html>"; exit; } else { setcookie('loggedin', true, false, '/', false, 0); setcookie('mysite_username', '$username', '/', false, 0); mail( "[email protected]", "Member login: $username", "XXXXXX.com member $username has logged in", "From: XXXXXX.com" ); echo "<html><head><link href=\"../stylelogin.css\" rel=\"stylesheet\" type=\"text/css\"></head><body class=\"login\">You are now logged in, $username</body></html>"; } ob_end_flush(); ?> I thought it might be that the form that feeds this was not passing the $username and &password variables so i tried adding the following to the top of the script: $username = $_REQUEST['username']; $password = $_REQUEST['password']; This had no effect. I am stumped. Any help/advice/direction is most appreciated. Thanks! Chris Link to comment https://forums.phpfreaks.com/topic/63095-cookie-error-moving-form-php4-to-php5/ Share on other sites More sharing options...
premiso Posted August 2, 2007 Share Posted August 2, 2007 setcookie('loggedin', true, false, '/', false, 0); setcookie('mysite_username', '$username', false, '/', false, 0); You were missing a "false" in the second set cookie. I believe that is the issue. Link to comment https://forums.phpfreaks.com/topic/63095-cookie-error-moving-form-php4-to-php5/#findComment-314274 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.