auto login and sessions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

auto login and sessions

Post by qads »

hey guys
i am makeing a site for a client and he wants auto login, and i have all that part working and all.

if user is new to website then he gets logged in as guest, if the user has logged in before and chose to remain logged in then the script reads the cookie and gets the value and logs him/her in.

Problem:
Me and one other user get logged in as guest by the script, i get to see all the pages, he get "Server not found" error on "new_user.php" page but still sees all the other pages in the site.

so i was wondering why does that happen? and how to fix it?, btw the site is on my computer atm, so is that why i am able to see all the pages?

i am useing Apache 1.3.23, php 4.2.3 on windows XP.

i have't changed anything in php.ini, only email settings.

btw, how would i delete this cookie?

Code: Select all

<?php
$time = time();
$random = mt_rand(0,$time);
$autologin_length = 60*60*24*30;
setcookie("autologin",$random, time() + $autologin_length);
?>
thanks alot for your time
- Qads -
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Did you use a static host-part for an uri somewhere (e.g. localhost) ?


http://www.php.net/manual/en/function.setcookie.php
All the arguments except the name argument are optional. If only the name argument is present, the cookie by that name will be deleted from the remote client. You may also replace an argument with an empty string ("") in order to skip that argument.
...
Common Pitfalls:
...
Cookies must be deleted with the same parameters as they were set with.
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

no i did't use localhost anywhere, i have checked for that 100 times or so, and thanks for cookie tip :P.

also, user2 is able to see the page if i put "text text text text" but not if i put

Code: Select all

<?php
echo "<input type="text" name="name" value="$bla">";
?>
i have quite afew of these fields. and i have checked for codeing errors alot of times and i have't found any, the page has quite alot of html and php so i won't post it here, here is a link to it: http://homepage.ntlworld.com/azizq1/code.htm
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

haven't read much of the code, but 2 things that came to my mind
$username = htmlspecialchars($_POST[username]);
http://www.php.net/manual/en/language.types.array.php#language.types.array.donts
and the extremely long echo
echo "<table border=\"0\" ...
maybe you should leave the php block there for a while.

But anyway...
If you take a look at the 404 page's properties what url is shown?
for IE that's something like
res://C:\WINNT\System32\shdoclc.dll/http_404.htm#not/available.html
while mozilla shows only the url
Both can be found if you right-click within the 404-page and choose properties
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

well, it works fine on the site server so i guess everything is fine :D. and the long echo bit...well i had to do put loads of <?php echo &bla; ?> in fleds so i just made up one big one..are there any problems with that other then it looks like something a cat just eat? :P.
Post Reply