Jump to content

pedro84

Members
  • Posts

    85
  • Joined

  • Last visited

Everything posted by pedro84

  1. Got problem. I need to merge three queries, but when I use UNION I got Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in D:\EasyPHP 2.0b1\www\bootleg2\includes\functions.php on line 90 Line 90: while($r = mysql_fetch_assoc($query)) { echo "<h2 style='padding-bottom:8px; font-size:1.2em;'>"; echo $r['tmp']; Queeries to be merged: SELECT * FROM shows where (band='$band') and (format='video') ORDER BY date SELECT *, COUNT(band) FROM shows where (band='$band') and (format='video') GROUP BY band SELECT DISTINCT(band) AS band FROM shows where format='video' ORDER BY band asc Any suggestions?
  2. Hi there, I got login script. I wanted to add some feature to remember user's login for some time. But first, some code. Function auto_login_cookie sends cookie if user want to, function auto_login checks the cookies. In the cookies only hashed username and user's uniqid are stored. function auto_login_cookie (){ if (isset($_POST['staylogged']) && $_POST['staylogged'] == 1) $username = $_SESSION['username']; $query = mysql_query("SELECT uniqid, username FROM users WHERE username = '$username' limit 1") or die ('Error'); $r = mysql_fetch_assoc($query); setcookie("bbuniqueidhash", $r['uniqid'], time() + 30 * 86400); setcookie("bbusernamehash", md5($r['username']), time() + 30 * 86400, "/", ".traderslists.com", 1); } function auto_login (){ $username = $_SESSION['username']; $query = mysql_query("SELECT uniqid, username FROM users WHERE username = '$username' limit 1") or die ('Error'); $r = mysql_fetch_assoc($query); if (isset($_COOKIE['bbuniqueidhash']) && $_COOKIE['bbuniqueidhash'] == $r['uniqid'] AND (isset($_COOKIE['bbusernamehash']) && $_COOKIE['bbusernamehash'] == md5($r['username']))){ return true; } else { return false; } } Ok. This functions checks if user is logged: function is_authed() { if (isset($_SESSION['username']) && (md5($_SESSION['username']) == $_SESSION['encrypted_name'])) { return true; } else { return false; } } and I check it this way: if (!is_authed()) { die ('You are not permitted to view this page, <a href="login.php">click here</a> to login.'); } There're some problems with that script. First of all, when I'm comparing cookies with the data in database everything is ok. Cookies are sending correctly if I want to, and data are equal with the data in database. But...how to call that function? I tried: auto_login(); if (!is_authed()) { die ('You are not permitted to view this page, <a href="login.php">click here</a> to login.'); } but it does not work. I tried to make it many ways withou any positive result. Have you got any ideas and suggestions? Second case, I tested everything on my local server, but when I tried to debug on the webserver, cookies are not sending:( What did I do wrong? Need help:) Later, Pedro
  3. Oki. Thank you. I understand now. So could I make something like that: <?php $text = $my_variable; function clean($text) ? Or is it possible to change variable when calling function, ex: function clean($my_variable)
  4. The last question. I should post it in the activation.php file? What will this function do?
  5. I need to change variable $text, right?
  6. Ok. Now works great. That's what I meant. Ok..now question. What did I make wrong? Thanks for everyone for reply.
  7. Hi, Thanks for reply. I used every way and even code you posted and Im getting: Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in D:\EasyPHP 2.0b1\www\system\activate.php on line 10 Your account has been already activated
  8. Both of us are right. Saying that md5 is impossible to break I meant that I use id with salt. That's more secure. About my problem. Currently is as following: <?php include ("init.php"); function user_activation () { $password = $_GET['hash']; $timestamp = base64_decode($_GET['timestamp']); $query = mysql_query("UPDATE users SET status=1 WHERE (password = '$password') AND (timestamp = '$timestamp')") or die (mysql_error()); } if (user_activation ()){ echo 'Your account has been activated.'; } else { echo 'Your account has been already activated.'; } ?> This is the problem generating part of the script. The problem is that echo. No matter if status = 1 (no data has been added to datasbase) or status = 0 (data has been added) I got: echo 'Your account has been already activated.'; That's the only problem now;)
  9. Thanks for reply, but I think your proporsal is totally the same I did. It's impossible to breake md5. Why password you ask? It is safe to use the timestamp and passwrod hash to to locate the user because it is very unlikely that another person will register at exactly the same time with exactly the same password as another user. There's only need to split error messages. PS I don't know why there was elseif. Maybe was testing or something. Cheers, Pedro
  10. Hi there, I wrote small function that provides to my site users a email validation. User must click the link thast has been sent with activation email. I'm very tired and can't make one thing. This is the function: function user_activation () { $password = $_GET['hash']; $timestamp = base64_decode($_GET['timestamp']); $query = mysql_query("UPDATE users SET status=1 WHERE (password = '$password') AND (timestamp = '$timestamp')") or die (mysql_error()); $activated = mysql_affected_rows(); if ($activated = 1){ return true; } else { return false; } } if (user_activation()) { echo 'Your account has been activated! Please click here to login'; }elseif (!user_activation()){ echo 'Error! Your account has already been activated!'; } Ok. Let's say that user's account has been activated early. How to change error text? Second thing, how to put any error text here? Cheers! Pedro
  11. Thanks for reply:) Just...did it without reading your post:) Since few days I totally felt in love eith php:) Thanks! Cheers mate! Pedro
  12. I turned on notices and got Notice: Undefined variable: userid in www\system\functions.php on line 38
  13. Yes, I know. But when I try to echo $userid or echo $_SESSION['userid'] Nothing happen ???
  14. Hi all, I wrote quite simple script to allow users to log in but got problem that I can't fix myself. For begining, some data: function user_login function user_login($username, $password) { // Try and get the salt from the database using the username $query = "select salt from users where username='$username' limit 1"; $result = mysql_query($query); $user = mysql_fetch_array($result); // Using the salt, encrypt the given password to see if it // matches the one in the database $encrypted_pass = md5(md5($password).$user['salt']); // Try and get the user using the username & encrypted pass $query = "select userid, username from users where username='$username' and password='$encrypted_pass'"; $result = mysql_query($query); $user = mysql_fetch_array($result); $numrows = mysql_num_rows($result); // Now encrypt the data to be stored in the session $encrypted_id = md5($user['userid']); $encrypted_name = md5($user['username']); // Store the data in the session $_SESSION['userid'] = $userid; $_SESSION['username'] = $username; $_SESSION['encrypted_id'] = $encrypted_id; $_SESSION['encrypted_name'] = $encrypted_name; if ($numrows == 1) { return 'Correct'; } else { return false; } } login.php file <?php // Include init file include 'init.php'; if (!isset($_POST['submit'])) { // Show the form include 'login_form.inc.php'; exit; } else { // Try and login with the given username & pass $result = user_login($_POST['username'], $_POST['password']); if ($result != 'Correct') { // Reshow the form with the error $login_error = $result; include 'login_form.inc.php'; } else { echo 'Thank you for logging in, <a href="usercp.php?'; } } ?> Ok. Script works quite correctly, only one bug. How can I get user ID from database? I need this to make this link <a href="usercp.php? like that <a href="usercp.php?username=USERID_FROM_DATABASE ? I do not need code, only tips;) Any help will be appreciated. Cheers! Pedro
  15. Will try it. Another question....is there a way to make a register form you can recommend?
  16. Hi! Wanna to add some features to my site and I'd like to ask if it's even possible. I want to give my users opportunity to post their lists of their music. So...I'd like to host eveyrthing in one table, in one record. I think I can do this, but I got problems with some other things. How to allow them editing this lists later? How to make, I don;t know how to call it, but after registration and submitting their list I'd like it to be accessible @ http://mysite.com/user_name ? Every help will be very appreciated!
  17. tinker: But I don't know how to apply it in this case...
  18. Thanks for reply. Ok, I know what mod-rewrite is. But how to apply it? Don't know...
  19. Hi users! I got account here some months ago, but I think it was deleted due to inactivity. I got back in to my php excercises and got problem. I'd like to make a qusi hosting system for my forum users & I get some problems. Maybe not with doing it, but with idea how to sort it out. Ok. I start from begining. Only plain text will be hosted so I think it wouldn't be so hard. I got form. Users fill this form out. I know how to to that. I want all data to be stored in database, but I got some problems with it. So..we got from filled out, all data has been sent to the database and generally life is beautiful now. But I always must to have ideas I can sort out myself. Is it any way to make something like that: All data from filled out form are stored in database. How to make this list accessible for everybody? Example. User with username "John" has posted his site, how to make his list online @ address: http://www.mysite.com/john ? Is it any way to do that? Of course, all data will be printed from database, I got some teplates. Should I store all data in one table, right? But how to make it online. I got everything sorted out without this. I simply don't know how to do that:( Sorry for strange language, but I try to make it for 5 hours & I'm bit crazy right now. Thanks for anybody for ANY tip. Cheers, Pedro
  20. Could You be so nice and show me how to do that? I have the same problem in other topic!
  21. Ok. I have quasi done it. I need only something like that: If cookie exist, read language from it, if don't send it...hmm how to do that?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.