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

Recommended Answers

All 2 Replies

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.