开发者

Adding a login system [closed]

开发者 https://www.devze.com 2023-03-01 19:05 出处:网络
Closed. This question needs details or clarity. It is not currently accepting answers. 开发者_JAVA百科
Closed. This question needs details or clarity. It is not currently accepting answers.
开发者_JAVA百科

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 2 years ago.

Improve this question

Hey! I bought and settled up my site long ago.. My site is a facebook like site where people can add their own or like others. I thought about adding a login system so people can post with their username and make it easier to make posting-liking contests. I already have the system itself - using this http://www.evolt.org/node/60384

I tried to add an option in the process file that when the session is 'loggedin' the code retrieves the username and in all other cases, 'Anonymous'.

Problem is it doesn't work :(

The code is:

    $today = date("Ymdhis");
    $rand = $today.mt_rand().mt_rand().mt_rand();
    $count = '0';
    $type = 'picture';
    $username = '<? if($session->logged_in){   echo "$session->username"   } else { echo "Anonymous" } ?>';
    $sql = "INSERT INTO `like` (`rand`, `like`, `count`, `created`, `youtube`, `type`,`username`) VALUES ('$rand', '$like', 0, '$today', '$string', '$type', '$username')";

I first defined $username and then 'told' the script to INSERT the $username entry into it's field.

The problem is that when I try this in real-time, the field shows the actual code; <? if($session->logged_in){ echo "$session->username" } else { echo "Anonymous" } ?> instead of the desired output.

Also, I've included the session.php for the login in the start of the process document.

The session.php I used along with all of the other files is available at http://www.evolt.org/node/60384 WITHOUT download.

P.S the code i used for $username is used on the main page to output the username after logged in.. I added the 'Anonymous' part myself.. which could cause it to not work..


The code you post is PHP, but gets put into your side AFTER it is parsed. So it will never 'run'.

Unless you are using some sort of templating system that parses your code twice, don't you mean this?

if($session->logged_in){   
        $username = $session->username;
} else { 
        $username = "Anonymous" ;
}


$username is a variable containing a string :

$username = '<? if($session->logged_in){   echo "$session->username"   } else { echo "Anonymous" } ?>';

Everything that is in the quotes is a string, not PHP code. It won't be executed.

You need to do something like this :

if($session->logged_in){
    $username = $session->username;
} else {
    $username = "Anonymous";
}


Change

$username = '<? if($session->logged_in){ echo "$session->username" } else { echo "Anonymous" } ?>';

to

if($session->logged_in) $username = $session->username; else $username = "Anonymous"

0

精彩评论

暂无评论...
验证码 换一张
取 消