Php function returns 0?

ok, so I am creating a php registration system and would like to get an easy way to get a link to the exit page by calling a function, but it keeps returning 0. It is its function:

function logout_link() {
include("auth_vars.php"); //This file contains $auth_path_login
return $auth_path_login+"?status=loggedout";}

and here is how I use it:

<a href="<?php echo logout_link();?>">logout</a>

However, he continues to produce:

<a href="0">logout</a>

What is going wrong?

+5
source share
5 answers

An operator for concatenating strings ., not +.

See http://www.php.net/manual/en/language.operators.string.php

+17
source

PHP . - , + - , . + ( ), PHP . 0+0

+7

PHP uses .string concatenation, not +.

Try this instead:

function logout_link() {
   include("auth_vars.php"); //This file contains $auth_path_login
   return $auth_path_login . "?status=loggedout";
}
+6
source

Your PHP code is incorrect. It should be:

function logout_link() {
include("auth_vars.php"); //This file contains $auth_path_login
return $auth_path_login."?status=loggedout";
}
+5
source

You meant:

return $auth_path_login."?status=loggedout";

Concatenation operator .in PHP.

+3
source

All Articles