Jump to content

Mr_CHISOL

Members
  • Posts

    404
  • Joined

  • Last visited

Everything posted by Mr_CHISOL

  1. $check = $_POST['check'];$result = mysql_query("SELECT bruker FROM Members WHERE bruker= '$user'");if (mysql_num_rows($result)==0){echo "<p align=\"center\">Ur search didn't turn out any results</p>";}while ($row = mysql_fetch_array($result)){echo $row['user'];} You're comparing the column 'bruker' with the value $user, I guess it should be compared with $check instead...And you use the column 'user' in the while-loop but 'bruker' in the SQL.
  2. You don't need to make anything global...Just use $s .= get_include_contents('ads/leftsideads.php'); Just make sure that the function is "included" somewhere...
  3. Why don't use xampp?I saw a thread in this forum that linked to it...It should work fine, without any configuration (at least in the sence to get mysql/php/apache to work together)XAMPP should work fine wit any OS, at least according to the info i've seen.There also WAMP, for windows only,,,XAMPP
  4. Got this at the include man-page: <?php$string = get_include_contents('somefile.php');function get_include_contents($filename) { if (is_file($filename)) { ob_start(); include $filename; $contents = ob_get_contents(); ob_end_clean(); return $contents; } return false;}?> It works like a charm and I've used it several times.
  5. well, I think that's complex way of doing it.The simplest way is to just have column with the parent-ID, in this you only has one table to keep track on.This is just an example of how the table may look: id title href parent1 Main main.php 02 News news.php 03 Old News main.php 2 And this is how the code that displays the menu could look like $result = mysql_query("SELECT * FROM browse WHERE parent=0"); // Note the use of parent=0, this is the same as level=1// Use a function to display the menu$menuHTML = GetMenu( $result, 0 ); // 0 is the id of the parent// The functionfunction GetMenu( $items, $parent, $indent = " " ){ $html = $indent . "<ul>\n"; while ($row = mysql_fetch_array($items)) { $html .= $indent . " <li>\n"; $html .= $indent . ' <a href="' . $row['href'] . '" title="' . $row['title'] . '">' . $row['label'] . "</a>\n"; // Check for childrens if ($result = mysql_query( "SELECT * FROM browse WHERE parent=".$row['id'])) { // Call this function recursively to get the childs $html .= GetMenu( $result, $row['id'], $indent.' ' ); } $html .= $indent . " </li>\n"; } $html .= $indent . "</ul>\n"; return $html;} That should work fine...An importen thing when programming is flexibility, you don't want rewrite alot of code as soon as you make a change (i.e, more levels to the menu)The recursive function can write out as many levels that you would like without any complex code or changes..,.Good Luck and Don't panic
  6. Mr_CHISOL

    Help please

    Yeah, that's gonna work.Two things though:instead of case "": ... use default at the end, as you don't handle requests that doesn't match any of the sections: switch($_GET['section']) { ... default: include('./home.html'); }; Why don't you use php on the "sections" also, or did you just write .html in the code in the forum?If you use .php files you get some advantages; You can add logic to the sections without editing in the case-structure when you change in the files.You can stop visitors to visit the sections by yourhost.com/section.html: add <?php define( '_SITE_LOADED', 1 );?> in index.php and <? defined( '_SITE_LOADED' ) or die( 'Direct Access are not allowed' );?> to the section-file...
  7. Mr_CHISOL

    PAGE protection

    First: I gave you a "good example" in the other thread.The sessions use a sort of cookies that expire after a predefined number of minutes (or never, but that's not recommended) which means that the user is logged out if she/his is inactive too long.Another advantage with sessions is that your job becomes more easy, as the sessions is client speciffic, the information is handled by the browser (and the session-functions..). To accomplish this without sessions you have two options: make youre own cookies (basically the same as using sessions, so ehy make own cookies when sessions does this better...) and keeping track of IPs and when the user acted last.The problem with the last one is many: it's not a fun job, it can be complex etc, but there's a big security problem: diffrent users may use the same IP and this means that two different users will be treated as the same user; the second user can then do anything the first user can do, eaven if he shouldn't be alowed to.Here is also some tutorials:http://www.tizag.com/phpT/phpsessions.phphttp://www.phpfreaks.com/tutorials/20/0.phphttp://www.phptutorial.info/learn/session.php
  8. Mr_CHISOL

    Help please

    how do you display the section?There's a few different way to do this.I like to have a seperate file (the more code you put in one file the more difficult it is to maintain) called OpenSite.php that I include: ...<div id="main"><?php include "OpenSite.php"; ?></div>.. In that file you put the code that loads the sections.This code differs depending on you use a database table that contains with sections you have or if you to it by hand (as in this example): <? if ((!isset($_GET["section"]))||($_GET["section"] == "start")) { include("welcome.php"); } else if ($_GET["section"] == "gallery") { include("gallery.php"); // ... } else { ?> <br /> The section you're looking for doesn't exists!<br /> If you experience further problems pleas <a href="?section=contact">contact the Administrator</a>, <br /> <? }?> If you use a db, just compare $_GET['section'] with the rows in the table...To link to the different sections use<a href="?section=gallery">Gallery</a><a href="index.php?section=gallery">Gallery</a>or something like that...Hope You found that helpfull.Good Luck and Don't Panic.
  9. I don't now anything about dreamweaver templates, but I think it would be easier to help you out if you provide some sort of code/example of how you done it.It's always to tell whats wrong with something that you can't look at...
  10. Mr_CHISOL

    PHP form

    This will not work att all as there is no call to delu().The call to delu() in the onclick is to a "client-side script" (in the browser, using <script></script>) such as JavaScript or VBScript and has no connection to the "server-side" where PHP works.It's important to keep those two appart, as long as you don't work with ajax, but that is a whole other story...
  11. Mr_CHISOL

    PHP URL

    Detailed information can be found here php.net/session.This is the basics: // Do this before any html or such is outputet on every site where you check if the user is logged insession_start();// Check if the visitor is logged in// I like to use a seperate value for the check, others may notif ($_SESSION['loggedin'] == 1) {// The site code} else { // Tell the user that she/he isn't allowed here if she/his isn't logged in, or someting like that // Good place for a login form (see below)} A simple login form <form action="index.php" method="post"> User: <input type="text" name="user" /><br /> Pass: <input type="password" name="pass" /><br /><input type="submit" value="login" /><br /><input type="hidden" name="site" value="admin" /><input type="hidden" name="task" value="login" /></form> We use hidden fields with the values instead of ?site=admin&task=login as we use POST to send the data, and some servers don't allow POST and GET on the same time (they often ignore GET in those cases). Check login if ($_POST['task'] == 'login') { $sql = "SELECT * FROM users WHERE user='.$_POST['user']; if ($db->run( $sql )) { $row = $db->GetResult(); // Always use md5 or similar to encrypt the password (also when you add the user) // NEVER save the password in plain text if ($row->password == md5( $_POST['pass'] )) { // Save info in session: $_SESSION['user'] = $row->user; $_SESSION['rights'] = $row->rights; // type of rights/user for example admin or normal member // Check this in parts wich demands a speciall level (ex. admin-page) $_SESSION['loggedin'] = 1; // You could save any value you want here, but be conservetive. // A good practice may to be redirect to a certain part of the site here, or just include the site... } else { // wrong password } } else { // Not a valid user }} And when the user logsout: if ($_GET['task'] == 'logout') { $_SESSION['loggedin'] = 0; session_destroy(); } A good practice could be to set $_SESSION['loggedin'] to a random value that also will be saved in the db on login and then compare the $_SESSION['loggedin'] with corresponding row in the db, and then remove the value (or set to 0) on logout, this should stop any "false logged in".Hope you got it, I wrote this rather fast.
  12. Mr_CHISOL

    or operators

    try this: if (empty($_POST["username"]) || emtpy($_POST["password"]) || empty($_POST["email"])) { ...} It should work
  13. Mr_CHISOL

    PHP URL

    Barafranca doesn't do like that, at least not in my browser (Firefox 2.0, Ubuntu), but if they do it on the member-section I don't know.And Ogame uses frames. For this you need a "security/login-system".Sorry if I'm a pain in the a** now, but this is how I see it.
  14. Mr_CHISOL

    PHP URL

    First: That's the question I answered, it's a perfect valid answer on that question.And it's not a good solution to have the same URL in the addressbar all the time.One other way to accomplish that though, is to use a javascript that changes the URL in the addressbar...Second: boen_robot is right; there will always be a way to go directly to that file, unless you make a complex filestructor whith strange names on files and dirs.But that is just not good security, there isn't any advantages with that.A better way is to use logins (secure passwords, one-way encryption etc.), sessions and different "security levels/rights" for different users.I don't know if there's a good tutorial for this, if you don't find one or/and you think it's to complex/difficult (I mean no disrespects, but I now that it can be hard to get in to security-systems, eaven on a basic level. I had my problems with logins and such myself) I recommend a CMS, such as joomla!, it takes a lot of the headaches away, it's like a virtual aspirin for developers. :?)There isn't so difficult to adapt a design to work as a Joomla! template.Edit: Noticed that boen_robot added a reply while I was typing... :?)Good Luckand Don't Panic
  15. Mr_CHISOL

    PHP URL

    Actually, that isn't what the question says.The master only asks how to make the URL stay the same, nomather what page the visitor is on.Hope that the script works at your satisfaction tough.:?)
  16. Mr_CHISOL

    PHP URL

    My I ask why?It perhaps looks good, but it isn't a good solution etiher for the visitors (at least I don't like it) or by XHTML standards...The easiest way to do this is to use a frame:Frame tutorialIt can also be accomplished wtih PHP, JavaScript and forms, but it's a complex and highly NOT recommended solution...
  17. Mr_CHISOL

    PHP form

    Hi!First of: You can't reference a PHP-function from a HTML-form, only functions in "client-side sccripts" such as JavaScript.To accomplish what you want there is two ways: GET or POSTGET: <form action="admin.php" method="GET"> Delete user: <input type="text" value="Deleted user name:" name="del" /><br /> <input type="submit" value="Delete user" /></form> This means that the browser now will call your script with the address admin.php and send the information in the "HTTP-request".POST:Just change method="GET" to method="POST".And here's the PHP-part: <?php// Check if we got a userif (isset($_REQUEST['del'])) { $con = mysql_connect("db01","*****","*****"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("17919", $con); $dels = $_REQUEST['del']; $del = mysql_query("DELETE FROM Members WHERE user = '$dels'"); if ($del){ echo " $dels is succesfully deleted "; } else { echo "There whas an error"; }} Note that this code works with both GET and POST (due to the use of $_REQUEST, you could use $_GET or $_POST instead if you want).I better way to do this is just to add a hidden field to the form: <input type="hidden" name="task" value="deluser" /> and then check the value of task: if ($_REQUEST['task'] == 'deluser') { ...} instead of if (isset($_REQUEST['del'])) { ...} If you use task I recommend that you name the field del to user instead, looks better and are more logic.That became rather long, but I hope you find it helpful, just don't panic
  18. Mr_CHISOL

    phpscript.php

    You can use $_SERVER['SCRIPT_FILENAME'] which contains the full path to the file.If you just wanna have the filename, you can use basename() $file = basename($_SERVER['SCRIPT_FILENAME']); basename - Documentation
  19. It's quite simple, this is just the basics, not much code. (The best way to learn is to figure out it at your own)Create a table (in a database, pref. use MySQL; I call it downloads here...) where you save info. about all files that the users should be able to download.(Columns coculd be: id, file, title, description, downloadcount etc.)Then You should create a admin. script that you can use to simply add the files.Create a script that shows all files/downloads.Here comes the big "secret":The downloadlink for each file should look someting like this ?do=download&file=$id or download.php?file=$id where $id is the id of the file from the DB.Then the script that is called (either by include, in the first example, or a own file, last ex.)Should look something like this (This is "half pseudo"): <? $id = $_GET['file']; // Open database... ... // Get file $query = "SELECT file FROM downloads WHERE id=$id"; $db->RunQuery( $query ); // Depending on which db-motor you use, this will be different $file = $db->GetResult(); // Here is the important thing; header("Location: http://yoursite.com/files/$file"); // This line must be before any output (of HTML) // Close DB...?> Hope you got it... :?)Good Luck, and don't panic
  20. I solved it by using GROUPING BY.It works but I don't think it's an satisfying solution, but it works.
  21. Hello there!I'm working on a component for Joomla!, it's a "quote handler" (I'm tired right now, it's 2am here...).I'm listing all quotes in a list (table: jos_kacquotes) and getting the name of the category it belongs to (table: jos_kacquotes_categories) and the user who added the quote (table: jos_users).In a normal case I use a seperatet query (one for each row..) when I list the quotes to get the username.(It isn't the best, partially because of the whole "seperate data from layout"-thing, but that's not the point)I get the catagory in the same query as I get the quotes: SELECT a.*, b.cattitle FROM jos_kacquotes AS a LEFT JOIN jos_kacquotes_categories AS b ON b.id = a.categoryid ... But as I have added the abbility to sort by column, I need to include the user-table in that query to, and it's hete it gets tricky.Right now I have this query for that: SELECT DISTINCT a.*, b.name, c.cattitle FROM jos_kacquotes AS a LEFT JOIN jos_kacquotes_categories AS c, jos_users AS b ON b.id = a.createdby OR c.id = a.categoryid ORDER BY a.createdby_str, b.name DESC The problem with this query is that it returns "twin-rows" (each row twice).And I can't figure out how I'm going to make it work as I want...Thankfull for all ideas.
×
×
  • Create New...