PHP - Would Anyone Be Able To Help Me Make A 'user's Online Counter'.
Hey, guys.
I'm a programmer and i've designed an application to assist in an online game. When users visit my website for whatever reason i want to display the amount of users currently using my application. As you may have guessed i'm not to crash hot at php or any web related languages at that . What i think will work, is when my application starts up, i can make it visit a webpage in the background and just idle there while they are using the program, when they close the program obviously it is no longer viewing that webpage. So if there some sort of php counter i can make for this? I was reading some sources to php counters and they count the amount of "sessions" and display that, i was just curious if my program navigates to a webpage upon opening and it doesn't do anything will this 'time it out'? Anyway, any help is appreciated. Thanks. Similar Tutorialsok i want to make it to where when you look at there profile it will tell you if they are online or not! how would i do that ? here is my php script that has some modifications on the profile page but wont show if other users are online! here is the login script where i put the session and the profile page. login.php Code: [Select] <?php // Start Session to enable creating the session variables below when they log in session_start(); // Force script errors and warnings to show on page in case php.ini file is set to not display them error_reporting(E_ALL); ini_set('display_errors', '1'); //----------------------------------------------------------------------------------------------------------------------------------- // Initialize some vars $errorMsg = ''; $email = ''; $pass = ''; $remember = ''; if (isset($_POST['email'])) { $email = $_POST['email']; $pass = $_POST['pass']; if (isset($_POST['remember'])) { $remember = $_POST['remember']; } $email = stripslashes($email); $pass = stripslashes($pass); $email = strip_tags($email); $pass = strip_tags($pass); // error handling conditional checks go here if ((!$email) || (!$pass)) { $errorMsg = '<font color="red">Please fill in both fields</font>'; } else { // Error handling is complete so process the info if no errors include 'scripts/connect_to_mysql.php'; // Connect to the database $email = mysql_real_escape_string($email); // After we connect, we secure the string before adding to query //$pass = mysql_real_escape_string($pass); // After we connect, we secure the string before adding to query $pass = md5($pass); // Add MD5 Hash to the password variable they supplied after filtering it // Make the SQL query $sql = mysql_query("SELECT * FROM myMembers WHERE email='$email' AND password='$pass' AND email_activated='1'"); $login_check = mysql_num_rows($sql); // If login check number is greater than 0 (meaning they do exist and are activated) if($login_check > 0){ while($row = mysql_fetch_array($sql)){ // Pleae note: Adam removed all of the session_register() functions cuz they were deprecated and // he made the scripts to where they operate universally the same on all modern PHP versions(PHP 4.0 thru 5.3+) // Create session var for their raw id $id = $row["id"]; $_SESSION['id'] = $id; // Create the idx session var $_SESSION['idx'] = base64_encode("g4p3h9xfn8sq03hs2234$id"); // Create session var for their username $username = $row["username"]; $_SESSION['username'] = $username; //THIS IS WHERE I EDITED THE SESSION TO SAY IF THERE LOGGED IN OR NOT $logedin = $row['id']; $_SESSION['islogedin']=$logedin; mysql_query("UPDATE myMembers SET last_log_date=now() WHERE id='$id' LIMIT 1"); // THIS WAS JUST A TEST BUT WONT UPDATE UNTILL THEY LOGOUT mysql_query("UPDATE myMembers SET online='online' WHERE id='$id' LIMIT 1"); } // close while // Remember Me Section if($remember == "yes"){ $encryptedID = base64_encode("g4enm2c0c4y3dn3727553$id"); setcookie("idCookie", $encryptedID, time()+60*60*24*100, "/"); // Cookie set to expire in about 30 days setcookie("passCookie", $pass, time()+60*60*24*100, "/"); // Cookie set to expire in about 30 days } // All good they are logged in, send them to homepage then exit script header("location: home.php?test=$id"); exit(); } else { // Run this code if login_check is equal to 0 meaning they do not exist $errorMsg = "<h3><font color='red'>Email/Password invalid<br /></font></h3><a href='forgot_pass.php'>Forgot password?</a><div align='right'> <br> Forget to activate you account?</div>"; } } // Close else after error checks } //Close if (isset ($_POST['uname'])){ ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="icon" href="favicon.ico" type="image/x-icon" /> <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" /> <link href="style/main.css" rel="stylesheet" type="text/css" /> <script src="js/jquery-1.4.2.js" type="text/javascript"></script> <title>Log In</title> <title>Login Page</title> <style type="text/css"> #stage { top: 0px; left: 0px; z-index: 100; } .stage { position: absolute; top: 0; left: 0; width: 100%; min-width: 900px; height: 1359px; overflow: hidden; } #bg { background: #aedfe5 url(images/sky1.png) 0 0 repeat-x; } #clouds { background: transparent url(images/cloud.png) 305px 10px repeat-x; } #sun { background: url(images/land_sun.gif)0 0 no-repeat; } #hillbottom { background: url(images/hill2.png)0 1270px repeat-x; } </style> <link rel="stylesheet" type="text/css" href="css/loginstyle.css" /></head> <body> <!-- IE6 fixes are found in styles/ie6.css --> <!--[if lte IE 6]><link rel="stylesheet" type="text/css" href="css/ie6.css" /><![endif]--> <script src="js/jquery-1.3.2.min.js" type="text/javascript"></script> <script src="js/jquery-ui-1.7.2.spritely.custom.min.js" type="text/javascript"></script> <script src="js/jquery.spritely-0.5.js" type="text/javascript"></script> <script type="text/javascript"> (function($) { $(document).ready(function() { var direction = 'left'; $('#clouds').pan({fps: 40, speed: 0.5, dir: direction, depth: 10}); }); })(jQuery); </script><div id="bg" class="stage"></div> <div id="container"> <div id="sun" class="stage"></div> <div id="clouds" class="stage"> <div id="stage" class="stage"> <body> <div id="behindform"> <form id="signinform" action="login.php" method="post" enctype="multipart/form-data" name="signinform"> <fieldset> <legend>Log in</legend> <label for="login">Email</label> <input type="text" id="email" name="email" /> <div class="clear"></div> <label for="password">Password</label> <input type="password" id="password" name="pass" /> <div class="clear"></div> <label for="remember_me" style="padding: 0;">Remember me?</label> <input type="checkbox" id="remember" style="position: relative; top: 3px; margin: 0; " name="remember"/ value="yes" checked="checked"> <div class="clear"></div> <br /> <input type="submit" style="margin: -20px 0 0 287px;" class="button" name="commit" value="Sign In"/> </fieldset><?php print "$errorMsg"; ?> </form> </div> </div> </div><div id="hillbottom" class="stage"> </div> </body> </html> profile.php This is only a part where i try. but when i putt it on , it wont echo the other peoples on , like it doesnt get the other sessions or somethig Code: [Select] //HERE IS WHERE I STARTED , BUT dONT KNOW WHAT TO DO ! if (isset($_SESSION['islogedin']) && $logOptions_id != $id) { $isonline = "<font color='green'>online</font>"; } else{ $isonline = "<font color='red'>offline</font>"; } // This is to Check if user is online or not! needs editing //$isonline = mysql_query("SELECT online FROM myMembers WHERE id='$logOptions_id'AND online='online'"); //$isonlinecheck=mysql_query($isonline); //if ($isonlinecheck ="online"){ //$online = "is <font color='green'>online!</font>";} //else { // $online = "is<font color='red'> offline!</font>"; //} // End to Check if user is online or not! ?> im trying to count and display the number on users on my site this is the coding im using cant see where im going wrong, its inserted into the data base correctly but wont delete after 60 seconds, cheers matt $session=session_id(); $time=time(); $time_check=$time-60; $sql="SELECT * FROM onlineusers WHERE session='$session'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count=="0"){ $sql1="INSERT INTO onlineusers(session, time, username)VALUES('$session', '$time', '$username')"; $result1=mysql_query($sql1); } else { "$sql2=UPDATE onlineusers SET time='$time' WHERE session = '$session'"; $result2=mysql_query($sql2); } $sql3="SELECT * FROM onlineusers"; $result3=mysql_query($sql3); $count_user_online=mysql_num_rows($result3); $sql4="DELETE FROM onlineusers WHERE time<$time_check"; $result4=mysql_query($sql4); Can somebody put a code that would show all the people that are online on the website? ok well i have this is online script that starts at the login page where it sets a session. well it echos that that person is online even if they are not, i will have all of the code only for the online script so it will be in peaces. ok so here is the login page where the session is started login.php Code: [Select] <?php //ok so if they submit the page and its all right and they login , here is the session that is set for the person, again its just the piece of the script . $_SESSION['logedin'] = $_POST['email']; mysql_query("UPDATE myMembers SET last_activity=now() WHERE id='$id'"); ?> now here is where i call on the session and see if there online , the profile.php is set up to where it sees if it is your profile or not so $logoptions_id is the id that they are logged in as. profile.php Code: [Select] <?php // this is on top of the page , where the session is called and if they are logged in it updates the database where there id is. if( isset($_SESSION['logedin']) ) { mysql_query("UPDATE myMembers SET last_activity=now() WHERE id='$logOptions_id'");// there is where $logOptions_id comes in. } // now this is further down the page(script) where we see if they are logged in or not. $age= 60; //set a variable called age, assign an integer of 60 to it. if( isset($_SESSION['logedin']) ) { $q = 'SELECT id=`$id`, DATE_FORMAT(`last_activity`,"%a, %b %e %T") as `last_activity`,UNIX_TIMESTAMP(`last_activity`) as `last_activity_stamp`FROM `mymembers`WHERE `$id` <> \''.($_SESSION['logedin']).'\''; $isonlinecheck = mysql_query($q); $row = mysql_fetch_assoc($isonlinecheck); if (($row['last_activity_stamp'] + $age)< time()){ $isonline = "is <font color='green'>online!</font>";} else { $isonline = "is<font color='red'> offline!</font>"; } } ?> i wana thank all who helps! your all greatly appreciated it displays is online no matter what! please help me! here is the login.php where the session is started . login.php Code: [Select] <?php // Start Session to enable creating the session variables below when they log in session_start(); // Force script errors and warnings to show on page in case php.ini file is set to not display them error_reporting(E_ALL); ini_set('display_errors', '1'); //----------------------------------------------------------------------------------------------------------------------------------- include 'scripts/connect_to_mysql.php'; // Connect to the database // Initialize some vars $errorMsg = ''; $email = ''; $pass = ''; $remember = ''; if (isset($_POST['email'])) { $email = $_POST['email']; $pass = $_POST['pass']; if (isset($_POST['remember'])) { $remember = $_POST['remember']; } $email = stripslashes($email); $pass = stripslashes($pass); $email = strip_tags($email); $pass = strip_tags($pass); // error handling conditional checks go here if ((!$email) || (!$pass)) { $errorMsg = '<font color="red">Please fill in both fields</font>'; } else { // Error handling is complete so process the info if no errors $email = mysql_real_escape_string($email); // After we connect, we secure the string before adding to query //$pass = mysql_real_escape_string($pass); // After we connect, we secure the string before adding to query $pass = md5($pass); // Add MD5 Hash to the password variable they supplied after filtering it // Make the SQL query $sql = mysql_query("SELECT * FROM myMembers WHERE email='$email' AND password='$pass' AND email_activated='1'"); $login_check = mysql_num_rows($sql); // If login check number is greater than 0 (meaning they do exist and are activated) if($login_check > 0){ while($row = mysql_fetch_array($sql)){ // Pleae note: Adam removed all of the session_register() functions cuz they were deprecated and // he made the scripts to where they operate universally the same on all modern PHP versions(PHP 4.0 thru 5.3+) // Create session var for their raw id $id = $row["id"]; $_SESSION['id'] = $id; // Create the idx session var $_SESSION['idx'] = base64_encode("g4p3h9xfn8sq03hs2234$id"); // Create session var for their username $username = $row["username"]; $_SESSION['username'] = $username; //THIS IS WHERE I EDITED THE SESSION TO SAY IF THERE LOGGED IN OR NOT $_SESSION['logedin'] = $_POST['email']; mysql_query("UPDATE myMembers SET last_activity=now() WHERE id='$id'"); mysql_query("UPDATE myMembers SET last_log_date=now() WHERE id='$id' LIMIT 1"); // THIS WAS JUST A TEST BUT WONT UPDATE UNTILL THEY LOGOUT } // close while // Remember Me Section if($remember == "yes"){ $encryptedID = base64_encode("g4enm2c0c4y3dn3727553$id"); setcookie("idCookie", $encryptedID, time()+60*60*24*100, "/"); // Cookie set to expire in about 30 days setcookie("passCookie", $pass, time()+60*60*24*100, "/"); // Cookie set to expire in about 30 days } // All good they are logged in, send them to homepage then exit script header("location: /socialtscripts/home.php?test=$id"); exit(); } else { // Run this code if login_check is equal to 0 meaning they do not exist $errorMsg = "<h3><font color='red'>Email/Password invalid<br /></font></h3><a href='forgot_pass.php'>Forgot password?</a><div align='right'> <br> Forget to activate you account?</div>"; } } // Close else after error checks } //Close if (isset ($_POST['uname'])){ ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="icon" href="favicon.ico" type="image/x-icon" /> <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" /> <link href="style/main.css" rel="stylesheet" type="text/css" /> <script src="js/jquery-1.4.2.js" type="text/javascript"></script> <title>Log In</title> <title>Login Page</title> <style type="text/css"> #stage { top: 0px; left: 0px; z-index: 100; } .stage { position: absolute; top: 0; left: 0; width: 100%; min-width: 900px; height: 1359px; overflow: hidden; } #bg { background: #aedfe5 url(images/sky1.png) 0 0 repeat-x; } #clouds { background: transparent url(images/cloud.png) 305px 10px repeat-x; } #sun { background: url(images/land_sun.gif)0 0 no-repeat; } #hillbottom { background: url(images/hill2.png)0 1270px repeat-x; } </style> <link rel="stylesheet" type="text/css" href="css/loginstyle.css" /></head> <body> <!-- IE6 fixes are found in styles/ie6.css --> <!--[if lte IE 6]><link rel="stylesheet" type="text/css" href="css/ie6.css" /><![endif]--> <script src="js/jquery-1.3.2.min.js" type="text/javascript"></script> <script src="js/jquery-ui-1.7.2.spritely.custom.min.js" type="text/javascript"></script> <script src="js/jquery.spritely-0.5.js" type="text/javascript"></script> <script type="text/javascript"> (function($) { $(document).ready(function() { var direction = 'left'; $('#clouds').pan({fps: 40, speed: 0.5, dir: direction, depth: 10}); }); })(jQuery); </script><div id="bg" class="stage"></div> <div id="container"> <div id="sun" class="stage"></div> <div id="clouds" class="stage"> <div id="stage" class="stage"> <body> <div id="behindform"> <form id="signinform" action="login.php" method="post" enctype="multipart/form-data" name="signinform"> <fieldset> <legend>Log in</legend> <label for="login">Email</label> <input type="text" id="email" name="email" /> <div class="clear"></div> <label for="password">Password</label> <input type="password" id="password" name="pass" /> <div class="clear"></div> <label for="remember_me" style="padding: 0;">Remember me?</label> <input type="checkbox" id="remember" style="position: relative; top: 3px; margin: 0; " name="remember"/ value="yes" checked="checked"> <div class="clear"></div> <br /> <input type="submit" style="margin: -20px 0 0 287px;" class="button" name="commit" value="Sign In"/> </fieldset><?php print "$errorMsg"; ?> </form> </div> </div> </div><div id="hillbottom" class="stage"> </div> </body> </html>and then this is the profile.php where i see if there online , i could only put sertian areas , script is too big profile.php Code: [Select] <?php //on top of the page where it checks the session and updates the time // This updates the database correctly if( isset($_SESSION['logedin']) ) { mysql_query("UPDATE myMembers SET last_activity=now() WHERE id='$logOptions_id'"); // this is where it selects the users id but it wont work , it says online for every user! $age= 60; if( isset($_SESSION['logedin']) ) { $q = mysql_query('SELECT id=`$logOptions_id`, DATE_FORMAT(`last_activity`,"%a, %b %e %T") as `last_activity`,UNIX_TIMESTAMP(`last_activity`) as `last_activity_stamp`FROM `mymembers`WHERE `$logOptions_id` <> "'.($_SESSION['logedin']).'"'); $isonlinecheck = mysql_query($q); if ($isonlinecheck ="last_activity_stamp" + $age < time()){ $isonline = "is <font color='green'>online!</font>";} else { $online = "is<font color='red'> offline!</font>"; } } ?> PLEASE HELP ME i got my user login and register working with my sql but now if a non logged in user tries to access the shoutbox i want it to redirect them to the register page. <?PHP session_start(); if (!(isset($_SESSION['login']) && $_SESSION['login'] != '')) { header ("Location: /login/main.php"); } ?> im using that code but even if im logged in, it redirects me to the register page? my main site is on the root of the site. the login page and the logged in page is in "/login/ So I'm trying to make a counter that counts how many times a record on mysql database has been viewed. Not a hit counter for a webpage. In other words I have a page that displays the info of that record from the mysql database and within that page I would like to display the amount of times it has been viewed. Would anyone know where I can begin or send me to a good tutorial? Thanks Hey Guys/Girls, Thanks for offering to help! I'm currently setting up a small social network for school and I just basically want to know whether the way I'm dealing with in-active users is appropriate and not going to SLOW down my code A LOT, My method is : 3 Functions: Code: [Select] function update_active_user(){ global $connection; global $id; $time = time(); $result3 = mysql_query("UPDATE users5 SET last_update = '$time' WHERE id = '$id'", $connection); } function update_inactive_users(){ global $connection; $time_to_expire = time() - 300; // 300 seconds off the current time $result2 = mysql_query("UPDATE users5 SET online='0' WHERE last_update < $time_to_expire AND online='1'", $connection); } function update_active_users(){ global $connection; $time_to_expire = time() - 300; // 300 seconds off the current time $result2 = mysql_query("UPDATE users5 SET online='1' WHERE last_update > $time_to_expire AND online='0'", $connection); } First function updates the user's field called last_update to the current time (This will only occer when the script loads and the user has done something on my website, it will update their last_update field to current time) Second function sets ALL users that haven't loaded any pages in the last 300 seconds to offline or field online to 0, which obviously means the user is offline Third function sets ALL users that have loaded pages in the last 300 seconds to online if they're offline The reason I'm worried about this is not because it doesn't work, it's working fine at the moment with 2 users, I'm worried when their might be A LOT of users and there are people who are active. My question is : will it make my scripts really slow or be bad for my database in ANY way if I do use these functions for ALL users because each time it searches the table, it is searching ALL users to see if they're active or inactive. How can i make this hit counter code, so that it doesnt update the views on ALL of my videos. i want it to be unique for each video id. any ideas? Code: [Select] <?php $querySelect = mysql_query("SELECT * FROM `mydatabase` WHERE `counter`"); $row = mysql_fetch_assoc($querySelect); $counter = $row['counter']; if (empty($counter)) { $counter = 1; $insert = mysql_query ("INSERT INTO counter VALUES ('counter')"); } $add = $counter+1; $insertNew = mysql_query("UPDATE mydatabase SET counter=('$add')"); echo "Video Views"; echo ":"; echo" "; echo"<br />"; echo "$counter"; ?> www.game4vids.com if you pick a video you can see that it changes the views on ALL the videos i have. Maybe some experienced people could be letting me know when it comes this?
I thought of a "file storage" web app like "YouSendIt", I also thought of a "web host" web app as a "reseller".
With this I am getting caught up in thoughts, that the traffic could not happen.
Is there something, where one could be more "sure" that the traffic may happen, and with this the "clicks" too, even if it are a $100 or $200 per month?
I would appreciate the suggestions a lot.
There's this really old website called http://ipolygraph.com/google/ Basically it mimics the Google homepage (as you can see it's been a while since they've updated) but the idea is really simple but clever. If you go to the search box and type cars (or whatever) and click search, it searches Google for "cars". However if you type something like /php manual/ you'll notice it changes what you're searching to "What is...etc etc". The idea is say you tell your friend you're on Google and you ask them to think of a card, if you type /4c/ is bob thinking of? it'll look as if you're typing "What is Bob thinking of?", when you hit search it'll be the 4 of clubs. Is there any way to make something similar to this? The idea came to me after I learned about the file_get_contents command in PHP. So I'm trying to make an online quiz where the user can 'take the quiz' or go to 'module' where the user can edit the quiz. I've tried for days to search through the net for this particular one but I can't find any solutions. For the quiz I made a comma delimited text file and tried to use that file to make a multidimensional array. So far I only have the following: <h2>ONLINE QUIZ</h2> <ul> <li><a href='question.php'>Take quiz</a></li> <li><a href='module.php'>Admin Module</a></li> </ul> <?php $file = fopen ("data.txt","r"); $i=0; while (feof($file)==false) { $line = fgets($file); $array[$i]=$line; $i=$i + 1; } fclose($file); session_start(); $_SESSION["questions_array"]=$array; ?> My question is, how do I turn the text file from something that looks like this: HTML is...,Main markup language for web pages,Cross-site Security,Cleverly Structured Scripting,eXtremely Safe and Secure, PHP...,General-purpose server-side scripting language,Cross-site Security,Processing Hypertext Products,Process HTML Prettily To output something like this: Question #1 HTML is... [radio button] a.) Main markup language for web pages [radio button] b.) Cross-site Security etc, etc ll----I will type out the exact plan for this quiz----ll Main page: module and quiz link. For the quiz Question page: Questions only show up one by one. ex.) What is a dog? a.) a human b.) a pet c.) a job d.) a car (Submit button) Answer page: Once submit is hit, the page goes here, where the user can see whether they answered right or wrong. ex.) INCORRECT Your answer: a.) a human Correct answer: b.) a pet (continue link) Note that when 'continue' is hit, the page redirects back to the 'question page' but this time outputs the next question. When no more questions are available, the page automatically redirects to the 'results page'. Results page: Table of results For the module Main: A table of the available questions plus their choice answers ex.) Question l choice a l choice b l [] What? cat toy [] How? rat pop etc. Each row can be selected through a radio button. (so we know which question to edit) Select option: Drop down list whether to 'add', 'edit' or 'delete' a question. Each choice directs to a different page where you can perform the action. Also, if 'delete' is chosen, a confirmation page should show up. (i.e are you sure you want to delete this file?) I think that's detailed enough, I'm so sorry for the trouble;; but please if you don't have the time to help me throughout the whole thing, please help me figure out how to use the text file as a multi-dim array (aka the first thing I asked). I've been dying to know how to do it but I just can't get it to work so I'd really appreciate that! Thank you! I have a paypal shopping cart form. Right now the form submits to paypals normal site and works fine. But the problem is the user can use firebug and change the price before sending to paypal. So i want the form to submit to my php script, where ill whatever is in the session, not what was posted, create an NVP string from that post, then POST that to paypal. I thought i could do this with cURL, but cURL always responds, it never actually takes the user to paypal with post. Is there a way to mimic what a form submit does completely in PHP? Hi guys, I've got a snippet of code that's supposed to make a new directory with the user's unique ID (member_id) in the database. I have the code here but I get a myriad of errors including the infamous "at line 1 error, and the directory does not create. Please help me!! //Create Directory $queryString2 = $_SERVER['QUERY_STRING']; $query2 = "SELECT member_id FROM members WHERE $queryString2 = $row[activation]"; $result2 = mysql_query($query2) or die(mysql_error()); mkdir("/home/gafferzo/www/members/clubs/" . mysql_result($result2,0), 0777); This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=347193.0 Login.php Code: [Select] <?php session_start(); mysql_connect("localhost","root") or die(mysql_error()); mysql_select_db("cute") or die(mysql_error()); $username = $_POST['username']; $password = $_POST['pass']; if (isset($_POST["submit"])) { $log = "SELECT * FROM regis WHERE username = '$username'"; $login = mysql_query($log); $row = mysql_fetch_array($login); $number = mysql_num_rows($login); if ($number > 0) { $_SESSION['username'] = $row['username']; $_SESSION['userlevel'] = $row['userlevel']; if($_SESSION['userlevel']==1) { $_SESSION['is_logged_in'] == 1; header("Location: form2.php"); } else if($_SESSION['userlevel']== 0) { $_SESSION['is_logged_in'] == 1; header("Location: registration.php"); } } Registration.php Code: [Select] <?php echo 'Welcome:' .$_SESSION['is_logged_in'];?> form2.php Code: [Select] <?php session_start(); if (empty($_SESSION['is_logged_in'])) { header("Location:chatframe.php"); die(); // just to make sure no scripts execute } ?> <?php mysql_connect("localhost","root") or die(mysql_error()); mysql_select_db("cute") or die(mysql_error()); $message=$_POST['message']; $a=$_SESSION['username']; if(isset($_POST['submit'])) //if submit button push has been detected { if(strlen($message)>1) { $message=strip_tags($message); $IP=$_SERVER["REMOTE_ADDR"]; //grabs poster's IP $checkforbanned="SELECT IP from ipbans where IP='$IP'"; $checkforbanned2=mysql_query($checkforbanned) or die("Could not check for banned IPS"); if(mysql_num_rows($checkforbanned2)>0) //IP is in the banned list { print "You IP is banned from posting."; } else { $thedate = date("U"); //grab date and time of the post $insertmessage="INSERT into chatmessages (name,IP,postime,message) values('$a','$IP','$thedate','$message')"; mysql_query($insertmessage) or die("Could not insert message"); } } } ?> <html> <head> <script type="text/javascript"> function addsmiley(code) { var pretext = document.smile.message.value; this.code = code; document.smile.message.value = pretext + code; } function a() { var x = document.smile.message.value; if(x=="") { alert("Please insert an message!"); return false; } } </script> <style type="text/css"> body{ background-color: #d8da3d } </style> </head> <body> <form name="smile" method="post" action="form2.php" onSubmit="return a()" > Your message:<br><textarea name='message' cols='40' rows='2'></textarea><br> <img src="smile.gif" alt=":)" onClick="addsmiley(':)')" style="cursor:pointer;border:0" /> <img src="blush.gif" alt=":)" onClick="addsmiley('*blush*')" style="cursor:pointer;border:0" /> <input type='submit' name='submit' value='Send' class='biasa' ></form> <br> <br> </body> </html> In this registration.php when im called back its appear nothing im means the number is not showing and the login code even im had also put the "$_SESSION['is_logged_in'] == 1;" outside if else userlevel statement and then i put $d= $_SESSION['is_logged_in'] == 1; and im echoing back but it is nothing im thinks something wrong in session is login and also still it cannot redirect to admin -form2.php when session is login in is 1 I'm creating a social network for a friend and I need to make a flash webcam to talk to another flash webcam. I have all the flash code working, now all I need is a way to let users match themselves up to each other without other users being able to barge in. What areas of php do I need to learn about to do this? Dallas. Hi everyone... I would like to implement a questionnaire/survey system that has only two Answers (Yes /No). Basically, this questionnaire system will be widely used on Mobile Phones. It will be looking something like this below: http://awardwinningfjords.com/2009/06/16/iphone-style-checkboxes.html Lets say a user selects a response as No (Using the above slider button for a question). That response should be recorded in the database with User Details + Time Stamp. Also, I would like to generate a report for each question (Responses of Multiple Users) and a report at a User Level for the entire questionnaire/survey (s). Can some one guide me the fastest & easiest way to achieve this? I'm a new learner of PHP. Regards Sandeep Hello everybody,
I am honestly quite a newb when it comes to mod_rewrite.
We run a small social media page with different areas and I would like to change the URLs to something more clean and professional.
User profiles look like this:
http://www.sky-mp3.com/index.php?action=cm&siteid=59&wahl=artists&tat=details&keyid=477siteid 59 is the artists list and the keyid at the end is the ID of the artist but should be like: http://www.sky-mp3.com/mischuraor in worse case like: http://www.sky-mp3.com/user/mischuraCMS pages look like this: http://www.sky-mp3.com/index.php?siteid=106but should be like: http://www.sky-mp3.com/charts(page name instead of siteid) What I know so far: - I have to add something to the .htaccess file - I need to change something in the code (but I don`t know where) Im good he? What would be the first step on the path to clean URLs for me? I found alot of infos here and there but found nothing yet for this specific case. Kind regards from and thx in advance from Cologne I would appreciate your assistance, there are tons of login scripts and they work just fine. However I need my operators to login and then list their activities for the other operators who are logged in to see and if desired send their clients on the desired activity. I have the login working like a charm and the activities are listed just beautifully. How do I combine the two tables in the MySQL with PHP so the operator Logged in can only make changes to his listing but see the others. FIRST THE ONE script the member logges in here to the one table in MSQL: <?php session_start(); require_once('config.php'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } $login = clean($_POST['login']); $password = clean($_POST['password']); if($login == '') { $errmsg_arr[] = 'Login ID missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'Password missing'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header("location: login-form.php"); exit(); } $qry="SELECT * FROM members WHERE login='$login' AND passwd='".md5($_POST['password'])."'"; $result=mysql_query($qry); if($result) { if(mysql_num_rows($result) == 1) { session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID'] = $member['member_id']; $_SESSION['SESS_FIRST_NAME'] = $member['firstname']; $_SESSION['SESS_LAST_NAME'] = $member['lastname']; session_write_close(); header("location: member-index.php"); exit(); }else { header("location: login-failed.php"); exit(); } }else { die("Query failed"); } ?> ................................................. ................................ Now I need the person who logged in to the table above to be able to make multiple entries to the table below <? $ID=$_POST['ID']; $title=$_POST['title']; $cost=$_POST['cost']; $activity=$_POST['activity']; $ayear=$_POST['aday']; $aday=$_POST['ayear']; $seats=$_POST['special']; $special=$_POST['seats']; mysql_connect("xxxxxx", "xxx350234427", "========") or die(mysql_error()); mysql_select_db("xxxx") or die(mysql_error()); mysql_query("INSERT INTO `activity` VALUES ('ID','$title', '$cost','$activity', '$aday', '$ayear', '$special', '$seats')"); Print "Your information has been successfully added to the database!" ?> Click <a href="member-profile.php">HERE</a> to return to the main menu <?php ?> |