0

This is my php file where it creates a session for the user:-

<?php
    //starting the session
    session_start();

    //checking if session of user is set ot not
    if(isset($_SESSION['UID'])) {
        echo "Welcome, ".$_SESSION['UID'];

    }
    else {
        header("Location: ErrorPage.html");         
    }
?>

And this is my jQuery file:-

$(document).ready(
    function hiding() {           
        $("#links").hide();
    }
);

I want my "#links" to be hidden after a user logs in. How do I include the jQuery file in my if statement in php? I tried:-

include("jqueryFile.js");
require("jqueryFile.js");

But it didn't work.

2
  • why do you want to use javascript for something that can be done via CSS? Commented Sep 2, 2011 at 10:27
  • you can just assign CSS class if the user is logged in like "hidden" and in CSS write .hidden{ display: none;}. However even better approach would be probably to have two templates: one with menu for logged in user and the second one with menu for not logged in user. Commented Sep 2, 2011 at 10:33

3 Answers 3

2

Require and include is for server side files, like php.

you should simply do something like

echo '<script type="text/javascript" src="jqueryFile.js"></script>';

If you want to use the require/include commands you should store your javascript in a .php file

require('jqueryFile.php');

Sign up to request clarification or add additional context in comments.

Comments

1
<?php if (isset($_SESSION['uid'])) { ?>
    <script type="text/javascript" src="jqueryFile.js"></script>
<?php } ?>

Comments

0

you have to output that file (ready to deploy into client)

if (isset($_SESSION['uid'])){
?>
   <script src='jqueryFile.js'></script>
   <script>hiding();</script>
<?php    
}

1 Comment

you can do something better than this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.