Web Design Forums

Welcome! Please register or log in: Forgot your password? Why register?
You are here: Web Design Forums » Programming Help » PHP » Problem with user log in code RSS

Problem with user log in code

This thread was started by DGS and has been viewed 542 times, and contains 3 replies, with the last reply made by Danny[MLWA].
Post Reply
1
View DGS's reputation
DGS, WDF User Private message  
Posted June 21 '09 at 02:15 PM
      Posts: 25
Hey everyone.

I found a script that I wanted to use that allows users to register to your website, access members-only pages, have their own profiles, ect...

But there seems to be a problem with the code that I have to put on the pages that I want to be members-only.

Here is the code:

<?php
$username = $_COOKIE['loggedin'];
if (!isset($_COOKIE['loggedin'])) die("You are not logged in, <a href="login.html">click here</a> to login.");
echo "You are logged in $username";
?>


Every time I try to run it, it tells me there's an error on this line:

if (!isset($_COOKIE['loggedin'])) die("You are not logged in, <a href="login.html">click here</a> to login.");


I do not know much of PHP, so I can't tell if anything is wrong.
It would be much appreciated if anyone could help me.

Advertisement Register for free to hide these ads and participate in discussions!

2
32 points at 100%
Posted June 21 '09 at 02:42 PM
      Posts: 76
if (!isset($_COOKIE['loggedin'])) die("You are not logged in, <a href="login.html">click here</a> to login.");

Look closer...

die("You are not logged in, <a href="login.html"> 

You start the string with a quote.. then your're HTML stops the string with the quote... Not good... two ways to fix it...

1. Replace <a href="login.html"> with <a href='login.html'>
2. Or do it the real way.... <a href=\"login.html\">
Lead Web Designer
MLW & Associates, LLP.
W3C Standards Complaint and SEO Friendly
Admin of Vraul

3
View DGS's reputation
DGS, WDF User Private message  
Posted June 21 '09 at 03:01 PM
      Posts: 25
Oohhhh, how could I have missed that.

Thank you very much for your help!

4
32 points at 100%
Posted June 25 '09 at 12:49 PM
      Posts: 76
I have a pretty mean login library for php if you're interested =). It uses the combination of the IP address, cookie, and php sessions which enables the "remember me" function from the same machine and browser (so no one can hijack the session's sent in unencrypted envornments he he).
Lead Web Designer
MLW & Associates, LLP.
W3C Standards Complaint and SEO Friendly
Admin of Vraul

Post Reply

Similar Threads
Thread Thread Starter Forum Replies Last Post
Top 21 PHP Programming mistakes thexchord PHP 18 March 10 '10 08:52 AM
Tricky problem VegaLA ASP and .NET 2 April 22 '05 01:33 PM
User uploads code, or links to it bfsog PHP 2 November 28 '04 04:45 AM
Psuedo Code Please DanielGibbs PHP 5 June 12 '04 12:00 PM