blufish Posted May 31, 2008 Share Posted May 31, 2008 I am making a login for my website. When someone is able to login I make a cookie that says who is logged in. The file that reads the cookie is in a different folder than the file that makes the cookie. Is this a problem? it's not working, the file won't acknowledge the cookie. Quote Link to comment https://forums.phpfreaks.com/topic/108078-solved-cookie-problem/ Share on other sites More sharing options...
BillyBoB Posted May 31, 2008 Share Posted May 31, 2008 No this shouldn't be a problem. You should use sessions anyway they are more secure. Quote Link to comment https://forums.phpfreaks.com/topic/108078-solved-cookie-problem/#findComment-553956 Share on other sites More sharing options...
blufish Posted May 31, 2008 Author Share Posted May 31, 2008 how do you use a session? Quote Link to comment https://forums.phpfreaks.com/topic/108078-solved-cookie-problem/#findComment-553957 Share on other sites More sharing options...
eaglelegend Posted May 31, 2008 Share Posted May 31, 2008 Simply change _COOKIES (all of them) to _SESSION and put session_start() at the top , just under <php on EVERY php file, trust me, I was where you a few mon ths ago! Quote Link to comment https://forums.phpfreaks.com/topic/108078-solved-cookie-problem/#findComment-553960 Share on other sites More sharing options...
eaglelegend Posted May 31, 2008 Share Posted May 31, 2008 "session_start();" sorry! an example $_COOKIE['ses-name']=="" to $_SESSION['ses-name']=="" and at the top of the page if there isnt <?php already, add <?php session_start(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/108078-solved-cookie-problem/#findComment-553962 Share on other sites More sharing options...
blufish Posted May 31, 2008 Author Share Posted May 31, 2008 what about? setcookie("user", $name, $time); Quote Link to comment https://forums.phpfreaks.com/topic/108078-solved-cookie-problem/#findComment-553963 Share on other sites More sharing options...
blufish Posted May 31, 2008 Author Share Posted May 31, 2008 It's still not working... Heres some code, This is the create account php file (accounts/make.php) <?php session_start(); ?> <?php $name = strip_tags($_POST[name]); if (file_exists($name)) { echo "<h1 align=center>Account name already in use!</h1>"; } if (!file_exists($name)) { $layout = $_POST['layout'].".css"; $time = time()+3600*24*365; $_SESSION['user'] = $_POST['name']; $nc = strtolower($name); $pass = strtolower($_POST['pass']); $pass = str_replace("a","[1]",$pass); $pass = str_replace("b","[2]",$pass); $pass = str_replace("c","[3]",$pass); $pass = str_replace("d","[4]",$pass); $pass = str_replace("e","[5]",$pass); $pass = str_replace("f","[6]",$pass); $pass = str_replace("g","[7]",$pass); $pass = str_replace("h","[8]",$pass); $pass = str_replace("i","[9]",$pass); $pass = str_replace("j","[10]",$pass); $pass = str_replace("k","[11]",$pass); $pass = str_replace("l","[12]",$pass); $pass = str_replace("m","[13]",$pass); $pass = str_replace("n","[14]",$pass); $pass = str_replace("o","[15]",$pass); $pass = str_replace("p","[16]",$pass); $pass = str_replace("q","[17]",$pass); $pass = str_replace("r","[18]",$pass); $pass = str_replace("s","[19]",$pass); $pass = str_replace("t","[20]",$pass); $pass = str_replace("u","[21]",$pass); $pass = str_replace("v","[22]",$pass); $pass = str_replace("w","[23]",$pass); $pass = str_replace("x","[24]",$pass); $pass = str_replace("y","[25]",$pass); $pass = str_replace("z","[26]",$pass); fopen($pass."+%+".$nc,"x"); fopen("check".$nc,"x"); file_put_contents("check".$nc,$name); } ?> This is the file that reads it (index.php): <?php session_start(); ?> <html> <head> <?php if ($_GET['where']=='jokes/blond') { echo "<TITLE>Frozenoven :: Jokes :: Dumb Blonde Jokes</TITLE>"; } if ($_GET['where']=='home') { echo "<TITLE>Frozenoven :: Home</TITLE>"; } if ($_GET['where']=='customize') { echo "<TITLE>Frozenoven :: Customization</TITLE>"; } if ($_GET['where']=='jokes/yourmother') { echo "<TITLE>Frozenoven :: Jokes :: Your Mother Jokes</TITLE>"; } if ($_GET['where']=='jokes/6yroldbacktalk') { echo "<TITLE>Frozenoven :: Jokes :: 6-Year-Old-Back-Talk</TITLE>"; } if (isset($_SESSION["user"])) { echo '<link rel="stylesheet" type="text/css" href="'.$_SESSION["user"].'">'; } else { echo '<link rel="stylesheet" type="text/css" href="white.css">'; } ?> <script type="text/javascript"> function go(location) { parent.location = location } </script> </head> <body> <?php if (isset($_SESSION["user"])) { echo "Hey ".$_SESSION["user"]."! <a href='logout.php'>Logout</a>"; } else { echo "Hey Guest! <a href='http://www.frozenoven.com/index.php?where=make'>wanna customize?</a>"; } ?> <center> <table> <tr> <td align=center> <img src="http://www.frozenoven.com/images/logo.gif" width="500" height="53.7" alt="www.frozenoven.com"> </td></tr> <tr> <td><table><tr> <td width=100 valign=top> <div class="side"><p class="option"><a href="http://www.frozenoven.com/index.php?where=account">Accounts</a></p></div> <div class="side"><p class="option"><a href="http://www.frozenoven.com/index.php?where=jokes/index">Jokes</a></p></div> </td><td valign=top> <div class="main"><p> <?php $mypage = $_GET['where']; $mypage = $mypage.".fzp"; if ($mypage==".fzp") { echo "<script type='text/javascript'>parent.location='http://www.frozenoven.com/index.php?where=home';</script>"; } if (file_exists($mypage)) { echo file_get_contents($mypage); } if (!file_exists($mypage)) { echo "<h1 align=center>404 File not Found!</h1><p>Either the file you are looking for does not exist or you typed the url wrong.</p><p align=center><a href='http://www.frozenoven.com'>Home</a>"; } ?></p></div> </td> </tr> </table> </td> </tr> </table> <table> <tr> <td> <div class="ad"> <script type="text/javascript"><!-- google_ad_client = "pub-2142734016668784"; /* 728x90, created 5/30/08 */ google_ad_slot = "1701812294"; google_ad_width = 728; google_ad_height = 90; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> </div> </td> </tr> </table> </center> </body> </html> Can anyone tell me why this doesn't work? Quote Link to comment https://forums.phpfreaks.com/topic/108078-solved-cookie-problem/#findComment-553974 Share on other sites More sharing options...
darkfreaks Posted May 31, 2008 Share Posted May 31, 2008 Fix: <?php echo "Hey '".$_SESSION["user"].'"! <a href=logout.php>Logout</a>';?> Quote Link to comment https://forums.phpfreaks.com/topic/108078-solved-cookie-problem/#findComment-553976 Share on other sites More sharing options...
blufish Posted May 31, 2008 Author Share Posted May 31, 2008 that doesn't change anything, it still doesn't acknowledge the session. Quote Link to comment https://forums.phpfreaks.com/topic/108078-solved-cookie-problem/#findComment-553978 Share on other sites More sharing options...
darkfreaks Posted May 31, 2008 Share Posted May 31, 2008 try <?php $_SESSION['user']= $_REQUEST['name'];?> Quote Link to comment https://forums.phpfreaks.com/topic/108078-solved-cookie-problem/#findComment-553982 Share on other sites More sharing options...
blufish Posted May 31, 2008 Author Share Posted May 31, 2008 That doesn't change anything either. Quote Link to comment https://forums.phpfreaks.com/topic/108078-solved-cookie-problem/#findComment-553985 Share on other sites More sharing options...
darkfreaks Posted May 31, 2008 Share Posted May 31, 2008 every thing looks fine put ini_set("error_reporting",E_ALL); in your code and tell me what errors you get Quote Link to comment https://forums.phpfreaks.com/topic/108078-solved-cookie-problem/#findComment-553987 Share on other sites More sharing options...
blufish Posted May 31, 2008 Author Share Posted May 31, 2008 I didn't get any errors I put them at the bottom of the pages, is that right? Quote Link to comment https://forums.phpfreaks.com/topic/108078-solved-cookie-problem/#findComment-553988 Share on other sites More sharing options...
darkfreaks Posted May 31, 2008 Share Posted May 31, 2008 put what at the bottom? the error code it should go at the top. also look at my code i edited it the field name was username when it should have been user Quote Link to comment https://forums.phpfreaks.com/topic/108078-solved-cookie-problem/#findComment-553989 Share on other sites More sharing options...
blufish Posted May 31, 2008 Author Share Posted May 31, 2008 ok, I put the error code at the top, I didn't get any errors though. It should say Hey Username! Logout or Hey Guest! Login? if they are not logged in. yeah I changed that Quote Link to comment https://forums.phpfreaks.com/topic/108078-solved-cookie-problem/#findComment-553990 Share on other sites More sharing options...
darkfreaks Posted May 31, 2008 Share Posted May 31, 2008 <?php $_SESSION['user']= $_REQUEST['name'];?> Quote Link to comment https://forums.phpfreaks.com/topic/108078-solved-cookie-problem/#findComment-553992 Share on other sites More sharing options...
blufish Posted May 31, 2008 Author Share Posted May 31, 2008 yeah, I have that. still doesn't do anything.. Quote Link to comment https://forums.phpfreaks.com/topic/108078-solved-cookie-problem/#findComment-553993 Share on other sites More sharing options...
darkfreaks Posted May 31, 2008 Share Posted May 31, 2008 paste your current code plz ??? Quote Link to comment https://forums.phpfreaks.com/topic/108078-solved-cookie-problem/#findComment-553994 Share on other sites More sharing options...
blufish Posted May 31, 2008 Author Share Posted May 31, 2008 File that reads it: <?php ini_set("error_reporting",E_ALL); session_start(); ?> <html> <head> <?php if ($_GET['where']=='jokes/blond') { echo "<TITLE>Frozenoven :: Jokes :: Dumb Blonde Jokes</TITLE>"; } if ($_GET['where']=='home') { echo "<TITLE>Frozenoven :: Home</TITLE>"; } if ($_GET['where']=='customize') { echo "<TITLE>Frozenoven :: Customization</TITLE>"; } if ($_GET['where']=='jokes/yourmother') { echo "<TITLE>Frozenoven :: Jokes :: Your Mother Jokes</TITLE>"; } if ($_GET['where']=='jokes/6yroldbacktalk') { echo "<TITLE>Frozenoven :: Jokes :: 6-Year-Old-Back-Talk</TITLE>"; } if (isset($_SESSION["user"])) { echo '<link rel="stylesheet" type="text/css" href="'.$_SESSION["user"].'">'; } else { echo '<link rel="stylesheet" type="text/css" href="white.css">'; } ?> <script type="text/javascript"> function go(location) { parent.location = location } </script> </head> <body> <?php if (isset($_SESSION["user"])) { echo "Hey ".$_SESSION["user"]."! <a href='logout.php'>Logout</a>"; } else { echo "Hey Guest! <a href='http://www.frozenoven.com/index.php?where=make'>wanna customize?</a>"; } ?> <center> <table> <tr> <td align=center> <img src="http://www.frozenoven.com/images/logo.gif" width="500" height="53.7" alt="www.frozenoven.com"> </td></tr> <tr> <td><table><tr> <td width=100 valign=top> <div class="side"><p class="option"><a href="http://www.frozenoven.com/index.php?where=account">Accounts</a></p></div> <div class="side"><p class="option"><a href="http://www.frozenoven.com/index.php?where=jokes/index">Jokes</a></p></div> </td><td valign=top> <div class="main"><p> <?php $mypage = $_GET['where']; $mypage = $mypage.".fzp"; if ($mypage==".fzp") { echo "<script type='text/javascript'>parent.location='http://www.frozenoven.com/index.php?where=home';</script>"; } if (file_exists($mypage)) { echo file_get_contents($mypage); } if (!file_exists($mypage)) { echo "<h1 align=center>404 File not Found!</h1><p>Either the file you are looking for does not exist or you typed the url wrong.</p><p align=center><a href='http://www.frozenoven.com'>Home</a>"; } ?></p></div> </td> </tr> </table> </td> </tr> </table> <table> <tr> <td> <div class="ad"> <script type="text/javascript"><!-- google_ad_client = "pub-2142734016668784"; /* 728x90, created 5/30/08 */ google_ad_slot = "1701812294"; google_ad_width = 728; google_ad_height = 90; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> </div> </td> </tr> </table> </center> </body> </html> <?php ini_set("error_reporting",E_ALL); ?> code that writes it: <?php ini_set("error_reporting",E_ALL); session_start(); ?> <?php $name = strip_tags($_POST[name]); if (file_exists($name)) { echo "<h1 align=center>Account name already in use!</h1>"; } if (!file_exists($name)) { $layout = $_POST['layout'].".css"; $time = time()+3600*24*365; $_SESSION['user']= $_REQUEST['name']; $nc = strtolower($name); $pass = strtolower($_POST['pass']); $pass = str_replace("a","[1]",$pass); $pass = str_replace("b","[2]",$pass); $pass = str_replace("c","[3]",$pass); $pass = str_replace("d","[4]",$pass); $pass = str_replace("e","[5]",$pass); $pass = str_replace("f","[6]",$pass); $pass = str_replace("g","[7]",$pass); $pass = str_replace("h","[8]",$pass); $pass = str_replace("i","[9]",$pass); $pass = str_replace("j","[10]",$pass); $pass = str_replace("k","[11]",$pass); $pass = str_replace("l","[12]",$pass); $pass = str_replace("m","[13]",$pass); $pass = str_replace("n","[14]",$pass); $pass = str_replace("o","[15]",$pass); $pass = str_replace("p","[16]",$pass); $pass = str_replace("q","[17]",$pass); $pass = str_replace("r","[18]",$pass); $pass = str_replace("s","[19]",$pass); $pass = str_replace("t","[20]",$pass); $pass = str_replace("u","[21]",$pass); $pass = str_replace("v","[22]",$pass); $pass = str_replace("w","[23]",$pass); $pass = str_replace("x","[24]",$pass); $pass = str_replace("y","[25]",$pass); $pass = str_replace("z","[26]",$pass); fopen($pass."+%+".$nc,"x"); fopen("check".$nc,"x"); file_put_contents("check".$nc,$name); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/108078-solved-cookie-problem/#findComment-553995 Share on other sites More sharing options...
darkfreaks Posted May 31, 2008 Share Posted May 31, 2008 code: <html> <head> <?php ini_set('error_reporting',E_ALL); //error reporting if ($_GET['where']=='jokes/blond') { echo "<TITLE>Frozenoven :: Jokes :: Dumb Blonde Jokes</TITLE>"; } if ($_GET['where']=='home') { echo "<TITLE>Frozenoven :: Home</TITLE>"; } if ($_GET['where']=='customize') { echo "<TITLE>Frozenoven :: Customization</TITLE>"; } if ($_GET['where']=='jokes/yourmother') { echo "<TITLE>Frozenoven :: Jokes :: Your Mother Jokes</TITLE>"; } if ($_GET['where']=='jokes/6yroldbacktalk') { echo "<TITLE>Frozenoven :: Jokes :: 6-Year-Old-Back-Talk</TITLE>"; } if (isset($_SESSION['user'])) { echo '<link rel="stylesheet" type="text/css" href="'.$_SESSION['user'].'">'; } else { echo '<link rel="stylesheet" type="text/css" href="white.css">'; } ?> <script type="text/javascript"> function go(location) { parent.location = location } </script> </head> <body> <?php if (isset($_SESSION['user'])) { echo "Hey ".$_SESSION['user']."! <a href='logout.php'>Logout</a>"; } else { echo "Hey Guest! <a href='http://www.frozenoven.com/index.php?where=make'>wanna customize?</a>"; } ?> <center> <table> <tr> <td align=center> <img src="http://www.frozenoven.com/images/logo.gif" width="500" height="53.7" alt="www.frozenoven.com"> </td></tr> <tr> <td><table><tr> <td width=100 valign=top> <div class="side"><p class="option"><a href="http://www.frozenoven.com/index.php?where=account">Accounts</a></p></div> <div class="side"><p class="option"><a href="http://www.frozenoven.com/index.php?where=jokes/index">Jokes</a></p></div> </td><td valign=top> <div class="main"><p> <?php $mypage = $_GET['where']; $mypage = $mypage.".fzp"; if ($mypage==".fzp") { echo "<script type='text/javascript'>parent.location='http://www.frozenoven.com/index.php?where=home';</script>"; } if (file_exists($mypage)) { echo file_get_contents($mypage); } if (!file_exists($mypage)) { echo "<h1 align=center>404 File not Found!</h1><p>Either the file you are looking for does not exist or you typed the url wrong.</p><p align=center><a href='http://www.frozenoven.com'>Home</a>"; } ?></p></div> </td> </tr> </table> </td> </tr> </table> <table> <tr> <td> <div class="ad"> <script type="text/javascript"><!-- google_ad_client = "pub-2142734016668784"; /* 728x90, created 5/30/08 */ google_ad_slot = "1701812294"; google_ad_width = 728; google_ad_height = 90; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> </div> </td> </tr> </table> </center> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/108078-solved-cookie-problem/#findComment-553996 Share on other sites More sharing options...
blufish Posted May 31, 2008 Author Share Posted May 31, 2008 looks just the same, can REQUEST variables be shared across pages? Quote Link to comment https://forums.phpfreaks.com/topic/108078-solved-cookie-problem/#findComment-553998 Share on other sites More sharing options...
darkfreaks Posted May 31, 2008 Share Posted May 31, 2008 request should work fine to my knowledge. it should request the name field and retrieve it from the database. code: <html> <head> <?php ini_set('error_reporting',E_ALL); //error reporting if ($_GET['where']=='jokes/blond') { echo "<TITLE>Frozenoven :: Jokes :: Dumb Blonde Jokes</TITLE>"; } if ($_GET['where']=='home') { echo "<TITLE>Frozenoven :: Home</TITLE>"; } if ($_GET['where']=='customize') { echo "<TITLE>Frozenoven :: Customization</TITLE>"; } if ($_GET['where']=='jokes/yourmother') { echo "<TITLE>Frozenoven :: Jokes :: Your Mother Jokes</TITLE>"; } if ($_GET['where']=='jokes/6yroldbacktalk') { echo "<TITLE>Frozenoven :: Jokes :: 6-Year-Old-Back-Talk</TITLE>"; } if (isset($_SESSION['user'])) { echo '<link rel="stylesheet" type="text/css" href="'.$_SESSION['user'].'">'; } else { echo '<link rel="stylesheet" type="text/css" href="white.css">'; } ?> <script type="text/javascript"> function go(location) { parent.location = location } </script> </head> <body> <?php if (isset($_SESSION['user'])) { echo 'Hey "'.$_SESSION['user'].'"! <a href=logout.php>Logout</a>'; } else { echo "Hey Guest! <a href='http://www.frozenoven.com/index.php?where=make'>wanna customize?</a>"; } ?> <center> <table> <tr> <td align=center> <img src="http://www.frozenoven.com/images/logo.gif" width="500" height="53.7" alt="www.frozenoven.com"> </td></tr> <tr> <td><table><tr> <td width=100 valign=top> <div class="side"><p class="option"><a href="http://www.frozenoven.com/index.php?where=account">Accounts</a></p></div> <div class="side"><p class="option"><a href="http://www.frozenoven.com/index.php?where=jokes/index">Jokes</a></p></div> </td><td valign=top> <div class="main"><p> <?php $mypage = $_GET['where']; $mypage = $mypage.".fzp"; if ($mypage==".fzp") { echo "<script type='text/javascript'>parent.location='http://www.frozenoven.com/index.php?where=home';</script>"; } if (file_exists($mypage)) { echo file_get_contents($mypage); } if (!file_exists($mypage)) { echo "<h1 align=center>404 File not Found!</h1><p>Either the file you are looking for does not exist or you typed the url wrong.</p><p align=center><a href='http://www.frozenoven.com'>Home</a>"; } ?></p></div> </td> </tr> </table> </td> </tr> </table> <table> <tr> <td> <div class="ad"> <script type="text/javascript"><!-- google_ad_client = "pub-2142734016668784"; /* 728x90, created 5/30/08 */ google_ad_slot = "1701812294"; google_ad_width = 728; google_ad_height = 90; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> </div> </td> </tr> </table> </center> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/108078-solved-cookie-problem/#findComment-553999 Share on other sites More sharing options...
blufish Posted May 31, 2008 Author Share Posted May 31, 2008 doesn't change anything. Quote Link to comment https://forums.phpfreaks.com/topic/108078-solved-cookie-problem/#findComment-554001 Share on other sites More sharing options...
darkfreaks Posted May 31, 2008 Share Posted May 31, 2008 you can try the $_GET or $_POST method see which works Quote Link to comment https://forums.phpfreaks.com/topic/108078-solved-cookie-problem/#findComment-554002 Share on other sites More sharing options...
darkfreaks Posted May 31, 2008 Share Posted May 31, 2008 it should be $_SESSION['user']= $_POST; Quote Link to comment https://forums.phpfreaks.com/topic/108078-solved-cookie-problem/#findComment-554004 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.