Jump to content

davidp

Members
  • Posts

    25
  • Joined

  • Last visited

    Never

Everything posted by davidp

  1. Hey all, I am having a situation where I have a singleton class with a static array in it. I insert an element into that array, and then I redirect the user to another page. At that page, I then retrieve that array (it's stored in the session vars), but the array is then empty when I retrieve it. I can't figure out why. Here are some pertinent code snippets. First, the class with the static array: class Logger { private static $instance = NULL; private static $messages = array(); //Private constructor to prevent this class from being instantiated multiple times private function __construct() { } //The clone function is private to prevent cloning of this class private function __clone() { } //Returns the singleton instance of this class public static function GetInstance() { if (!self::$instance) { self::$instance = new Logger; } return self::$instance; } public static function GetMessageCount() { return count(self::$messages); } public static function LogMessage($new_message) { self::$messages[] = $new_message; } public static function GetMessages() { return self::$messages; } public static function ClearMessages() { self::$messages = array(); } } Here is the code where I insert something into the aformentioned array (the process is that a user tries to log in, but the login fails, and so we insert a message into the array saying that the login credentials failed). //Retrieve the message logging instance from the session data to be able to pass messages to the user. $message_log = $_SESSION['user_messages']; $user = $_SESSION['user_account']; //Create a new instance of the database management class and //try to connect to the database $dbm = new DBM(); if ( !$dbm->isConnected() ) { $message_log::LogMessage("We are sorry, but we are unable to access the database at this time. Please try again later."); } else { //Retrieve the user login information $useremail_dirty = $_POST['useremail']; $password_dirty = $_POST['userpassword']; //Check to see if the email we were given exists in the database, and if the password matches $doesPasswordMatch = $dbm->doesPasswordMatch ( $useremail_dirty, $password_dirty ); if ( $doesPasswordMatch ) { //Correct login information was received. Login the user and redirect appropriately. $user->Login(); header ( "Location: ".BASE_URL."/userpage.php" ); exit; } else { //If an incorrect email or password was given, report that information to the user. $message_log::LogMessage("Incorrect login information."); } } //The user has failed to login. Redirect to the appropriate page. header ( "Location: ".BASE_URL."/loginfailed.php" ); And finally, given an unsuccessful login attempt, this is where I pick back up the array of messages to display the messages to the user: $message_log = $_SESSION['user_messages']; $all_messages = $message_log::GetMessages(); print $message_log::GetMessageCount()."<br>"; print count($all_messages)."<br>"; foreach ($all_messages as $message_string) { $prepared_string = prepare_text_for_html_output($message_string); echo $prepared_string."<br>"; } $message_log::ClearMessages(); Unfortunately, the "all_messages" variable has nothing in it...it's like the messages that I logged in the previous PHP script never even existed. I am calling session_start, so don't worry about that (even though it's not seen in these code snippets). What could be going wrong?
  2. Okay, so this problem will seem a little convoluted at first, so try and keep up I am running a PHP script which is doing some updating to our SQL database. Every so often this PHP script will output its status, and all-in-all it takes about 1 hour for this script to finish the work that it is does. We have a test server and a production server. When I run this particular script on our test server, it will run perfectly for about 45 minutes, and then suddenly it will give me an error stating: "Fatal error: Maximum execution time of 30 seconds exceeded in importusers.php on line 235" First of all, I didn't know that there was a maximum execution time for PHP scripts to run. Second of all, why would it give me this error saying that it had exceeded the 30 second limit if it is already 45 minutes into the process? It doesn't make much sense to me. Anyways, I ran phpinfo() and checked where the php.ini file that it references is. It is in the "/etc/" directory. I went there and edited the max_execution_time variable to be 300. I then restarted the server and ran phpinfo() again. But according to phpinfo() the max_execution_time is still 30 seconds! How can that be? I know I edited the correct php.ini file, and I have it open in front of me right now. It says 300 seconds. How could the php.ini file and phpinfo() disagree? Anyways, all of that is just the problems I am having on the test server. Now we come to the production server: Whenever I run this same script on the production server, I simply don't get any output. If you remember, I said that the script outputs its status every once in awhile so that I know how things are going. Well, running it on the production server it simply doesn't give me any output at all! However, when I place random "exit" statements throughout the PHP script to see what is going on, it will output stuff as it exits. Why is it doing this? How can I get it to do the output on the fly on the production server? (I am calling flush() after every echo and print statement.) So, all in all, I need to somehow fix this 30 second issue on the test server (and possibly on the production server...I can't tell because there is no output) and the output on the production server. Any advice?
  3. I am using the "mhash" function in some of my PHP scripts, although when I tried to run the script I realized that I didn't have the mhash library installed. It screamed at me saying the function was not found. So I went to the sourceforge site for mhash, downloaded it, and installed it. It said that it installed successfully, but for some reason the "mhash" function still can't be found by PHP. I am using Mac OS X. Any thoughts on what the problem could be?
  4. Wow...this is a pretty mind boggling bug I am having. I am using the socket API in PHP to connect to a server called GeoNames and retrieve some information. I formulate my request as such: //Now we start to set up our sockets. We will be using port 80, and we specify the host and the path we want. $service_port = 80; $address = gethostbyname('ws.geonames.org'); $path = '/countrycodeJSON?lat='.$lat.'&lng='.$lon; //$path = '/findNearbyPlaceNameJSON?lat='.$lat.'&lng='.$lon; //Create a socket for us to use $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if ($socket === false) { echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n"; } //Connect to the host $result = socket_connect($socket, $address, $service_port); if ($result === false) { echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n"; } //Now that we have a socket connected to the host, we need to form our HTTP request. $in = "GET ".$path." HTTP/1.1\r\n"; $in .= "Accept: */*\r\n"; $in .= "Host: ws.geonames.org\r\n"; $in .= "\r\n"; $out = ''; //Now we send our HTTP request to the host socket_write($socket, $in, strlen($in)); It is pretty simple socket code that anybody familiar with sockets should understand. Here is the fun part: when I run this same PHP script on my own computer, and then run it again on a different machine in the Computer Science labs on campus at my university, I get two different responses from the GeoNames server. Let me explain how I retrieve the response. I wrote this code to retrieve the response initially: //Now we read a reply while ($out = socket_read($socket, 2048)) { $out = trim ( $out ); $len = strlen ( $out ); if ( $out[$len - 1] == '0' ) break; } Running this code on my machine, I get a response from the GeoNames server formatted like this: As you can see, there is no "Content-Length" header. I figured out however, that the "25" contained right at the beginning of the content is actually the hexidecimal representation of the number of bytes contained in the content. That, then, is essentially this other server's way of telling me the content length. Then the "0" tells me when I have reached the end of the response. So...that is what happens on my own computer when I run this PHP script. Now, I also coded up a 2nd way of receiving the response from the GeoNames server that is much more C/C++ in style. Here it is: $bytesReceived = -1; $httpResponse = ""; $responseMessage = ""; while ( $bytesReceived != 0 ) { $httpResponse = ""; $bytesReceived = socket_recv ( $socket, $httpResponse, 2048, 0 ); $responseMessage .= $httpResponse; } This is how I normally handle responses using the socket API in C/C++, so I wanted to try it in PHP. Unfortunately, when I tested this on my own machine, it entered an infinite loop. Soooo.... I then transferred my PHP script to a machine on campus in our CS labs, and I ran it there (using method 1 of retrieving a response from the GeoNames server). Doing this...it crashed. Well, it didn't crash, but I simply didn't receive ANY response from the GeoNames server. The response came back blank. I decided to implement method 2 of retrieving a response (the C/C++ way of doing things), and I tested that way on that machine. I got a response perfectly! (No infinite loop occurred like had happened on my machine). However....the response is different than the response I receive on my own machine. Here is the response I get when I run the script on the CS lab machine: As you can see, for some reason the connection has been downgraded from HTTP/1.1 to HTTP/1.0. Also, there is still no "Content-Length" header, and the number contained at the beginning of the content that acted as a content-length identifier does not exist anymore! And there is no "0" to signal the end of the response like there was when I ran it on my own machine! So my question is: How can the two HTTP responses be so different? Is it a factor of the differences in my PHP code when I retrieve the responses? Why does the C/C++ style of doing things enter an infinite loop on my own machine, but work perfectly on another machine? And vise-versa for the first method I used of retrieving a response? I don't understand exactly what is going wrong here.
  5. I am developing a mapping tool where the user is able to click on a country, and when the user does so, I will dynamically bring up an RSS feed associated with that country. Well, the problem is simple: AJAX doesn't allow cross-server requests. Solution 1: I could write a PHP script on my own server. The PHP script would have to accept a GET or POST variable containing the URL of the RSS feed that I want to load. I can then use the sockets API to open up a socket in my PHP script, make the request, wait for a response, and then send the response back from my PHP script to the client. That is a round-about way of doing things, but it will work. The thing is...I don't want to have to do that. That just doesn't seem like the most elegant way of doing things. How would any other web page dynamically load RSS feeds contained on any arbitrary server? Anyone have any ideas?
  6. haha. Don't worry I am going in that direction, but not at least for another 2 years Once my laptop gets outdated I will get a Mac because I love Macs
  7. So something just suddenly came up on my computer....completely out of the blue. I'm not sure how it happened, but it seems like the most likely option is a virus. I keep my computer very clean and protected, so off the top of my head I don't know how it happened, especially because it just suddenly hit really quickly. My computer has been working completely fine with no problems up until about 15 minutes ago...when suddenly everything just went down. I came back from the grocery store and tried to open up Firefox, when I was presented with an error message telling me that Firefox had to close. I assumed that it must just be something that had happened to Firefox, and so I tried to open Safari. Safari crashed too. I then tried to open Windows Messenger, but it crashed. My virus scanner was already open sitting in my tray at the bottom of the screen, so I brought it up and started a scan. I tried opening up AdAware, and was successful, but it was not able to connect to the internet and get an update. I then started a scan...it failed in its scan about 1 minute into it and just hung. I tried opening up Spybot but it crashed. Internet Explorer successfully opened, but I wasn't able to connect to any websites. I then tried opening up Putty and WinSCP. WinSCP crashed. Putty opened but couldn't connect to anything. After all this my virus scanner still had not found anything. I wanted to see my list of running processes, so I pressed CTRL+ALT+DEL, but even it failed to open, bringing up an error message. I immediately opened up Cygwin, but it failed whenever it tried to "fork" any processes....thus not allowing me to run anything from Cygwin. I opened up Windows PowerShell and ran "ps" to see my list of running processes. I didn't see anything suspicious. "ps" succeeded on the first run, but my next attempt failed with another error message. After this I immediately disconnected my internet connection from my wireless router, and then plugged myself directly into the wall jack. I ran "cmd" and tried "ipconfig /renew" (I was hoping I could try and access the internet with IE which was still open), but ipconfig failed and brought up an error message. Most of the error messages that came up were all "memory access" errors. Some of them had to do with the inability to create a socket (Putty) or fork a process (Cygwin). One particular one gave me some useful information to go by: it said that "hhctrl.dll" and "psapi.dll" were not valid Windows images. sooooo....after all of this I decided to stop my virus scanner which still hadn't found anything and I booted up using an Ubuntu DVD...which is what I am in right now. It appears that PSAPI.dll is a very important dll file in Windows used for starting up processes. How this file could have been compromised is beyond me... Has anyone ever had similar problems? Anyone have any suggestions? I am wondering what will happen if I try to boot up back in to Windows. I am going to back up all my important data onto my external hard drive before I do that, however.
  8. Nevermind I got it Had to use absolute positions instead of fixed positions.
  9. I have an HTML page using CSS, and the content of the page is of moderate length....but no scroll bar appears in the browser to scroll the content at all. I have attached a screen shot, so take a look at that. Now, of course to really know what's going on, you need to see the relevant CSS, so here it is. The HTML file itself is quite short, so I will post it in its entirety (minus the country links which take up the length of the page): <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html> <head> <title>Exploring Borders Admin</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link rel="stylesheet" href="http://localhost/borders/style/layout_admin.css" type="text/css"> </head> <body> <b> <div style="font-size: 16pt;">Admin Access Page</div> </b> <br> <div style="width: 800px; height: auto;"> <div style="position: fixed; left: 10px; top: 50px; width: 800px; height: 75px; text-align: left;"> You are logged in as an administrator.<br> <a href="adminlogout.php?action=logout" class="header">Click here to log out</a> <br><br> </div> <div class="admincontrol" style="position: fixed; top: 100px; left: 10px; height: auto;"> Administrator Options: <br><br> <a href="index.php" class="sidebar">Main</a><br> <a href="index.php?action=viewusers" class="sidebar">View Users</a><br> <a href="index.php?action=viewadmins" class="sidebar">View Administrators</a><br> <a href="index.php?action=viewcountries" class="sidebar">View Country Info</a><br> <br> </div> <div style="position: fixed; left: 250px; top: 100px; height: auto; overflow: auto;"> ... all the country links... </div> </div> </body> </html> Now here is the only other relevant piece of CSS contained in the linked CSS file (all other CSS classes in the linked CSS file are specific for "a" tags): div.admincontrol { border-style: solid; border-color: #00285C; background-color: #EBEBEB; width: 200px; text-align: left; padding-left: 1ex; padding-top: 1ex } Given that information...does anybody know why no scroll bar appears on the right side of the browser to let me scroll down the page of country links? [attachment deleted by admin]
  10. The post variables are not being lost...that's just what I thought was happening at first. It turns out the post variables are fine, but the session data is being lost. In terms of cookies: No, my browser accepts cookies. I always have cookies turned on. I am also testing this on three different browsers (IE, Safari, Firefox) and the same error happens on all 3 of them. The error is simply: The reason I am getting this error is obvious to me....the "Admin" object which I created in the session data during the execution of index.php is lost...it's gone. It doesn't exist anymore. I am wondering why. Like I said...it can't be cookies. I am using 3 browsers and they all accept cookies. Second, sessions are serverside anyways, not client-side.
  11. I have found out a few more specifics that might help in finding a response to the problem. Here is the jist of it all: It looks like I am losing my session data inbetween page changes/redirects. The PHP error occurs on the line of: $_SESSION['admin_account']->Login( $userName ); Notice that that line is the first time I reference any member of $_SESSION['admin_account'] which should be an "Admin" object. You might say, "Well before you reference the session variable, use an if statement to check and make sure it exists." I did this at first, and I tried creating a new "Admin" object at that point if no "Admin" object existed already.....but when that happened, the redirect to "ADMIN_BASE_URL" (index.php) would just take me back to the login form again (because the session data was once again being lost in the redirect). The interesting thing is that as I have monitored my HTTP requests that are being sent back and forth, I am getting a new PHP session ID everytime I get a response back from the server. Why is it giving me a new session ID every single time??? This same thing is happening on my own personal server and on my school's CS server. It's weird. Here is the code in which I do session_start(): session_set_cookie_params ( 0, SESSION_ADMIN_PATH, SESSION_DOMAIN ); session_start(); $_SESSION['dumb'] = rand(1, 10); Do you see any problems with that?
  12. Something odd is happening with my script. The really weird thing is that sometimes it will work (but only for Firefox), while most of the time it won't....but it's not a 100% failure rate (except for browsers other than Firefox). It's just really weird. Anyways, posted below is my index.php file, which is quite short and easy to understand. Here is a basic synopsis of it: I load a PHP file containing some global variables. I load my DBM and Admin classes. I require require a file which is supposed to do all handling of SSL connections, but for right now all it does is a session_start(). After that I load a file containing some general functions for admin usage. I then create the DBM, make sure the admin account is created, and then display the admin login form or the admin page depending on whether the admin is logged in or not. <? require_once ( "../../site_support/globals.php" ); require_once ( "../../site_support/classes/dbm.php" ); require_once ( "../../site_support/classes/admin.php" ); require_once ( "secure.php" ); require_once ( "adminfunctions.php" ); //Connect to the database global $dbm; $dbm = new DBM(); // Check if the database is available. if (!$dbm->isConnected()) { print 'Unable to access the database at this time.<p>Sorry for the inconvenience.'; exit; } if ( !isset($_SESSION['admin_account']) ) $_SESSION['admin_account'] = new Admin(); print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html> <head> <title>Exploring Borders Admin</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link rel="stylesheet" href="'.BASE_URL.'style/layout_admin.css" type="text/css"> </head> <body> <b><div style="font-size: 16pt;">Admin Access Page</div></b><br>'; if ( !$_SESSION['admin_account']->isLoggedIn() ) { $_SESSION['admin_account']->displayLoginForm(); } else { displayAdminPage(); } print '</body></html>'; ?> Now here is my problem. When the login form is displayed, and the user types in his/her information, and clicks "Submit", I redirect to "adminlogin.php". Once that happens, all the session data and the POST data gets lost. Here is a copy of the login form that gets displayed: function displayLoginForm ( ) { print '<form action="'.BASE_URL.'admin/adminlogin.php" method="POST"> User Name:<br> <input type="text" name="username"><br> Password:<br> <input type="password" name="password"><br> <input type="submit" value="Submit"><br> </form>'; } And here is the code that handles the POST data in "adminlogin.php": <? require_once ( "../../site_support/globals.php" ); require_once ( "../../site_support/classes/admin.php" ); require_once ( "../../site_support/classes/dbm.php" ); require_once ( "secure.php" ); $dbm = new DBM ( ); if ( !$dbm->isConnected() ) { print 'Unable to access the database. Try again later.'; return; } $userName = $_POST['username']; $password = $_POST['password']; $md5RevPass = strrev ( md5 ( $password ) ); $result = $dbm->CheckAdminLogin ( $userName, $md5RevPass ); if ( sqlite_num_rows($result) == 0 ) { print 'Invalid name and password!<br>'; } else { $_SESSION['admin_account']->Login( $userName ); header ( "Location: ".ADMIN_BASE_URL ); } ?> Well, that's everything. I can't understand why my session variables are being lost (session_start() is being called. I tried removing the require_once('secure.php') lines, and instead I put session_start() inline in the code I posted above, but I just got the same results as I am getting now. And where is my POST information going? I am not using SSL...Although I wanted to, I have cut out all SSL code until I can get these errors resolved.
  13. I am having a problem accessing my dbm from my PHP script. Basically, the user comes to the page, and logs in. After logging in, the user can browse certain things on the page. Here is the code for index.php, which is quite short so don't worry: require_once ( "../../site_support/classes/admin.php" ); require_once ( "../../site_support/globals.php" ); require_once ( "secure.php" ); require_once ( "adminfunctions.php" ); require_once ( "../../site_support/classes/dbm.php" ); //Connect to the database global $dbm; $dbm = new DBM(); // Check if the database is available. if (!$dbm->isConnected()) { print 'Unable to access the database at this time.<p>Sorry for the inconvenience.'; exit; } if ( !isset($_SESSION['admin_account']) ) $_SESSION['admin_account'] = new Admin(); print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html> <head> <title>Exploring Borders Admin</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link rel="stylesheet" href="'.BASE_URL.'style/layout_admin.css" type="text/css"> </head> <body> <b><div style="font-size: 16pt;">Admin Access Page</div></b><br>'; if ( !$_SESSION['admin_account']->isLoggedIn() ) { $_SESSION['admin_account']->displayLoginForm(); } else displayAdminPage(); print '</body></html>'; ?> Now, in this part of the code I am able to connect to the SQLite database completely fine. This is evident in the fact that the code doesn't throw up the error message that I inserted in there, and logging in/logging out works perfectly. The problem is when I call the function displayAdminPage which is contained at the bottom of the code snippet that I just posted. displayAdminPage is located in "adminfunctions.php". Here is the body of that function: //This is the main function of the "adminfunctions". It calls the other display functions. function displayAdminPage ( ) { print '<div style="width: 800px;">'; displayAdminHeader(); displayAdminSideBar(); displayMainContent(); print '</div>'; } Inside my displayMainContent() function, I do this: if ( isset ($dbm) ) print "dbm is set."; else print "dbm is not set."; Now here is where the problem lies, the DBM is not set anymore. Once I start calling functions from adminfunctions.php, the DBM becomes undefined....but that I don't understand. I am making the function call from a place where the DBM is defined, so shouldn't it still be defined inside of the function itself? Anyone have a suggestion on how I can fix the problem?
  14. I am building a web site that requires users to log in, and I would like to use SSL to that it is secure (of course...it makes sense that one would want to do that). Well, my test server is my own computer running WAMP (with Apache 2.2.6 and PHP 5.2.5). My "production server" (which is actually a server on my university campus) is running Apache 2.0 and PHP 4.3.9. Consequently I am coding all my PHP code to be compliant with PHP 4 since my production server is running PHP 4. Anyways, my problem is that for some reason on my computer (the test server) I cannot create an SSL connection. When I run the code on the production server, however, the secure connection is made successfully with no problems at all. So when I try to create an SSL connection to my test server, I get the following error from my web browser: I am confused as to why the SSL connection isn't being created properly when I have Apache installed with OpenSSL properly installed and enabled. Any ideas? If you need any more info I can provide it.
  15. thanks treenode and wildteen. i wasn't aware of those small differences between single-quoted strings and double-quoted strings. that helps a lot.
  16. This is kind of a simple bug, but I'm not sure why it's happening. Here is a code snippet: function DisplaySideBar ( $pageNumber ) { $SideBarBeginning = "<h3>Sections:</h3><p>"; $SideBarEnding = "</p><br><br>"; print $SideBarBeginning; switch ( $pageNumber ) { case 0: print '<a class="sidelink" href="http://www.lds.org">LDS Church</a><span class="hide"> | </span>\n'; print '<a class="sidelink" href="http://www.byu.edu">BYU</a><span class="hide"> | </span>'; print '<a class="sidelink" href="http://validator.w3.org/check/referer">Valid XHTML</a><span class="hide"> | </span>'; print '<a class="sidelink" href="http://jigsaw.w3.org/css-validator/check/referer">Valid CSS</a>'; break; case 1: print '<p><a class="sidelink" href="index.php?page=1&section=0">Projects</a><span class="hide"> | </span>'; print '<a class="sidelink" href="index.php?page=1&section=1">Source Code</a><span class="hide"> | </span>'; print '<a class="sidelink" href="index.php?page=1&section=2">Contest Problems</a><span class="hide"> | </span>'; print '<a class="sidelink" href="index.php?page=1&section=3">Tutorials</a><span class="hide"> | </span>'; print '<a class="sidelink" href="index.php?page=1&section=4">Programming Links</a></p>'; break; case 2: break; case 3: break; case 4: break; case 5: break; } print $SideBarEnding; } You will notice that after the first "print" statement inside of the switch block, I am printing a \n newline. I do this because I want there to be a newline in the source file sent to the client's browser, but of course not a newline in the HTML itself (or else I would have used an HTML "br" tag). Anyways...for some reason the characters "\n" are actualling being printed onto the HTML page and displayed in the browser. I tried using printf, but it didn't work either. How can I fix that?
  17. I downloaded Fiddler, which is a program that watches your HTTP requests that you send. Here is the HTTP request that is being sent when I click submit: POST /~dpru/musicstore/site/transition.php?action=login HTTP/1.1 Accept: */* Referer: http://students.cs.byu.edu/~dpru/musicstore/site/ Accept-Language: en-us Content-Type: application/x-www-form-urlencoded UA-CPU: x86 Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0; .NET CLR 2.0.50727; FDM) Proxy-Connection: Keep-Alive Content-Length: 33 Host: students.cs.byu.edu Pragma: no-cache Cookie: PHPSESSID=c394148909541df0b83ad1a707bb03dc userid=test&userpassword=testcase The request is perfectly fine. It is a POST request, and it contains the post data. Nothing is missing. I thought maybe the server doesn't like receiving post requests, but it receives my other post requests from other forms perfectly fine....so that cannot be the problem. That leaves the only problem lying in my PHP code. Whats wrong? I'm going to go ahead and post a larger amount of the PHP code...maybe it could shed some light: require_once ("../classes/account.php"); require_once ("globals.php"); require_once ( "secure.php" ); require_once ("../db/dbm.php"); if ( !isset($_SESSION['dp_account']) ) { header ( "Location: ".BASE_URL ); } if ( isset( $_GET['action'] ) ) { /*************************************** The Login Script ***************************************/ if ( $_GET['action'] == "login" ) { //Check the username and password $userName = ""; $password = ""; print $_POST['userid']."<br>"; if ( isset( $_POST['userid'] ) ) $userName = $_POST['userid']; if ( isset( $_POST['userpassword'] ) ) $password = $_POST['userpassword']; print "Username: ".$userName."<br>Password: ".$password."<br>"; //Connect to the database $dbm = new DBM ( ); if ( !$dbm->isConnected() ) { print 'Sorry, we are unable to connect to the database at this time.<br>'; //print '<a href="'.BASE_URL.'">Main Site</a>'; } //Check to see if the login is valid if ( $dbm->isValidLogin($userName, $password) ) { $_SESSION['dp_account']->login($userName); print 'You successfully logged in!'; } else { print 'Invalid Login!'; $_SESSION['dp_account']->logout(); } //header ( "Location: ".BASE_URL ); } /*************************************** The Logout Script ***************************************/ if ( $_GET['action'] == "logout" ) { $_SESSION['dp_account']->logout(); if ( isset ( $_SERVER['HTTP_REFERER'] ) ) { header ( "Location: ".$_SERVER['HTTP_REFERER'] ); } else { header ( "Location: ".BASE_URL ); } exit; } /*************************************** The New Account Script ***************************************/ if ( $_GET['action'] == "newaccount" ) { //Connect to the database global $dbm; $dbm = new DBM ( ); if ( !$dbm->isConnected() ) { print 'Sorry, but your account could not be created because a connection with the database has failed.'; exit; } //Process the new account $userData['FirstName'] = $_POST['FirstName']; $userData['LastName'] = $_POST['LastName']; $userData['UserName'] = $_POST['UserName']; $userData['Email'] = $_POST['Email']; $userData['Password'] = $_POST['Password1']; $userData['Country'] = $_POST['Country']; $userData['Password2'] = $_POST['Password2']; $userData['Validate'] = $_POST['Validate']; print $_POST['FirstName']; print $_POST['LastName']; print $_POST['UserName']; print $_POST['Email']; print $_POST['Password1']; print $_POST['Country']; print '<br>'; $fileName = $_GET['fileName']; if ( !$dbm->isValidImageValidation($fileName, $userData['Validate']) ) { print 'The text you entered into the image validation field was wrong!<br>'; return; } if ( $dbm->UserExists( $userData['UserName'] ) ) { print 'That username already exists!'; return; } if ( strcmp($userData['Password'], $userData['Password2']) == 0 && (strlen($userData['Password']) >= 6) ) { $dbm->insertUser ( $userData['FirstName'], $userData['LastName'], $userData['Email'], $userData['UserName'], $userData['Password'], $userData['Country'] ); print 'Your account has been successfully created'; } else print 'Password does not match!'; } } Thanks for any help yall can give me here.
  18. yeah i left out that last curly bracket just because there is more code after that....the if statement doesn't end there...i just posted the important part. That is really odd. Here is another strange thing. Let's say that I test one of my other forms that is functioning properly, for example. If I use that form...and submit data...and then I try a refresh, the message box comes up telling me "Are you sure you want to resubmit POSTDATA?"...which is of course what should happen. When I do that for that specific form, however, no message box comes up like that. It is almost as if it is not even recognizing the fact that I told it to use the post method. Why would that happen? It's really strange. If you want to test it for yourselves, it is the login form at the following site: http://students.cs.byu.edu/~dpru/musicstore/site/ You can try logging in using these fields for data: username: test password: testcase
  19. For some reason my PHP script is not catching the post variables that should be being sent by this form. I have been looking at it for awhile now, and I cannot find any bug. Maybe one of you could help? This is the code that is supposed to catch the post variables: if ( $_GET['action'] == "login" ) { //Check the username and password $userName = ""; $password = ""; if ( isset( $_POST['userid'] ) ) $userName = $_POST['userid']; if ( isset( $_POST['userpassword'] ) ) $password = $_POST['userpassword']; print "Username: ".$userName."<br>Password: ".$password."<br>"; This is the form itself (if HTML formats properly on this board...I guess I will find out when I post this): <form action="../site/transition.php?action=login" method="POST"> dPru ID:<br> <input type="text" name="userid"><br> Password:<br> <input type="password" name="userpassword"><br> <input type="submit" value="Log In"> </form> <a href="../site/index.php?action=newaccount">Create Account</a> All the names of the fields match up with what I call them in the PHP script. I know that the PHP script is being run, because I have output going on, so I know that it is not being skipped over. Other forms that I have on the site that are similar to this one work fine...so I don't understand why this won't work! Thanks for any help on this bug.
  20. I am receiving a problem with my session variables in PHP. In essence, PHP thinks that I am trying to use a session variable before it is created. Here is the error itself: Here is my code, in a bit cut-down form: secure.php ...some code at the beginning, doesnt have to do with sessions.... session_set_cookie_params ( 0, SESSION_PATH, SESSION_DOMAIN ); session_start(); $_SESSION['dumb'] = rand(1, 10); ...a little bit more code follows, but none of it has to do with sessions.... index.php: //Files that need to be included require_once ( "globals.php" ); require_once ( "secure.php" ); require_once ( "functions.php" ); //The DBM require_once ( "../db/dbm.php" ); //Classes to include require_once ( "../classes/account.php" ); //Connect to the database global $dbm; $dbm = new DBM(); // Check if the database is available. if (!$dbm->isConnected()) { print 'Unable to access the database at this time.<p>Sorry for the inconvenience.'; exit; } else print 'Connected!'; if ( !isset($_SESSION['dp_account']) ) $_SESSION['dp_account'] = new Account(); ?> ...some HTML.... <? $_SESSION['dp_account']->displayLoginForm(); ?> ...more stuff The error occurs on that last line where I do displayLoginForm(). To me it looks like I am starting the session, setting the session variables appropriately, and then using them...but obviously I must not be doing so....anyone see an error in my code?
  21. If you want to sort through about 50 php files all experiencing the same problem, be my guest
  22. I have done some more research since posting that first post, and I have found some interesting things. By reading a thread on phpbuilder, I discovered that most people receive this thread because of their carelessness and they leave out curly brackets. This cant be our problem, however. We have been using this code faithfully for a long time now, and have received no such errors in the past...surely those would have already been caught since our code has been running on production servers for quite a long time. The other case where people seem to be receiving this error (a bit less common) is in their php configuration (php.ini file), the short_open_tags flag is not turned on. In other words, the server is set to not be able to recognize short open tags, or <? tags. But only <?php tags. I decided that this could possibly be our problem, and so I checked out the php.ini file, only to find that short_open_tags was set to the value "On"...so they should be allowed perfectly fine. After toying around with the code...I place "<?php" tags in place of all "<?" tags...and suddenly things worked...which is odd considering that short_open_tags was enabled. With that in mind...if I make a very simple php file: <? print 'Hi!'; ?> with short open tags...it works... So I know the problem seems to be with short open tags....but I cannot pinpoint it exactly. Under that new light and knowledge...any advice?
  23. Here at work we just updated to PHP 5.2.1 on our test server. Testing out the web page on there, for some reason the PHP scripts are all breaking. We are getting errors sent back to us from PHP saying it has found an "unexpected $end". Depending on the file it could occur at the very end of the file, or even in the middle of the file. Not sure exactly what is causing this problem. Anyone had this same problem after upgrading to 5.2.1?
  24. ah thats true thanks. yeah the server is running 4.3.9. i am used to working on a server running 5.x. Thanks!
  25. I am receiving what looks to be like a relatively simple syntax error, but I am at a loss for exactly WHY I am receiving it, because the syntax looks correct to me. Here is my code. It is fairly short: <? /******************************** dbm.php Author: David Pruitt Purpose: This file handles connections to the database for the music store. ********************************/ class DBM { private $connected; function __construct ( ) { $server = "Edited out for security"; $db = "Edited out for security"; $username = "Edited out for security"; $password = "Edited out for security"; $this->connected = false; if (mysql_connect($server, $username, $password)) { if (mysql_select_db($db)) { $this->connected=true; } } } function isConnected ( ) { return $this->connected; } } global $dbm; $dbm = new DBM(); // Check if the database is available. if (!$dbm->isConnected()) { print 'Unable to access the Speeches database at this time.<p>Sorry for the inconvenience.'; exit; } else print 'Connected!'; ?> The error that I am receiving is the following: It appears to be on the line where i declare private $connected; Why would it complain about that? Anyone see anything wrong with that code?
×
×
  • 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.