January 23, 201115 yr Hello my fellow WDF members, If you haven't already seen my topic for me making my own forum script from scratch you can view it here: http://www.webdesignerforum.co.uk/topic/44934-my-own-forum-script/page__p__282167#entry282167 Basically the help that I need links to the code for the script. So here it goes. I want to make a link appear only to an admin. Admin being user level 1. So I'm guessing it has something to do with, $_SESSION['user_level'] != 1 . So how can I do make it so that a link only appears for a user of user level 1 only!! Not sure if that makes too much sense. If not please tell me :/ Danny.
January 23, 201115 yr That is fine, you just need to use an if statement around it and just check that it equals 1 <?php if($_SESSION['user_level'] == 1) : ?> <a href="/blah">link</a> <?php endif; ?>
January 23, 201115 yr Author EDIT: Non-Admin members can't see the link. However guests can! Edited January 23, 201115 yr by DannyG17
January 23, 201115 yr If that's the case you've got the wrong session vars - echo the session at the top of the code so you know what it is <?php echo '<pre>'.print_r($_SESSION, true).'</pre>'; ?> And post back what the value is if it's something strange
January 23, 201115 yr Author That worked, but the code is visible on the template. ( [signed_in] => [user_id] => [user_name] => [user_level] => 0 )
January 23, 201115 yr EDIT: Non-Admin members can't see the link. However guests can! Personally i'd set permissions in the database not in a session set up a field called admin with 2 possibly values 0 being non admin 1 being admin then u can check permissions like this, using a simple user created function function is_admin($session){ $sql = mysql_query("SELECT * FROM table WHERE id = '$session'"); $row = mysql_fetch_array($sql); if($row['admin'] == "1"){ return true; }else{ return false; } } Then you can check it like this if( is_admin($_SESSION['user_id'])){ //Show only what an admin should see }
January 23, 201115 yr Author function is_admin($session){ $sql = mysql_query("SELECT * FROM table WHERE id = '$session'"); $row = mysql_fetch_array($sql); if($row['admin'] == "1"){ return true; }else{ return false; } } where does that bit of code go? I'd like to point out I have never used PHP. I have learnt a lot already just from looking at code today. Hence why I needed a PHP Coder But I still want to learn PHP so this project is great for me Edited January 23, 201115 yr by DannyG17
January 23, 201115 yr That worked, but the code is visible on the template. ( [signed_in] => [user_id] => [user_name] => [user_level] => 0 ) OK well that code doesn't actually do anything other than show you the current users session, it was used just to see what the values in $_SESSION were. By the sounds of it you hadn't set the user level to 0 on log in/out properly for the guest. You can remove that bit of code now
January 23, 201115 yr where does that bit of code go? I'd like to point out I have never used PHP. I have learnt a lot already just from looking at code today. Hence why I needed a PHP Coder But I still want to learn PHP so this project is great for me This is just a simple function to check if a user is an admin or not, u can put it in a global function's file for ur script or where ever
January 23, 201115 yr Author This is just a simple function to check if a user is an admin or not, u can put it in a global function's file for ur script or where ever Ha I'm still lost?
January 23, 201115 yr To be honest you shouldn't be starting on making a forum if you're this new to PHP. It's pretty crazy IMO. Start small and build on your experience
January 23, 201115 yr Author To be honest you shouldn't be starting on making a forum if you're this new to PHP. It's pretty crazy IMO. Start small and build on your experience I like doing it this way. Trust me It's the fastest way I learn. Is how I learnt HTML and CSS.
January 23, 201115 yr Is how I learnt HTML and CSS. HTML & CSS is not programming. PHP is debatably getting into real programming. There is a significant difference in complexity and, unlike HTML/CSS, it's crucial you don't do a dodgy job. I seriously recommend starting something smaller than a forum. If you're under the impression that if($_SESSION['admin'] == 1) is a safe, secure way to check for an admin - you've got a lot to learn! Learn the basics at W3Schools Learn a bit about data structures and the like via the Interwebs Learn about different OOP Concepts; inheritance, abstraction, polymorphism, etc. Learn about OOP in a general sense Get straight into OOP with PHP By this point you should have a reasonable understanding - the learning of syntax/built-in methods will come with time I'm hoping someone like Jock will visit the thread and give you a good-and-proper list for you, but the above should get you to the beginner stage of PHP development. Edited January 23, 201115 yr by andyl
January 23, 201115 yr Ha I'm still lost? Mmmm im confused? do u not even know what a function is? cause i seen ur forum and unless u copied the code to the tee which i think u sorta did cause i seen that tutorial before and its the exact same style. The u should step back like jay said and learn this stuff first, gotta learn to walk before u can run
January 23, 201115 yr Author Mmmm im confused? do u not even know what a function is? cause i seen ur forum and unless u copied the code to the tee which i think u sorta did cause i seen that tutorial before and its the exact same style. The u should step back like jay said and learn this stuff first, gotta learn to walk before u can run Read my other topic (link at top) I have already learnt some php by looking, and have designed a simple Admin CP.
January 23, 201115 yr Read my other topic (link at top) I have already learnt some php by looking, and have designed a simple Admin CP. I did read it and looked at v0.1 of your forum and it looks like you copied the style ect.. from the tutorial you followed. And like Andy said doing if($_SESSION['admin'] == '1') is not secured cause sessions can be hijacked very easy
January 23, 201115 yr Author I did read it and looked at v0.1 of your forum and it looks like you copied the style ect.. from the tutorial you followed. And like Andy said doing if($_SESSION['admin'] == '1') is not secured cause sessions can be hijacked very easy Woops, thought I put on there that I used the source files.
January 23, 201115 yr Woops, thought I put on there that I used the source files. Mmmmm then how can that be u making a forum? its someone else making a forum for u, with u just adding bits and bobs
January 23, 201115 yr Author Mmmmm then how can that be u making a forum? its someone else making a forum for u, with u just adding bits and bobs That's what I was trying to get at. Wanting to expand from where he left off.
January 23, 201115 yr I feel like my post has been overlooked Danny? You seriously need to grasp even the basic programming concepts before you get yourself into terribly insecure, bad habits. Don't just jump in the deep-end with this, it won't work. HTML & CSS is child's play if you've got the patience. PHP is a few steps ahead.
January 23, 201115 yr I feel like my post has been overlooked Danny? You seriously need to grasp even the basic programming concepts before you get yourself into terribly insecure, bad habits. Don't just jump in the deep-end with this, it won't work. HTML & CSS is child's play if you've got the patience. PHP is a few steps ahead. Sorry i deff did not overlook ur post u pretty much gave it in a nutshell lol very good advice for danny or whoever to be honest, sometimes beginners dont like to here it though +1
January 23, 201115 yr Sorry i deff did not overlook ur post u pretty much gave it in a nutshell lol very good advice for danny or whoever to be honest, sometimes beginners dont like to here it though +1 You don't need to apologise - you're not the guy I'm worried about here Edited January 23, 201115 yr by andyl
January 23, 201115 yr Actually HTML/CSS is not programming at all and alot of designers really hate me when i say this but its a hardened truth and could be a painful one if you jump into the deep end without as much as even knowing half the functions that are happening within the forum system. And seeing that you pretty much don't know what a function is it really shows that you need to open up the PHP manual and study or like andy mentioned w3schools. Edited January 23, 201115 yr by webdesigner93
January 23, 201115 yr Author I didn't overlook your post. I'm on W3Schools now and I know HTML and CSS isn't programming.
January 23, 201115 yr I didn't overlook your post. I'm on W3Schools now and I know HTML and CSS isn't programming. Then your on the right track
Create an account or sign in to comment