Jump to content

Help creating external link (error)


chris86

Recommended Posts

I am trying to add an external link (i.e. a link to Google) into a forum sidebar.  Unfortunately, I am getting a 404 error.  The PHP code (which I was given) is appending my external URL to index.php (community) and then to the categories subdirectory.

When the sidebar URL is clicked, the user should be directed to Google.com (in this example).   

But, instead of going to google.com, the user is directed to domain.com/community/categories/\"http://google.com"

which produces a 404 error. 

Not good.

Here's the code...

[code]
<?php

if(in_array($Context->SelfUrl, array("index.php", "categories.php", "discussions.php", "comments.php", "search.php", "post.php", "account.php", "settings.php"))){
$content = <<< ENDCODE

<br><strong> <font size=\"2"> My Heading Here </strong></font> <br>
<a href=\"http://google.com"> Google</a><br>
<a href=\"http://yahoo.com"> Yahoo</a>

ENDCODE;

$Panel->AddString($content,150);
}

?>
[/code]


I think it's the "SelfUrl, array" part of the code that's screwing up my external link.  But, I am very new to PHP and don't fully understand the code above. 

And, what the heck is <<< ENDCODE  ?  Why three opening brackets?  I have never seen this before. 

I just want to create a functioning external link. 
Link to comment
Share on other sites

I got rid of the array part, and now I'm getting a parse error, which reads...

Parse error: syntax error, unexpected '<' in /home/user_name/public_html/community/extensions/Sidepanel-2006-07-24/default.php on line 13

Apparently, PHP doesn't like the beginning HTML tag.

Here is my code:
[code]

<?php

if(isset($Panel))
<br><strong> <font size=\"2"> My Heading Here </strong></font> <br>
<a href=\"http://lussumo.com"> Lussumo</a><br>
<a href=\"http://google.com"> Google</a>');

?>

[/code]

How do I get rid of the parse error?
Link to comment
Share on other sites

You can't just put HTML in PHP. You have to either print or echo it, or close your php.

[code]<?php
if(isset($Panel)) {
?>
<br><strong> <font size="2"> My Heading Here </strong></font> <br>
<a href="http://lussumo.com"> Lussumo</a><br>
<a href="http://google.com"> Google</a>');
<?php
}
?>
[/code]
Link to comment
Share on other sites

I tried adding a bunch of HTML break tags, and that doesn't work with the way this particular forum is set up.  It just adds a bunch of white space, and pushes the discussion threads further down. 

I would like to add...
[code]
$Panel->AddString($content,150);
[/code]

back into to my code (Problem is, I don't have a string any longer). I think the "150" relates to where the content is positioned on the page.  When I add that line of code back, I get an "undefined variable" error (because $content is undefined). 

How do I define the link data (anchor text and URL's) as $content ?

Link to comment
Share on other sites

$content=

But how does that work with HTML code?

I can’t do

[code]
$content= <br><strong> <font size="2"> My Heading Here </strong></font>
<br><a href="http://lussumo.com"> Lussumo</a><br>
<a href="http://google.com"> Google</a>

[/code]

or I’m going to get another parse error. 

Link to comment
Share on other sites

You need to escape the "'s with \'s

[code]
$content= "<br><strong> <font size=\"2\"> My Heading Here </strong></font>
<br><a href=\"http://lussumo.com\"> Lussumo</a><br>
<a href=\"http://google.com\"> Google</a>";

Enclosing all of that in " "'s tells php that it is a string and it doesnt care how it looks with <> or whatever. Without them, php wont like it.

Dave
[/code]
Link to comment
Share on other sites

Since there are no variables, in the string, you should use single quotes, and then you don't have to escape anything.
$content= '<br><strong> <font size="2"> My Heading Here </strong></font>
<br><a href="http://lussumo.com"> Lussumo</a><br>
<a href="http://google.com"> Google</a>';

I think you need to read up on basic code. Like, what strings, variables, functions ARE.
Link to comment
Share on other sites

Thank you Dave and Jesi.  Yes, Jesi I am very new to PHP, and I could use a good book or two. I am open to any suggestions/recommendations.

Ok, here is my new code...

[code]
<?php

$content= '<br><strong> <font size="2"> My Heading Here </strong></font>
<br><a href="http://lussumo.com"> Lussumo</a><br>
<a href="http://google.com"> Google</a>';


if(isset($Panel))
$Panel->$content;  /* I want to display $content here. Is what I've written accurate?  Is the arrow   
    appropriate here?  I tried searching Google for "arrow PHP" but I didn't find anything. I also tried
searching for " -> PHP" but no luck.  What do you call the arrow symbol?  It's not an operator. */

?>
[/code]

When I upload this code, I get [u]another[/u] error message.  It says "Undefined property" on line 18.  Line 18 is $Panel->$content. 

What have I done wrong? 
Link to comment
Share on other sites

The -> is a call to a function or variable in an object. change $content to content.
What is $Panel? If you're working with a third party script, you should check for support from them before randomly trying to call functions. If that's the way you display content in this class, then okay, but that's not a function so I doubt it will work.
Link to comment
Share on other sites

Thanks Jesi.  I figured it out with the help of some folks who know the forum software very well. 

Here's the code I ended up using:

[code]
<?php

if(in_array($Context->SelfUrl, array("index.php", "categories.php", "discussions.php", "comments.php",
  "search.php", "post.php", "account.php", "settings.php"))){

$ListName = 'Recommended Resources';
$Panel->AddList($ListName, 100);

$Panel->AddListItem($ListName, '<font color="#0000ff"> Heading Title Here</font>', 'http://domain1.com');
$Panel->AddListItem($ListName, '<font color="#0000ff">Heading Title 2 Here</font>', 'http://domain2.com');
}

?>
[/code]

Everything's working great now.  Thanks again for your help.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.