Note that there are some explanatory texts on larger screens.

plurals
  1. POCookies are Not Being Set Properly in PHP Script
    text
    copied!<p>Im very new in php and try to use cookie but it is not woking in my site, can anyone guide me please , what is going wrong in my code:</p> <pre><code>&lt;?php session_start(); ?&gt; &lt;script&gt; function Redirect(url) { location.href = url; } &lt;/script&gt; &lt;?php define('_VALID_ACCESS', true); include_once "includes/connect.php"; include_once "includes/login.php"; if(empty($_POST['loginname']) || empty($_POST['password'])) { $msg = "User or password is empty"; } else { if(login($_POST['loginname'], $_POST['password']) == true) { $usern = $_POST['loginname']; session_register('loginname'); $loginname = $usern; sleep(1); if(activestatus($_POST['loginname'], $_POST['password']) == true) { $usern = $_POST['loginname']; session_register('loginname'); $loginname = $usern; sleep(1); $hour = time() + 3600; setcookie("ID_my_site", $_POST['loginname'], $hour); setcookie("Key_my_site", $_POST['password'], $hour); $test = $_COOKIE["ID_my_site"]; $msg = "&lt;script&gt; Redirect ('home.html?testname=".$test."')&lt;/script&gt;"; //header("Location: home.html"); } else { $msg = "&lt;script&gt; Redirect ('valid.php?testname=".$usern."')&lt;/script&gt;"; } } else { $msg = "&lt;font color=red&gt;User or Password is wrong&lt;/font&gt;"; } } echo '&lt;div id="divTarget"&gt;' . $msg . '&lt;/div&gt;'; ?&gt; &lt;link rel="stylesheet" href="css/blueprint/screen.css" type="text/css" media="screen, projection"&gt; &lt;link rel="stylesheet" href="css/blueprint/print.css" type="text/css" media="print"&gt; &lt;link rel="stylesheet" href="css/blueprint/ie.css" type="text/css" media="screen, projection"&gt; &lt;body&gt; &lt;div class="container" id="login_container"&gt; &lt;form id="login" action="action.php" method="post" name="loginform" &gt; &lt;fieldset id="login_screen" style="width:350px"&gt; &lt;label id="login_label" for="login"&gt;User Login &lt;/label&gt; &lt;br&gt;&lt;br&gt; &lt;label for="login"&gt;Email Address&lt;/label&gt; &lt;input type="text" name="loginname" id="loginname" value="email@coolmates.com"&gt; &lt;p id="space"&gt;&lt;label for="password"&gt;Password&lt;/label&gt; &lt;input type="password" id="password" name="password" value="********" &gt;&lt;/p&gt; &lt;input type="checkbox"&gt;Keep me signed in until i signout &lt;p id="test"&gt;&lt;input type="submit" value="Submit"&gt;&lt;/p&gt; &lt;a href="forgetpassword.html"&gt;Forgot your password&lt;/a&gt;&amp;nbsp;&amp;nbsp;|&lt;span id="free"&gt;Not a member?&lt;/span&gt;&lt;a href="regForm.html"&gt;Sign up&lt;/a&gt;&lt;blink&gt;&lt;span id="free"&gt;Free&lt;/span&gt;&lt;/blink&gt; &lt;/p&gt; &lt;/fieldset&gt; &lt;/form&gt; &lt;/div&gt; &lt;/body&gt; </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