Jump to content

Recommended Posts

 

You can also escape :

echo "<li><a href='profile.php?=$_SESSION[\'id\']'>My profile</a></li>";

No, that wont work either. When using complex variable name like an associative array within a sting you need to wrap it within curly braces. You cannot escape the quotes for the variable

 

The only time you'd escape quotes would be for the HTML, eg

echo "<li><a href=\"profile.php?={$_SESSION['id']}\">My profile</a></li>";
//                 ^---- escape double quotes ----^
Edited by Ch0cu3r
 <?php

 

if(isset($_SESSION['id']) && $_SESSION['id'] > 0) {

    echo "<li><a href='profile.php?=$_SESSION{['id']}'>My profile</a></li>";

}

 

?>

 

 

The link has now completely disappeared but in my IDE it says there's no errors.

Edited by JackCode

Thank you I have solved the single/double quote problem but now my link has disappeared. Can anyone explain why? Thanks

 

Your conditional expression is not returning true. Print the contents of $_SESSION and check if it has been properly initialized in your code. 

 

Also Jack, make it good habit to always encapsulate your code with the CODE TAGS provided in the editor.

Edited by Dowlat

 

 <?php
 
if(isset($_SESSION['id']) && $_SESSION['id'] > 0) {
    echo "<li><a href='profile.php?=$_SESSION{['id']}'>My profile</a></li>";
}
 
?>
 
 
The link has now completely disappeared but in my IDE it says there's no errors.

 

The curly braces need to go around the whole variable, as {$_SESSION['id']}

echo "<li><a href='profile.php?={$_SESSION['id']}'>My profile</a></li>";
//                              ^---- brace ----^                         
Edited by Ch0cu3r

Well that is the correct syntax, If your link is not appearing your code might be outputting invalid HTML which is causing the link to not appear.

 

When you run your PHP code check the HTML source code via Right click >  view source. Can you spot an HTML error?

Edited by Ch0cu3r

Well that is the correct syntax, If your link is not appearing your code might be outputting invalid HTML which is causing the link to not appear.

 

When you run your PHP code check the HTML source code via Right click >  view source. Can you spot an HTML error?

There is definitely not an error because I tried it in a separate document named test.php and nothing appeared. Basically what I'm trying to do is create a universal link from a page to my profile.php page. Any advice on what I can use alternatively? 

 

There is definitely not an error because I tried it in a separate document named test.php and nothing appeared.

 

By this do you mean you get a completely blank page? If you do, then check your servers error log for php errors. Or turn error reporting on at the top of your PHP script.

ini_set('display_errrors', 1);
error_reporting(E_ALL);

By this do you mean you get a completely blank page? If you do, then check your servers error log for php errors. Or turn error reporting on at the top of your PHP script.

 

ini_set('display_errrors', 1);
error_reporting(E_ALL);

No I don't mean that I mean there is no errors with the HTML because I tried the PHP in a page with no other code and when I tested it there still was no link so there must be an error with the PHP code causing it to not appear.

Your link is visible! The problem is $_SESSION['id'] value has not been outputted, most probably due this variable not being defined before hand, has no value or you have not started the session.

 

What is the output of 

<?php printf('<pre>%s</pre>', print_r($_SESSION, true)); ?>
Edited by Ch0cu3r

Using a web server: my website is backupransack.freeoda.com

 

If you look on the home page then game page the home page is missing the 'my profile' link.

 

Jackcode,

 

The only way the profile link will be printed entirely is if the conditional statement returns (BOOL) True. If your link is visible then thats a different story, your problem lies with the html.

 

If your conditional statement is true, then the ID should print a number more than 0, and it is set. 

 

so I don't see how your url could be empty.

Edited by Dowlat

 

Your link is visible! The problem is $_SESSION['id'] value has not been outputted, most probably due this variable not being defined before hand, has no value or you have not started the session.

 

What is the output of 

<?php printf('<pre>%s</pre>', print_r($_SESSION, true)); ?>

nothing.

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.