Jump to content

Errant_Shadow

Members
  • Posts

    123
  • Joined

  • Last visited

    Never

Everything posted by Errant_Shadow

  1. I had previously forgot to set error reporting back to E_ALL after disabling it for my last migration over to the live domain (so amateur =_=) but even after turning it back on, no errors pop up.
  2. The script is cycling through many rows, so that will make a file with the name of the last row returned.
  3. Here's the basic logic you'll need, but the specific details can be found in many tutorials around the web. (NOTE: All code here is pseudo-code, not meant to actually work) First, you write a script to fetch the data you need require_once("database_connect.php"); // this is1 where you hold the connection details to your database // for this exercise, we'll assume the connection variable is called $con and that you connected to the appropriate database within that script $today = date("Y-m-d"); // creates a variable for the current date (and time) $1Day = date_add($today, new DateInterval('P1D')); // creates a variable for 1 day from today $2Day = date_add($today, new DateInterval('P2D')); // creates a variable for 2 day from today // this is assuming you will be telling everyone who has an appointment any time tomorrow // basically, you'd run this script at 1am // $1Day would be the date and time for 1am tomorrow and // $2Day would be the date and time for 1am the following day // then all you'll need to do is fetch all appointments between those date/times $query = "SELECT * FROM clients WHERE appointment > $1Day AND appointment < $2Day "; // appointment is GREATER than (past) 1am tomorrow but LESS than (before) 1am the next day $results = mysql_query($query, $con) or die(mysql_error()); // $results is not the actual data, you will need to exrtact the data to access it // people say it's poor form to use that die command // but for the purposes of this exercise, it will help you get it squared away // this will cycle through each record that the query fetched while($client = mysql_fetch_array($results)) { // and run your e-mail script here } Once you have that script working, you'll need to talk to your web host service and ask them how you can add cronjobs to your database. If they can't or don't allow you that level of access, maybe you should switch providers. If they provide you a site and database through them, you should have access to it.
  4. I don't know. When I have the script dump those variables, they come back as undefined, but when I don't they must be there because the auto-login script keeps activating.
  5. The worst problems tend to have the easiest fixes *nods* Be sure to mark as solved and happy coding.
  6. Try not escaping the string and seeing what it gives you? Or try escaping the string outside of assembling the query? Or perhaps try another method besides sprintf. $q = mysql_real_escape_string($question); $query = "SELECT answer FROM registertest WHERE question='$q' ";
  7. Just to make sure, on content.php, there are the <?PHP ?> tags? <?php echo '<center>My cat said '. $cat .' today!</center>'; ?>
  8. Is $row['title'] what you want? The result resource is not the data fetched by the query. You have to use mysql_fetch_array (or a similar function) to access the data. It is giving you "Resource id #3.php" because it has made a successful execution and is returning data. I see you are looping through the results and printing each title, so I wonder what you are using to derive the name of the file you are making?
  9. The best way I know to have a server automatically execute a script is to use cron jobs with MySQL. Basically you write a script that grabs the data you want and does something with it; I imagine in your case it will grab anyone with an appointment within the next x# hours/days/whatever and parse all of there info into a nice little e-mail, then send them all out. Once that's done, you set up a cron job (do some google searches, there are a bunch of tutorials) to execute that script on a specific schedule. Do you need info about how to execute those database searches, parse the data, or use the mail() function?
  10. /sigh... Not sure how to boil down my problem to anything simpler.
  11. Finally, my log out function simply sets the cookies to expire, destroys the session, and reloads the site. <?php if (isset($_SESSION['uid']) && (isset($_GET['a']) && $_GET['a'] == 'logout')) { // echo "<hr /><hr /><hr /><hr />logging out..."; // delete cookie... setcookie("uid", "", time() - 3600, "/", ".virtuocracy.com"); setcookie("email", "", time() - 3600, "/", ".virtuocracy.com"); setcookie("pword", "", time() - 3600, "/", ".virtuocracy.com"); if (ini_get("session.use_cookies")) { $params = session_get_cookie_params(); setcookie(session_name(), '', time() - 42000, $params["path"], $params["domain"], $params["secure"], $params["httponly"]); } session_unset(); session_destroy(); header('Location: /'); } ?> And of course, here's where it gets frustrating. I have a series of echoes that output data in between the logout code and the code that checks for cookies. <?php echo "<hr /><hr /><hr /><hr />"; echo "SESSION[uid] = "; if (isset($_SESSION['uid'])) { echo $_SESSION['uid'] ."<br />"; } else { echo "Unavailable!<br />"; } echo "COOKIE[uid] = "; if (isset($_COOKIE['uid'])) { echo $_COOKIE['uid'] ."<br />"; } else { echo "Unavailable!<br />"; } echo "COOKIE[email] = "; if (isset($_COOKIE['uid'])) { echo $_COOKIE['email'] ."<br />"; } else { echo "Unavailable!<br />"; } echo "COOKIE[pword] = "; if (isset($_COOKIE['uid'])) { echo $_COOKIE['pword'] ."<br />"; } else { echo "Unavailable!<br />"; } ?> So the page SHOULD load with the logout command (/?a=logout), it should log out, and the reload the page. Which it does, but then the cookies log it right back in... unless those echoes are outputting data. So what are all the things I'm doing wrong here?
  12. My log in script loads in the background, called by JavaScript. I know JS can be disabled, but it's enabled in my testing environment so that's not the problem. Anyway, it checks for a connection and creates one if there is none. Then it executes the log in function and outputs a return value if one is needed (depends on how the script is being called). It checks for the value of $r (which was passed to the page through $_GET['rem_me'] when JS called this file. If $r is true, it sets 3 cookies; uid, email, and pword (which is stored as an MD5 hash of whatever the user entered into the password field). <?php if (!isset($con)) { require_once("../functions/dbc.php"); mysql_select_db($dbname, $con); $close_con = true; $print_output = true; } function login() { $e=$_GET["e"]; $p=$_GET["p"]; $r=$_GET["r"]; $sql="SELECT `uid`, `approved`, `email`, `username`, `ethnicity`, `country`, `region` FROM `users` WHERE `email` = '$e' AND `pword` = '$p'"; // echo 'Query: '. $sql .'<br />'; $result = mysql_query($sql) or die(mysql_error()); $user_data = mysql_fetch_array($result); if (!empty($user_data)) { // uid, approved, email, username, ethnicity, country, region if ($user_data['approved']) { session_start(); $_SESSION['uid'] = $user_data['uid']; $_SESSION['email'] = $user_data['email']; $_SESSION['username'] = $user_data['username']; $_SESSION['ethnicity'] = $user_data['ethnicity']; $_SESSION['country'] = $user_data['country']; $_SESSION['region'] = $user_data['region']; /* echo "<hr />SESSION:<br />"; foreach($_SESSION as $key => $value) { echo $key .": ". $value ."<br />"; } echo "<hr />"; */ } $sql = " UPDATE `users` SET `last_login` = NOW(), `last_ip` = '". $_SERVER['REMOTE_ADDR'] ."' WHERE `uid` = '". $_SESSION['uid'] ."' LIMIT 1"; $result = mysql_query($sql) or die(mysql_error()); if ($r == true) { setcookie("uid", $_SESSION['uid'], time() + (60*60*24*30), "/", ".virtuocracy.com"); setcookie("email", $e, time() + (60*60*24*30), "/", ".virtuocracy.com"); setcookie("pword", $p, time() + (60*60*24*30), "/", ".virtuocracy.com"); } return "true"; } else { return "no user"; } } $output = login(); /* if (!isset($print_output)) { echo "<hr />"; echo "email = ". $_GET["e"] ."; "; echo "pword = ". $_GET["p"] ."; "; echo "rem = ". $_GET["r"] ."; "; } */ if (isset($print_output)) echo $output; if (isset($close_con)) mysql_close($con); ?> This script is also called when the index page checks for those 3 cookies (which it only does when it finds no active session). As you can see, it also sets the GET variables so the function will work. <?php if (!isset($_SESSION['uid']) && (isset($_COOKIE['uid']) && isset($_COOKIE['email']) && isset($_COOKIE['pword']))) { $_GET["e"] = $_COOKIE['email']; $_GET["p"] = $_COOKIE['pword']; $_GET["r"] = false; require_once("functions/login.php"); } ?>
  13. The log in form uses a little JavaScript to make sure the fields have data, then it passes that data to my log in script. <form name="login" id="login" method="post"> <table border="0" style="font-size:14px;" align="CENTER"> <tr align="center"> <td colspan="2"> <input class="rounded" type="text" name="email" id="email" onfocus="checkField(this.name)" onblur="setField(this.name)" style="width:400px; font-size:24px; background-image:url('forms/images/big-email.png');background-repeat:no-repeat;" value="" /> </td> </tr> <tr align="center"> <td colspan="2"> <input class="rounded" type="password" name="pword" id="pword" onfocus="checkField(this.name)" onblur="setField(this.name)" style="width:400px; font-size:24px; background-image:url('forms/images/big-pword.png');background-repeat:no-repeat;" value="" /> </td> </tr> <tr align="left"> <td width="1px"> <img src="/forms/images/login-out.png" alt="submit" onmouseover="this.src='/forms/images/login-over.png';" onmouseout="this.src='forms/images/login-out.png';" onclick="submitForm()" /> </td> <td> <input type="checkbox" name="rem_me" id="rem_me" /> Remember Me<br /> <div style="font-size:10px; padding-left:4px"><a href="/?p=login&a=reset">Forgot your Log in Information?</a></div> </td> </tr> </table> </form> <script type="text/javascript"> <!-- // trim function function myTrim(stringToTrim) { return stringToTrim.replace(/^\s+|\s+$/g,""); } // #### ## ## ###### #### ## ## ###### ###### ###### ## ##### // ## # ## ## ## ## # ## ## ## ## ## ## ## ## // ## ###### #### ## #### #### ## #### ## ## ## // ## # ## ## ## ## # ## ## ## ## ## ## ## ## // #### ## ## ###### #### ## ## ## ###### ###### ###### ##### function checkField (field) { // alert("checkField("+ action +","+ field +")"); var myField = document.getElementById(field); // var myValue = myTrim(myField.value); // alert('myValue = '+ myValue); myField.style.backgroundImage = 'url("forms/images/big-default.png")' } // #### ###### ###### ###### ###### ###### ## ##### // ## ## ## ## ## ## ## ## ## // #### #### ## #### ## #### ## ## ## // ## ## ## ## ## ## ## ## ## // #### ###### ## ## ###### ###### ###### ##### function setField(field) { var myField = document.getElementById(field); var myValue = myTrim(myField.value); var myBackgroundImage = false; if (myValue == "") { myBackgroundImage = true; } myField.style.backgroundImage =(myBackgroundImage)? 'url("forms/images/big-'+ field +'.png")' : 'url("forms/images/big-default.png")'; } // #### ## ## ###### #### ## ## ###### #### ##### # # // ## # ## ## ## ## # ## ## ## ## ## ## ## ## ## // ## ###### #### ## #### #### ## ## ##### # ## # // ## # ## ## ## ## # ## ## ## ## ## ## ## # # // #### ## ## ###### #### ## ## ## #### ## ## # # function checkForm () { var fields = new Array("email","pword"); // alert("fields = "+ fields); for (var thisField in fields) { var thisValue = document.getElementById(fields[thisField]).value; // alert ("Checking "+ fields[thisField] +" ("+ thisValue +")"); if (thisValue == "") return false; } return true; } // SUBMIT FORM function submitForm () { var email = myTrim(document.getElementById("email").value); var pword = MD5(document.getElementById("pword").value); var rem = document.getElementById("rem_me").checked; if (checkForm()) { // alert("Execute Log in Script..."); // code for IE7+, Firefox, Chrome, Opera, Safari if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } // code for IE6, IE5 else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { // alert('xmlhttp.onreadystatechange! (readyState = '+ xmlhttp.readyState +'; xmlhttp.status = '+ xmlhttp.status +')'); if (xmlhttp.readyState==4 && xmlhttp.status==200) { // document.getElementById("txtHint").innerHTML=xmlhttp.responseText; var response = xmlhttp.responseText; // alert('login('+ email +', '+ pword +') responce = '+ xmlhttp.responseText); switch (response) { case "true": // document.forms["login"].submit(); window.location.reload(); break; case "no user": alert("Log in Failed! \n\nThe e-mail address and password you \nentered did not match our records."); break; case "unapproved": alert("Log in Failed! \n\nThat account is not yet approved."); break; default: alert("Log in Failed!\n\n"+ response); break; } } } $uri = "functions/login.php?e="+ email +"&p="+ pword +"&r="+ rem; xmlhttp.open("GET",$uri,true); xmlhttp.send(); } else { alert("Form incomplete or inaccurate!"); } } --> </script>
  14. What I'm trying to accomplish is your average session login w/ a cookie-based "remember me" feature. I can log in fine, I can set cookies, I can access those cookies, and I can use that data to log in just as if the user had logged in manually. The problem is logging out. But the bigger problem is figuring out why. You see, it works perfect. It logs in and it log out, so long as I am outputting data to the page. I was outputting a session variable and the cookies I set to make sure they were all working right; and they were. But then as soon as I disable those echoes, all of a sudden it won't log out anymore. So then I turn them on to see what the data says and BAM, I'm logged out. I log back in fine, I log back out fine, so I turn em off again. I log in fine. I can't log out. I try multiple times. I close my browser and open a new one. Still logged in. I try a few more times, still logged in. I turn the output back on, load the page again and I'm logged out. So... WTF? (my code to follow)
  15. It sounds like it's work great for what I need, though I am using it to compare foreign keys. Would this be ill-advised of me to do?
  16. That'll definitely work for comparison to sequential numerical values, thank you. I'm trying to wrap my head around IN... Am I correct in understanding that the IN operator will return the requested field only if it's value is found in the series of values given? such as this: SELECT `myField` IN (0, 1, 4, 5) Where if myField is 1, then it will return it, but if myField is 3, it wont? Or am I completely misunderstanding this?
  17. First, I don't need to search a set for a single value. I actually need to do the opposite. I'm filtering my query for a single field that has a single numerical value. This field references another table by it's primary key. table1: field = value -- references table2.id table2: id data basically, I want results when table1.field is not equal to certain values. Let's say for the ids 1-5, I only want results if the value is NOT 2 or 3. How would I do that without a bunch of where clauses (if possible)? This is how I'm doing it right now: SELECT `table1`.* FROM `table1`, `table2` WHERE `table2`.`id` != '2' OR `table2`.`id` != '3' and that works fine... unless I want to filter out like 50 values. Yes, I could do a loop, but I was hoping there was a simpler way.
  18. Still haven't figured it out, but I found a better method to the same ends. check out addDomLoadEvent: http://www.thefutureoftheweb.com/blog/adddomloadevent Works cross browser and everything.
  19. I've looked at a lot of tutorials for this and they say a few different things, but I've tried them all with no luck. I have a function working that toggles the display of a div element on and off. Now what I'm trying to do is create a function that will collapse a series of specific div elements as soon as the page loads; I don't want them to be collapsed if javascript is off, which is why I'm collapsing it with more script rather than just setting the display to none. here's what I got so far: <script type="text/javascript"> <!-- function switchMenu(objID) { var divElement = document.getElementById(objID); divElement.style.display = (divElement.style.display != 'none')? 'none' : 'block'; } /* thought maybe it was this function, so I tried a more direct approach function switchMulti(array) { for (var i = 0; i < array.length; i++) { switchMenu(array[i]); } } */ function pageLoad() { switchMenu('Section 1'); switchMenu('Section 2'); switchMenu('Section 3'); switchMenu('Section 4'); } // tried onLoad="pageLoad();" inside the body tag, no luck // addEvent(window, load, pageLoad); window.onload = pageLoad; --> </script> They all work individually, just not all at once on the page load. Anyone got any ideas?
  20. I still can't figure out how this works and I can't seem to find anything online where it's being used the way I'm using it in any way that I can decompose and assimilate
  21. first of all, if your scripts wasn't spitting out an error message, add <? error_reporting(E_ALL); ?> to the very top of the file. Moving on, I took a look at your php and changed a few things, all of which I commented on: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="generator" content="HTML Tidy for Linux (vers 6 November 2007), see www.w3.org" /> <title>User Check</title> <style type="text/css"> /*<![CDATA[*/ span.c1 {color: green} /*]]>*/ </style> <?php // set this to false once your code it working $debug = true; // prototype the message variable so it will be accessible outside of your statements and loops $message = ""; // this is unnecessary // $user = $_POST['user']; // just test the post variable if (isset($_POST['user'])) { // if this activates, there WILL be a message, one way or another // so make this the default message unless an error is tripped later on $message = "<span class=c1>This User Exists and/or has not Been Suspended/Deleted</span>"; $url = 'http://vampirefreaks.com/profile.php?user='; $user = $_POST['user']; $file = file("$url$user"); foreach ($file as $lines) { $line = strip_tags($lines); $line = trim("$line"); if (!empty($line)) { // if the line is NOT empty $line = preg_replace('/\s+/', ' ', $line); $line = preg_replace('/\s+$/', ' ', $line); // if the debug variable is set to true, print the line variable // this is done so you can see exactly what this data looks like if ($debug) echo "<hr />Debug:<br>line = $line<hr />"; // instead of using a whole bunch of if,then statements, // you can check for a few exceptions, then analyze the rest for a default message // first, check for some preliminary states if ($line == 'This User Has Been Suspended') { // if the user has been suspended... $by = $reason = next($file); $reason = next($file); $message = "<font color=red>$user Has Been Suspended By VF Admin For:$by$reason</font>"; } else if ($line == 'THIS USER DOES NOT EXIST' || $line == 'Error Retreiving user info') { // else, if the user has NOT been suspended, but if the user does not exist... $message = "<font color=red><b>This user is dead!</b></font>"; } else { // else, if the user has NOT been suspended, and the user DOES exist... /** * rather than checking through every possible reason that can be given, * we'll break the line into two parts: * 'THIS USER HAS BEEN DELETED BY VF ADMIN Reason for Deletion' * and the reason for deletion * * to do this, we'll use a split() operation, the syntax being $array = split("delimiter", $string); * specifically, we'll be splitting the string at the colon ( */ $lineArray = split(":", $line); /** * now, this line could have been a whole bunch of different things since you're pulling data from the web page * but if it IS what we want, then the first index of the array will be: * 'THIS USER HAS BEEN DELETED BY VF ADMIN Reason for Deletion' */ if ($lineArray[0] == 'THIS USER HAS BEEN DELETED BY VF ADMIN Reason for Deletion') { // if this is the line we want, we'll reassemble the line, adding the colon back in between the message and reason $message = "<font color=red>$lineArray[0]:$lineArray[1] ($user)</font>"; } } } } // if the debug variable is set to true, print the message variable // this is done so you can see 1) if there is a message, and 2) what it says if ($debug) echo "<hr />Debug:<br>message = $message<hr />"; } // you were missing this final close bracket ?> <body> <?php // I moved this stuff down here to keep all of the HTML output in one place if (!empty($message)) { // if the message is NOT empty // note: I added the text coloring to the messages above echo "$message"; } else { // else, if it is, print some general instructions echo "Enter a User Name:"; } ?> <!-- since you're printing this regardless of the message... //--> <form method="post"> <input type="text" name="user"> <input type="submit" name="submit" value="Assimilate!"> </form> </body> </html>
  22. I'm looking at the code you've pasted but I need a little more info to narrow it down. 1) What is it supposed to be doing? 2) What it is actually doing?
  23. It seems to be loading for me; this may be a browser compatibility issue. What browser are you using? Also, I can't seem to open your attachment on my system; it is a large file?
×
×
  • 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.