Page 1 of 1

Str_replace & php error

Posted: Mon Apr 12, 2010 12:31 pm
by BlitzCorpUk
I am using 1 template for my whole site and the following code to check if a user is logged in if i remove the template and str_replace the code works it when i add it with that i get a problem can Any one tell me how to solve this please.
my code checks if a user is logged if yes displays logout if not displays Login.
" Parse error: syntax error, unexpected ';' in /home/Admin/public_html/index.php on line 45"<-- this the line were the code begins in my script
if i remove ":" I get a new error T if error.

Code: Select all

$template= str_replace ("{_SIDE_URL1_}", session_start(); if(!session_is_registered(username))
{
    echo 'href="http://www.mysite.com/Login.php" title="Login">Login';}else
 {
 echo  ' href="http://www.mysite.com/logout.php" title="Logout">Logout</a>'; },$template);
if any one knows how to fix this much appreciated

Re: Str_replace & php error

Posted: Mon Apr 12, 2010 12:52 pm
by AbraCadaver
#1 you don't have any idea what you're doing :-)
#2 you don't have any quotes around all that PHP code that you're using as a replacement.
#3 you could get this to replace but then you'd have to eval your template.

How about this:

Code: Select all

session_start();

if(!isset($_SESSION['username'])) {
	$link = '<a href="http://www.mysite.com/Login.php" title="Login">Login</a>';
} else {
	$link = '<a href="http://www.mysite.com/logout.php" title="Logout">Logout</a>';
}
$template = str_replace("{_SIDE_URL1_}", $link, $template);