Str_replace & php error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
BlitzCorpUk
Forum Newbie
Posts: 1
Joined: Mon Apr 12, 2010 11:37 am

Str_replace & php error

Post 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
Last edited by Benjamin on Mon Apr 12, 2010 12:59 pm, edited 1 time in total.
Reason: Added [syntax=php] tags.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Str_replace & php error

Post 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);
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply