PDA

View Full Version : I cant get cookies to work for some reason. Please helP!


l3vi
05-27-2003, 01:46 AM
I know that I have cookies turned on in my browser... at least I think I do:rolleyes:. But, here is my code for my login script(right now its not really a login script:o, but just something where u enter in a username and it will "Log" you in with that username and password):

LOGIN.php
<?php
if (isset($_POST['logincheck'])){
?>
<center>
Username: <?=$_POST['uname']?><br>
Password: <?=$_POST['pword']?><br>
<input type="submit" value="Login" name="login" class="searchl" style="background-image:url('/Main/LIL/no.jpg');" onClick="this.style.background='url(Main/LIL/in.php)';"><br>
</center>
<?
} else {
?>
<center>
<form method=POST action="index.php?type=login">
Login Name: <input type="text" name="uname"><br>
Password: <input type="password" name="pword"><br>
<input type="submit" value="Check" name="logincheck" class="search" style="filter:chroma(color:white);">
</center>
</form>
<?
}
?>


Another page where all the styles are, that login.php is included in
<style type="text/css">
.search{
background-image:url('Main/LIL/smt.jpg');
background-repeat:no-repeat;
width:75;
height:26;
border:medium none;
text-transform:uppercase;
font-size:8px;
font-family:Small Fonts;
text-indent:0px;
}
.searchl{
background-repeat:no-repeat;
width:75;
height:26;
border:medium none;
text-transform:uppercase;
font-size:8px;
font-family:Small Fonts;
text-indent:0px;
}
</style>


in.php
<?php
SetCookie ("Username", $_REQUEST['uname']);
SetCookie ("Password", $_REQUEST['pword']);
SetCookie ("in", "yes");
Header("Location: in_img.php") ;
?>


in_img.php
<?php
Header("Content-type: image/jpeg");
$im = imagecreatefromjpeg("yes.jpg");
Imagejpeg($im,'',200);
ImageDestroy($im);
?>

Any help?:confused:? :confused: ?:confused: ?:confused: ?

cpradio
05-27-2003, 04:33 AM
oh my what are you doing?!?!

You need to re-read how to set a cookie.
http://php.net/manual/en/function.setcookie.php

l3vi
05-27-2003, 05:53 PM
I still dont understand what im doing wrong...

cpradio
05-27-2003, 05:59 PM
okay, its quite simple.

To set a cookie you use the following syntax before any output is started.

setcookie("cookie name","cookie value",expiration time,"cookie path","domain",secure);

Examples of those values would be:
"cookie name" = "username"
"cookie value" = "cpradio"
expiration time = time() + (24*7*60*60)
"cookie path" = "/"
"domain" = "{$_SERVER['HTTP_HOST']}"
secure = 0

-Matt

l3vi
05-27-2003, 06:15 PM
Okay, Ill try that right now!:)

l3vi
05-27-2003, 06:18 PM
YAY!!!!!!!!!!!! IT WORKS! THANKYOU SOOO MUCH!!!:D