0

Hi All Im developing a website here's my situation.
Im using one template and using template to link it to every page and using str_replace to replace parts of my site template for what is needed for each page. Any way my problem is this I have sidebar and in the sidebar i want to put a php scirpt which checks if a user is logged in or not
heres the code

<?php 
$template= str_replace ("{_SIDE_URL1_}", session_start(); if(!session_is_registered(username))
{
echo href="http://www.mywebsite.com/Login.php" title="Login">Login;}else
 {
 echo   href="http://www.mywebsite.com/logout.php" title="Logout">Logout</a>; },$template);?>

$template is for my site template
str_replace is replacing something called SIDE_URL1 which is in my site template.
IT gives me this error

Parse error: syntax error, unexpected ';' in /home/admin/public_html/test.php on line 16

Can any one help me tell me is there another way of doing this because it always gives me an error

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Blitz-labs.com
0

You cannot place statements as parameters.

You need to create your HTML in a string, and then do the replacement with that string as the parameter.

eg:

session_start(); 

if(!session_is_registered(username))
{
 $html = 'href="http://www.mywebsite.com/Login.php" title="Login">Login</a>';
} 
else 
{
 $html = 'href="http://www.mywebsite.com/logout.php" title="Logout">Logout</a>'; 
}

$template = str_replace ("{_SIDE_URL1_}", $html, $template);

Here you create a string and save it to $html. Then replace any instance of the string "{_SIDE_URL1_}" inside $template with $html.

0

Thanks Man that really helped me I wasn't sure how exactly it would work Thanks again. :))

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.