# Custom link

**URL:** <https://forum.kirupa.com/t/custom-link/262472>\
**Category:** programming\
**Created:** [June 6, 2008, 8:13am UTC](https://forum.kirupa.com/t/custom-link/262472 "2008-06-06T08:13:26Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Valerij](https://avatars.discourse-cdn.com/v4/letter/v/e68b1a/32.png) [@Valerij](https://forum.kirupa.com/u/Valerij)\
**Post date:** [June 6, 2008, 8:13am UTC](https://forum.kirupa.com/t/custom-link/262472/1 "2008-06-06T08:13:26Z")

</div>

Hey guys…🙂  
So im trying to create a sidebar for my site and when user logs in he will be able to edit hes profile, to do so he must go to a custom link, but how do I add one of those?  
This is what Ive been trying;

```php
<p><a href="member.php?loginid="\.$_SESSION["username"]."\">'.$_SESSION["username"].'</a></p>

```

The link text works perfectly… But the link does not edit… When I click on it I go to:  
[http://www.myhomepage.com/folder/member.php?loginid=](http://www.myhomepage.com/folder/member.php?loginid=)

Does anyone know how to fix this…?  
Thanks 🙂

---

<div class="post-metadata">

**Author:** ![borrob](https://avatars.discourse-cdn.com/v4/letter/b/a87d85/32.png) [@borrob](https://forum.kirupa.com/u/borrob)\
**Post date:** [June 6, 2008, 9:28am UTC](https://forum.kirupa.com/t/custom-link/262472/2 "2008-06-06T09:28:24Z")

</div>

should be:

\<p\>\<a href=“member.php?loginid=\<?php echo $\_SESSION[“username”]; ?\>”&gt;\<?php echo $\_SESSION[“username”]; ?\>\</a\>\</p\>

or

\<?php  
echo “\<p\>\<a href='member.php?loginid=” . $\_SESSION[“username”] . “’\\>” . $\_SESSION[“username”] . “\</a\>\</p\>”;  
?\>

---

<div class="post-metadata">

**Author:** ![Valerij](https://avatars.discourse-cdn.com/v4/letter/v/e68b1a/32.png) [@Valerij](https://forum.kirupa.com/u/Valerij)\
**Post date:** [June 6, 2008, 5:11pm UTC](https://forum.kirupa.com/t/custom-link/262472/3 "2008-06-06T17:11:54Z")

</div>

Yeah, I kinda tryed thing like that and number of others, but I keep getting an error;

Parse error: syntax error, unexpected T\_STRING, expecting ‘)’ in functions/menus.functions.php on line 63

Anyway, heres my full code;

\*\*\<?php session\_start();

[U]if[/U]($\_GET[‘set’] \> 0)  
{

```
[U]if[/U]($_SESSION['whattoclose'] == NULL)
{

	$_SESSION['whattoclose'] = $_GET['set'];
	
} [U]else[/U] {

	$_SESSION['whattoclose'] = $_SESSION['whattoclose'] . '|' . $_GET['set'];
	
}

```

}

[U]if[/U]($\_GET[‘undo’] \> 0)  
{

```
[U]if[/U](![U]empty[/U]($_SESSION['whattoclose'])){

	$_SESSION['whattoclose'] = str_replace("|".$_GET['undo'] , "" , $_SESSION['whattoclose']);
	$_SESSION['whattoclose'] = str_replace($_GET['undo'] , "" , $_SESSION['whattoclose']);

}

```

}

[U]function[/U] showTitle($id)  
{

```
$title = [U]array[/U](
	"Navigation",
	"Login information",
	);
	
$data = $_SESSION['whattoclose'];

$not = explode( "|" , $data );
[U]if[/U](!in_array( $id , $not ))
{
	[U]echo[/U] $title[$id-1];
	[U]echo[/U] '&lt;a href="member.php?set='.$id.'"&gt; - close **&lt;/a&gt;**';
	
		
} [U]else[/U] {
	[U]echo[/U] $title[$id-1];
	[U]echo[/U] '&lt;a href="member.php?undo='.$id.'"&gt; - open **&lt;/a&gt;**';
	

}		

```

}

[U]function[/U] checkIt($id)  
{

```
$data = [U]array[/U](

	'**&lt;?php

```

**[U]echo[/U] “\<p\>\<a href='member.php?loginid=” . $\_SESSION[“username”] . “’\\>” . $\_SESSION[“username”] . "\*\*\</a\>**\</p\>**";  
?\>**  
**\<p\>** \<a href=“member.php?change=password”\>Change Password\*\*\</a\>**\</p\>\*\*  
 \<p\>\<a href=“member.php?change=email”\>Change Email\*\*\</a\>**\</p\>\*\*  
**\<p\>** \<a href=“member.php?change=account”\>Close account\*\*\</a\>\*\*\*\*\</p\>\*\*’,

```
	' **&lt;p&gt;** Welcome to the members only page '.$_SESSION['username'].'! **&lt;/p&gt;**
	**&lt;p&gt;** You are logged in [U]as[/U] '.$_SESSION['username'].' from the IP address '.$_SERVER['REMOTE_ADDR'].' **&lt;/p&gt;**',
	
	);

$str = $_SESSION['whattoclose'];

$not = explode( "|" , $str );
[U]if[/U](!in_array( $id , $not ))
{

	[U]echo[/U] '**&lt;div [U]class[/U]="table"&gt;**';
	[U]echo[/U] $data[$id-1];
	[U]echo[/U] ' **&lt;/div&gt;**';

}

```

}

?\>\*\*

**\<div [U]class[/U]=“headerr”\>**  
**\<? showTitle(1) ?\>**  
**\</div\>**  
**\<? checkIt(1) ?\>**  
**\<br\>**  
**\<div [U]class[/U]=“headerr”\>**  
**\<? showTitle(2) ?\>**  
**\</div\>**  
**\<? checkIt(2) ?\>**

---

<div class="post-metadata">

**Author:** ![djheru](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/djheru/32/3190_2.png) [@djheru](https://forum.kirupa.com/u/djheru)\
**Post date:** [June 6, 2008, 6:12pm UTC](https://forum.kirupa.com/t/custom-link/262472/4 "2008-06-06T18:12:15Z")

</div>

It looks like you have an extra comma at the end where you define your $data array. PHP editors with syntax highlighting are teh awesome!!!11!!1!11!

---

<div class="post-metadata">

**Author:** ![Valerij](https://avatars.discourse-cdn.com/v4/letter/v/e68b1a/32.png) [@Valerij](https://forum.kirupa.com/u/Valerij)\
**Post date:** [June 6, 2008, 6:27pm UTC](https://forum.kirupa.com/t/custom-link/262472/5 "2008-06-06T18:27:32Z")

</div>

Really? Cant find it:S The error says Im missing an ‘)’ I havent edited any commans and I didnt add any either, it worked before, but once I attemp to edit the link with session everything turns to mess! ☹

---

<div class="post-metadata">

**Author:** ![djheru](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/djheru/32/3190_2.png) [@djheru](https://forum.kirupa.com/u/djheru)\
**Post date:** [June 6, 2008, 6:37pm UTC](https://forum.kirupa.com/t/custom-link/262472/6 "2008-06-06T18:37:22Z")

</div>

I am pretty sure it is something to do with you loading your array. The formatting on your strings is what is causing the problem.

Why do you need to include the php opening and closing tags within your array? In order for the array to be evaluated, you have to be within a php section anyway.

Also, I noticed that you are not escaping some of your quotes properly. I would first assign the strings to a variable, and then load the arrays with those variables. It will help a great deal with readablity.

---

<div class="post-metadata">

**Author:** ![Valerij](https://avatars.discourse-cdn.com/v4/letter/v/e68b1a/32.png) [@Valerij](https://forum.kirupa.com/u/Valerij)\
**Post date:** [June 6, 2008, 7:18pm UTC](https://forum.kirupa.com/t/custom-link/262472/7 "2008-06-06T19:18:12Z")

</div>

Help please? And why does it work with the link title but not inside the link then?

---

<div class="post-metadata">

**Author:** ![borrob](https://avatars.discourse-cdn.com/v4/letter/b/a87d85/32.png) [@borrob](https://forum.kirupa.com/u/borrob)\
**Post date:** [June 9, 2008, 6:59am UTC](https://forum.kirupa.com/t/custom-link/262472/8 "2008-06-09T06:59:39Z")

</div>

now here is the code rewritten to work properly:  
i had to change a few things but mostly the checkit code part

```auto

<?php session_start(); 

if($_GET['set'] > 0)
{

if($_SESSION['whattoclose'] == NULL)
{

$_SESSION['whattoclose'] = $_GET['set'];

} else {

$_SESSION['whattoclose'] = $_SESSION['whattoclose'] . '|' . $_GET['set'];

}

}

if($_GET['undo'] > 0)
{

if(!empty($_SESSION['whattoclose'])){

$_SESSION['whattoclose'] = str_replace("|".$_GET['undo'] , "" , $_SESSION['whattoclose']);
$_SESSION['whattoclose'] = str_replace($_GET['undo'] , "" , $_SESSION['whattoclose']);

}

}

function showTitle($id)
{

$title = array(
"Navigation",
"Login information",
);

$data = $_SESSION['whattoclose'];

$not = explode( "|" , $data );
if(!in_array( $id , $not ))
{
echo $title[$id-1];
echo '<a href="member.php?set='.$id.'"> - close</a>';

} else {
echo $title[$id-1];
echo '<a href="member.php?undo='.$id.'"> - open</a>';

} 

}

function checkIt($id)
{

    $data = array( 
    "<p><a href='member.php?loginid=" . $_SESSION["username"] . "'\\>" . $_SESSION["username"] . "</a></p>",
    "<p><a href='member.php?change=password'>Change Password</a></p>",
    "<p><a href='member.php?change=email'>Change Email</a></p>",
    "<p><a href='member.php?change=account'>Close account</a></p>",

    "<p>Welcome to the members only page '" . $_SESSION['username'] . "'!</p>",
    "<p>You are logged in as '" . $_SESSION['username'] . "' from the IP address '" . $_SERVER['REMOTE_ADDR'] . "'</p>"

    );

    $str = $_SESSION['whattoclose'];

    $not = explode( "|" , $str );
    if(!in_array( $id , $not ))
    {
        echo '<div class="table">';
        echo $data[$id-1];
        echo '</div>';
    }
}

?>

<div class="headerr">
<? showTitle(1) ?>
</div>
<? checkIt(1) ?>
<br>
<div class="headerr">
<? showTitle(2) ?>
</div>
<? checkIt(2) ?>

```

---

<div class="post-metadata">

**Author:** ![Valerij](https://avatars.discourse-cdn.com/v4/letter/v/e68b1a/32.png) [@Valerij](https://forum.kirupa.com/u/Valerij)\
**Post date:** [June 9, 2008, 11:54am UTC](https://forum.kirupa.com/t/custom-link/262472/9 "2008-06-09T11:54:06Z")

</div>

Wow thanks alot! Everything works perfect now =)
