Jump to content

Link "Results" for user1 should point to www.site.com/user1, for user2 to www.site.com/user2. Is it possible?


hariskar

Recommended Posts

I would like to ask if this function is possible with javascript: After a member logins in my site with name eg user1, if he clicks on menu item "Results" I want him to see only his results, so go to link www.site.com/user1.

A second user with name user2 if he clicks the same menu item "Results" www.site.com/user2 should open.

Is that possible with javascript? How should I start?

 

Thank you

Link to comment
Share on other sites

You should do that with a server-side language. Whichever language you built the login system with.

 

What happens if user 1 types www.site.com/user2 into his browser? Will it show him the results for user 2?

  • Like 1
Link to comment
Share on other sites

If only the user sees the page, does it make sense to have one URL for each user?

 

Just having a single URL, like www.site.com/results, will be enough. On that page you would detect which user is logged in and display the correct information using a server-side language.

  • Like 1
Link to comment
Share on other sites

My site now with drupal and views works exactly like this: www.site.com/results for every user, but each user can see only his results. But now I want to rebuild my site without drupal. So I have to learn php :) .

Link to comment
Share on other sites

  • 1 month later...

If someone logins, there is a redirection in login.php to results.php

if($user->login($username,$password)){ 
		$_SESSION['username'] = $username;
		header('Location: /results.php');

So, in results.php there is a paragraph that should be visible for not logged in users. I would like it to be replaced with the users results if the user has results and is logged in. But it should be replaced with each users own results. Of course each users should be able to see only his results.

If he has no result this paragraph and is logged in should just not show.

 

Could you please give me some hints?

 

I thought:

With session_start these in the 2 files:

 

and put in results.php something like:

<?php
 $results = file_get_contents($username".html");?>
<script>
    function ChangeParagraph(par1)
    {
      if( $username->is_logged_in() 
            {
            document.getElementById("par1").innerHTML = "<?php echo $results; ?>";
            }
        }
</script>
?>

of course it does not work..

 

Thank you

Link to comment
Share on other sites

Why mix JavaScript and php? can't you just create if else for paragraph content and assign to variable then echo result wherever you require it, it is then not relying on JavaScript being enabled to work.

 

PS where is function being called to display result?

Link to comment
Share on other sites

Thank you, this works for me

 

<?php

if (!$_SESSION['username']) {?>

<p>Original text</p>

<?php } elseif ($_SESSION['username']==username1) {?>

<p>Text for username1</p>

<?php } ?>

 

Edited by hariskar
Link to comment
Share on other sites

With 3 cases it does not work as expected, if user hariskar logs in, echoed text is "hariskar text". If hariskar user logs out and test user logs in echoed text is again hariskar, which is wrong, although if I do

print_r($_SESSION);

the result is "testArray ( [loggedin] => 1 [username] => test [memberID] => 2 )" which is correct. Why do we not see the "test text" echoed?

Thank you!

<?php
if ($_SESSION['username']==hariskar) {
echo "hariskar text";
} elseif($_SESSION['username']==test) {
echo "test text";
} else {
echo "Some text."; 
 }
?>

PS. Maybe this topic should be moved in php section?

Edited by hariskar
Link to comment
Share on other sites

Thank you but I have already tried it, no difference, it still shows the "hariskar text" for user test..

<?php
if ($_SESSION['username']=="hariskar") {
echo "hariskar text";
} elseif($_SESSION['username']=="test") {
echo "test text";
} else {
echo "Some text."; 
 }
?>
Link to comment
Share on other sites

With

<?php
echo $_SESSION['username'];
if ($_SESSION['username']=="hariskar") {
echo "hariskar text";
} elseif($_SESSION['username']=="test") {
echo "test text";
} else {
echo "Some text."; 
 }
?>

for logged in user hariskar the result is

 

1hariskar text

 

for logged in user test

the result is again

1hariskar text

So

echo $_SESSION['username'];

gives 1. But why?

 

 

 

I start session with

<?php
session_start();
?>

in 1st line of results.php.

 

Thank you

Edited by hariskar
Link to comment
Share on other sites

It works perfectly now, something broke in included file login.php, but now it is OK!

Thank you!

<?php
if ($_SESSION['username']=="hariskar") {
echo "hariskar text";
readfile("arthra.html");
} elseif($_SESSION['username']=="test") {
readfile("results/xxx.html");
} else { ?>
<p>Αν θέλετε να μπορείτε να κατεβάζετε τα αποτελέσματά σας σε μορφή pdf παρακαλώ ενημερώστε μας και <a href="/user/register">εγγραφείτε στη σελίδα μας</a>.</p>
<?php } ?>
Edited by hariskar
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...