954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Need Help in PHP

Hello, I have designed a website that has some things for only registered users. I have javascript to hide these object if the user is not logged in using . But the problem is that when the page loads these items show up for a while and then hide I want to stop that.

Thanks

architact
Junior Poster
115 posts since Apr 2008
Reputation Points: 40
Solved Threads: 7
 

What you are probably doing is setting the default action to shown when the default action should be hidden. Then if a user is logged in the hidden items are then shown rather than the other way around.

R0bb0b
Posting Shark
998 posts since Jun 2008
Reputation Points: 358
Solved Threads: 89
 

Thanks for quick reply.

for example i want to hide a button from unregistered users, but it shows up fro 4-5 seconds and then hides.
i am using
document.getElementById('btn').style.visibility = 'none';

on body load

architact
Junior Poster
115 posts since Apr 2008
Reputation Points: 40
Solved Threads: 7
 

Thanks for quick reply.

for example i want to hide a button from unregistered users, but it shows up fro 4-5 seconds and then hides. i am using document.getElementById('btn').style.visibility = 'none';

on body load


Right, exactly, you are waiting until the page fully loads until you hide the button with your page load event. You should use

<input id="btn" type="button" style="display:none" />

Then your javascript onload event will check if the user is authenticated and display the button with:

document.getElementById('btn').style.display = 'block';

or

document.getElementById('btn').style.display = 'inline';
R0bb0b
Posting Shark
998 posts since Jun 2008
Reputation Points: 358
Solved Threads: 89
 

You've got the answer above, but remember that people can "view source" and see things hidden from the page display...just a thought to keep in mind.

langsor
Posting Whiz
390 posts since Aug 2008
Reputation Points: 30
Solved Threads: 36
 

Thanks a lot for the solution
same can be used for an image or table?

architact
Junior Poster
115 posts since Apr 2008
Reputation Points: 40
Solved Threads: 7
 
Thanks a lot for the solution same can be used for an image or table?


Yes you can, and as langsor stated, this is not for security, if you are trying to restrict access to something you should go with a server side solution. This will only hide it from plain site, but just remember that it is not hard to view all of your javascript no matter where you are pulling it from. Even if you don't see the javascript in the source and are getting it from another file, it can be read with things like the "web developer" add on with firefox and other applications.

R0bb0b
Posting Shark
998 posts since Jun 2008
Reputation Points: 358
Solved Threads: 89
 

Any html element can be hidden/shown using this method.

Images are 'inline' elements
Table are 'block' elements

Ciao

langsor
Posting Whiz
390 posts since Aug 2008
Reputation Points: 30
Solved Threads: 36
 

I am using php but i haven't figured out how to hide elements based on security, can you suggest what to do?

architact
Junior Poster
115 posts since Apr 2008
Reputation Points: 40
Solved Threads: 7
 

If you are looking for a server side security mixed with the wonders of javascript then an ajax solution would be the way to go.

R0bb0b
Posting Shark
998 posts since Jun 2008
Reputation Points: 358
Solved Threads: 89
 

no you said that i should go with a server side solution, can i hide object with php, or any thing to ristrict users from getting to an object.

Thanks

architact
Junior Poster
115 posts since Apr 2008
Reputation Points: 40
Solved Threads: 7
 

no you said that i should go with a server side solution, can i hide object with php, or any thing to ristrict users from getting to an object.

Thanks


Unfortunately, there is a learning curve to it but I will say that you want to use session variables. I would start with doing a google search on password protection using sessions.

R0bb0b
Posting Shark
998 posts since Jun 2008
Reputation Points: 358
Solved Threads: 89
 

Hello thanx for your help:
The solution i have figured out is
<?php
if(isset($_SESSION['id'])){?>
Hello
<?php } ?>

is it secure?

architact
Junior Poster
115 posts since Apr 2008
Reputation Points: 40
Solved Threads: 7
 

Hello thanx for your help: The solution i have figured out is <?php if(isset($_SESSION['id'])){?> Hello <?php } ?>

is it secure?


Yes, this is secure. I actually do this normally to not only verify that the session variable isset but that it isn't empty either:

<?php
if(isset($_SESSION['id']) && trim($_SESSION['id']) != ""){?>
<td>Hello</td>
<?php } ?>
R0bb0b
Posting Shark
998 posts since Jun 2008
Reputation Points: 358
Solved Threads: 89
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You