anolan13 Posted September 14, 2007 Share Posted September 14, 2007 Hi everyone, I'm trying to make a fairly simple login system based off of a couple bits of code and its not working right, hope you can help... So the page before I make a session after the person registers successfully with logname which is just the name he logged in with, I also write a text file with the contents being that same logname. Here's my code on the protected page. $myFile = "testFile.txt"; $fh = fopen($myFile, 'r'); $theData = fread($fh, filesize($myFile)); session_start(); if (@$_SESSION['logname'] != $theData) { header("Location: http://mywebsite.com/login.html"); exit(); } If I echo command $theData I see what it's contents are. If I type in $theData as the persons logname directly it works correctly and allows the rest of the page to run. But for some reason it won't accept this block of code, it keeps kicking me back to mywebsite.com/login.html. I'm very confused, please help! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/69275-solved-fread-not-working-right/ Share on other sites More sharing options...
btherl Posted September 14, 2007 Share Posted September 14, 2007 Try adding this line just before your "if" statement: print "Logname: " . urlencode($_SESSION['logname']) . ", thedata: " . urlencode($theData); exit(0); Do they match exactly? Quote Link to comment https://forums.phpfreaks.com/topic/69275-solved-fread-not-working-right/#findComment-348116 Share on other sites More sharing options...
anolan13 Posted September 14, 2007 Author Share Posted September 14, 2007 results Logname: 5, thedata: 5%0A So where did it get 5%0A???????? How come when I echo its exact? What to do? Quote Link to comment https://forums.phpfreaks.com/topic/69275-solved-fread-not-working-right/#findComment-348119 Share on other sites More sharing options...
btherl Posted September 14, 2007 Share Posted September 14, 2007 That's a "newline" character. It shows up in echo as an actual new line, so that's why you don't see it. The easiest way to deal with it is to use trim() on your data from fread(). trim() will remove spaces, newlines and some other invisible stuff from the start and end. Quote Link to comment https://forums.phpfreaks.com/topic/69275-solved-fread-not-working-right/#findComment-348122 Share on other sites More sharing options...
anolan13 Posted September 14, 2007 Author Share Posted September 14, 2007 thanks a bunch Quote Link to comment https://forums.phpfreaks.com/topic/69275-solved-fread-not-working-right/#findComment-348130 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.