Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
625 views
in Technique[技术] by (71.8m points)

php - Can't use function return value in write context

Ok, here is my code. What it is supposed to do is retrieve the referer that sent you to the page, the user will type someurl.com/refcreate.php?ref=username

<?php
session_start();

$referer = $_GET['ref'];
$_SESSION['referer'] = $referer;

if (!isset($referer))
{
    echo 'You did not specify a referer, please correct this to continue';
    die;
}
elseif($referer == "")
{
    echo 'You did not specify a referer, please correct this to continue';
    die;
}

The above part works fine if they forgot to specify the referer. The below half is to check if the current referer specified is an actual user in the database.

if(refcheck($referer) = false)
    {
        echo 'that referer is not in our database,please double chek the spelling and try again.';
        die;
    }

    function refcheck($ref)
    {
        require('mysql_con.php');

        $query="SELECT username FROM jos_users WHERE username='". $ref ."'";
        echo $query;
        $result = mysql_query($query, $con);
        $exists =mysql_fetch_assoc($result);
        if ($exists != false)
        {
            //return true;      
            echo 'true';    
            return true;

        }

        require('mysql_close.php');
    }
    ?>

OK, I figured out the problem (or problems rather). 1 was it needed to look like this if(refcheck($referer) == false){} instead of if(refcheck($referer) = false);. So it was a missing equal sign and a misplaced colon :P thanks guys

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You're assigning a variable and not comparing it

This refcheck($referer) = false

Should be refcheck($referer) == false

Also, your method should have a default return if your IF condition fails.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...