Jump to content

markspec87

Members
  • Posts

    63
  • Joined

  • Last visited

    Never

Everything posted by markspec87

  1. Im trying to implement a script that will check if a member is online and then display "members online: 3" When they login it updates their "online" field to 1, and my index just outputs how many rows have their online set to 1. My question is when a user logs out (by closing the browser, how can i detect this and set online to 0?) If they use my logout script it sets it to 0, but other than that i dont know how i can account for a user closing the browser? Maybe im going about this the wrong way? Hopefully you can help me :)
  2. Im looking for a piece of code that can put the filenames from a specific directory as options in a form drop down box. is this possible?
  3. yeh sorry ive missed bits out. Both files have session start, as i said, the username passes perfectly, but the ID just doesnt work.
  4. 2 of my variables will work but the third just doesnt want to work and im stumped why. index page code: [code] if (isset($_SESSION['username'])) {     echo "Welcome back " . $_SESSION['username'];     echo "click <a href='logout.php'>here</a> to logout<BR>";     echo "click <a href='editprofile.php?id=" .$_SESSION['userid']. "'>here</a> to edit your profile<BR>";     echo $_SESSION['userid']; } else {     echo "your not signed up, <a href='signup.php'>signup</a> now or <a href='login.php'>login!</a>"; }[/code] the 4th echo for userid was just for debugging, but its still not working. The username works fine. Login code: (relevant) [code]if(mysql_num_rows($result) == 1) {     // retrieve the access level     $row = mysql_fetch_assoc($result);         // set the session vars:     $_SESSION['username'] = $_POST['username'];     $_SESSION['accesslevel'] = $row['accesslevel'];     $_SESSION['userid'] = $row['id']; }[/code] The row definitely exists and has values in the records, yet on the main page the variable is always null. Any ideas guys?
  5. I have a piece of a code to count the active number of guests that looks like [code]$minutes = 5; $seconds = $minutes*60; $past = time()-$seconds; $now = time(); if ( @mysql_num_rows(mysql_query("SELECT * FROM visitors WHERE ip=$_SERVER[REMOTE_ADDR]")) != 0 ) { mysql_query("UPDATE visitors SET date="$now" WHERE ip=$_SERVER[REMOTE_ADDR]") or die ("Error - Unable to update visit"); } else { mysql_query("INSERT INTO visitors VALUES ($_SERVER[REMOTE_ADDR],"$now")") or die ("Error - Unable to insert records"); } mysql_query("DELETE FROM visitors WHERE date < $past") or die ("Error - Unable to delete old visits"); $visitors = mysql_result(mysql_query("SELECT COUNT(*) FROM visitors"),0); */[/code] However i get a parse error [quote]Parse error: syntax error, unexpected T_VARIABLE in myfile on line 136[/quote] Line 136 is the [code]mysql_query("UPDATE visitors SET date="$now" WHERE ip=$_SERVER[REMOTE_ADDR]") or die ("Error - Unable to update visit");[/code] any ideas guys?
  6. Ive had a go at that but its not working [code]if (is_dir('downloads/$id')) { } else { mkdir("downloads/$id", 0700); } [/code] will still try make the directory even if it exists.
  7. I have a small file upload script where users can upload files for their articles. However it doesnt work unless i manually create the numbered directories. i.e files/uploads/1 files/uploads/2 (each article has a unique ID) so i was wonder if there was a way at the start of my script to check if the directory exists, and if it doesnt create it using the name from my variable $id variable. thanks guys.
  8. no errors but it doesnt work still. Ive tried echoing $hash however it doesnt show, so obviously the problem is around that variable. Ive checked the code and i dont know why its not able to get the hash value from the url.
  9. you guys have been so helpful with my previous problems so i might aswell ask this here :) ive finally got a semi working email activation, the email is sent however when they click the link, the database isnt updated. For simplicty im simply using the timestamp to validate. My signup looks like: [code] $t= time(); $url='http://mywebsite.com/activate.php?hash='.$t; [/code] The activation link, when sent, looks like: [quote]mysite.com/activate.php?hash=1164562953[/quote] Which is how it looks in the database too. Activate.php: [code]<? include("config.php"); $hash = $_GET[’hash’]; @mysql_select_db($dbname) or die( "Unable to select database"); $query = "UPDATE users SET status = 1 WHERE hash = $hash"; mysql_query($query); echo "Your account has been activated<BR>"; ?>[/code] Any ideas why it isnt updating?
  10. I doubt this will work but your missing " " after your = assignment anyway. [quote]<? $id = "1" ; $title = "Main Page" ; $restricted = "0 " ; $keywords = "home page main " ; $type = "1" ; $pagecode = " ?> <lots of HTML> <? "; ?>[/quote]
  11. no, its on the web server. i just uploaded it. tried changing filename and link to db1.php but still it doesnt work. confused :(
  12. I have a peice of code in my config.php which reads an ini style file to get the database details The code starts with [code]$config = parse_ini_file('db.php');[/code] Now the db.php file is in the same folder as this file yet everytime i get the error: [quote]Warning: parse_ini_file() [function.parse-ini-file]: Cannot open 'db.php' for reading in /home/sites/mysite/public_html/includes/config.php on line 3[/quote] But i know for a FACT the file is definitely there. ive chmodded it to allow read write aswell and still it says it cant open it. has anyone got a clue whats going on?
  13. I made a post about my signup script which looks like: [code]<?php include("config.php"); mysql_select_db($dbname) or die ("Could not select database because ".mysql_error()); // check if the username is taken $check = "select id from users where username = '".$_POST['username']."';"; $qry = mysql_query($check) or die ("Could not match data because ".mysql_error()); $num_rows = mysql_num_rows($qry); if ($num_rows != 0) { echo "Sorry, that username $username is already taken.<br>"; echo "<a href=/signup.php>Try again</a>"; exit; } else { $t= time(); // insert the data $insert = mysql_query("insert into users values ('".$_POST['username']."', '".$_POST['password']."','','1', '".$_POST['avatar']."', '".$_POST['email']."', '0','$t', '".$_POST['age']."', '".$_POST['location']."', '".$_POST['clan']."', '".$_POST['website']."', '".$_POST['about']."')") or die("Could not insert data because ".mysql_error()); $to = $_POST['email']; $url='http://www.mysite.com/activate.php?hash='.md5($_POST['password']).'&s tamp='.base64_encode($t); $subject = "Account Activation"; $message = "Hello! This is a simple email message."; $from = "webmaster@clan.com"; $headers = "From: $from"; mail($to,$subject,$message,$headers); echo "Your user account has been created!<br>"; echo "An activation email has been sent to " .$_POST['email']. "<BR>"; } ?>[/code] However when i submit it, i get the error: [quote]Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request.[/quote] ive tried commenting out areas and it works fine if i dont call the mail() function. I looked in my server logs and ive found: [quote][Sat Nov 25 17:29:58 2006] [error] [client 82.153.230.227] malformed header from script. Bad header=/home/sites/mysite.com/dea: processsignup.php, referer: http://www.mysite.com/signup.php[/quote] Does anyone know whats wrong? I cant find anything thats wrong with my current script. The onlyu thought i have is that the email string isnt being passed properly (if im correct the mail() function requires a valid user@domain.com address) Any thoughts?
  14. Ive seen on CMS' like PHPnuke when you access certain files that simply process data or just arent meant to be accessed, it says "you cannot access this file directly". How do you go about doing that? I want to protect some of my admin files that add database information but would prefer not to go through making them admin only. Id rather have nobody be able to use them unless theyve been referred from one of the CMS forms etc. any ideas?
  15. Thanks :) however when i complete the form now and it loads this page it always says: [quote] Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request.[/quote] is this related? or just bad timing?
  16. Sorry for missing that [quote]Parse error: syntax error, unexpected '=' in /home/..... on line 28[/quote]
  17. [code]<?php include("config.php"); mysql_select_db($dbname) or die ("Could not select database because ".mysql_error()); // check if the username is taken $check = "select id from users where username = '".$_POST['username']."';"; $qry = mysql_query($check) or die ("Could not match data because ".mysql_error()); $num_rows = mysql_num_rows($qry); if ($num_rows != 0) { echo "Sorry, that username $username is already taken.<br>"; echo "<a href=/signup.php>Try again</a>"; exit; } else { $t= time(); // insert the data $insert = mysql_query("insert into users values ('".$_POST['username']."', '".$_POST['password']."','','1', '".$_POST['avatar']."', '".$_POST['email']."', '0','$t', '".$_POST['age']."', '".$_POST['location']."', '".$_POST['clan']."', '".$_POST['website']."', '".$_POST['about']."')") or die("Could not insert data because ".mysql_error()); $url='http://www.mysite.com/activate.php?hash='.md5($_POST['password']).’&stamp=’.base64_encode($t); $to = $_POST['email']; $subject = "Account Activation"; $message = "Hello! This is a simple email message."; $from = "webmaster@clan.com"; $headers = "From: $from"; mail($to,$subject,$message,$headers); echo "Your user account has been created!<br>"; echo "An activation email has been sent to " .$_POST['email']. "<BR>"; } ?>[/code] This is my complete signup / email ativation page and it throws the error: [quote]Parse error: syntax error, unexpected '=' in ....[/quote] any ideas?
  18. Thanks for that but i need it for use in a script. I.e use the config to read each line into variables. So i can use it to connect to the database. So how would i read those into variables? Sorry for all Questions :)
  19. works a treat thank you :) now without being too needy, could you point me how to read out those values? :) :)
  20. Sorry for bumping this but ive run into problem. After moving host i now only have php4, instead of 5(temporary) is there a way to get this script working on PHP4? [quote]Fatal error: Call to undefined function: fprintf() [/quote] EDIT: according to my sources this is still a function in PHP4? any ideas whats wrong?
  21. Im Currently making a CMS, as i believe it includes a lot of functions and code ill be using time and time again, but ive run into trouble here. I have a file "config.php" which contains [code] $host = "myhost; // db host $user = "myusername"; // db username $pass = "mypassword"; // db password $db = "mydatabase"; // db name[/code] Im looking for some help on editing this file through PHP. i.e if i have a page with database preferences, if these are altered, the new values will be written to this file. If anyone e can help me out that would be greatly appreciated :)
  22. hello guys, i need some help with a feature ive seen on many websites. Does anyone know how i would implement a active users and guests count? I know that users would obviously be database related but my knowledge of php/mysql is kinda limited (im getting there :P ) Im just wondering if anyone knew of a good piece of code that would me out or anything? any help would be appreciated, thanks.
  23. I currently use the code [code]<? define ('DB_USER', 'hidden'); define ('DB_PASSWORD', 'hidden'); define ('DB_HOST', 'hidden'); define ('DB_NAME', 'hidden'); $dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) or die('Failure: ' . mysql_error() ); mysql_select_db(DB_NAME, $dbc) or die ('Could not select database: ' . mysql_error() ); $query="SELECT * FROM news ORDER BY Datum"; $result=mysql_query($query); $num=mysql_numrows($result); $i=0; while ($i < $num) { $author=mysql_result($result,$i,"author"); $text=mysql_result($result,$i,"text"); $datum=mysql_result($result,$i,"Datum"); $readmore=mysql_result($result,$i,"readmore"); $image=mysql_result($result,$i,"image"); $Title=mysql_result($result,$i,"title"); $summary=mysql_result($result,$i,"summary"); $i++; } $dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) or die('Failure: ' . mysql_error() ); mysql_select_db(DB_NAME, $dbc) or die ('Could not select database: ' . mysql_error() ); $query="SELECT * FROM news ORDER BY datum DESC LIMIT 1,1"; $result=mysql_query($query); $rw = mysql_fetch_assoc($result); $author2=$rw['author']; $text2=$rw['text']; $datum2=$rw['Datum']; $readmore2=$rw['readmore']; $image2=$rw['image']; $newstitle2=$rw['title']; $summary2=$rw['summary']; ?>[/code] To retrieve the most recent and second most recent fields in news. Then i just call the variables for display on my news page (i have another page where news is submitted). Im wondering if theres a simplier or more efficient way to do this? on some pages i have 5 news articles shown and i simply repeat the above but for 5 rows, surely theres a better way? any help would be appreciated :)
  24. yeh i know the code to start with i.e [quote]$sql = "SELECT * FROM members WHERE username="spec"[/quote] But then how can i use this to say output specs age or location? (seperatly ofc)
×
×
  • 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.