Jump to content

crabfinger

Members
  • Posts

    110
  • Joined

  • Last visited

    Never

Everything posted by crabfinger

  1. i see that there is an unwanted whitespace character in this line $sth-> execute(); other than that try some error reporting.
  2. This is susceptible to an sql injection. $pass = $_POST['pass']; Remember mysql_real_escape_string(); $pass = mysql_real_escape_string($_POST['pass']
  3. Why not comment on the article? You're probably more likely to get the help you want. I can only speak for myself but I'm not going to jump right in to give you suggestions about how to use a language you don't have a clue how to use in the first place. My only suggestion is to visit http://www.php.net and RTFM (Read the Friendly Manual).
  4. on another note why not add the numeric level to the database and interpret it on the other end? saves for database size
  5. change </color> to </font> and your good
  6. consider arrays, they work with html too <input type="text" name="mypost[22]" value="" /><input type="text" name="mypost[54]" value="" />
  7. really budget has nothing to do with databases, learn how to use phpmyadmin (free) or an ssh terminal and the mysql command to build databases and tables, even build the databases using php code. there are a world of possibilities which cost nothing if you already have the server.
  8. If you have access to the server mysql is very easy and free to install. I would recommend looking into it. otherwise what I posted will do exactly what you're asking for, just modify the code to show what you want it to.
  9. <?php $strThisPage = 'hello.php'; // Change this to your page name $players['1'] = 'player 1'; $players['2'] = 'player 2'; $players['3'] = 'player 3'; $players['4'] = 'player 4'; $players['5'] = 'player 5'; if( isset( $_GET['player'] ) && !empty( $_GET['player'] ) ) { if( isset( $players[$_GET['player']] ) ) { print $players[$_GET['player']] . '<br /><br />'; } } foreach($players as $key => $value) { print '<a href="' . $strThisPage . '?player=' . $key . '">' . $value . '</a><br />'; } ?>
  10. alright so you didnt do what i said print_r($something) prints to the screen $somethingelse = print_r($something,true) formats an array as a string and returns to a variable instead of printing to the screen. make sure the second argument is true or it will print to the screen
  11. did a little work to clean your code up. not sure why you want to create another table with one thing in it, why not just add a column to the users table. <html> <head> <title>ReH-0.1--Create a Session</title> </head> <body bgcolor="#575757"> <center> <?php try { // Connect and select $connect = mysql_connect("localhost","root",""); if(!$connect) { throw new Exception( mysql_error() ); } mysql_select_db( "reh_temp", $connect ); // verify post-data if( isset( $_POST['session'] ) && !empty( $_POST['session'] ) ) { if( strlen( $_POST['session'] ) < 4 ) { throw new Exception('Session must be longer than four characters'); } $session = mysql_real_escape_string($_POST['session']); } else { throw new Exception( 'Session Required' ); } if(isset($_POST['session_conf']) && !empty($_POST['session_conf'])) { if( strlen( $_POST['session_conf'] ) < 4 ) { throw new Exception('Session confirmation must be longer than four characters'); } $session_conf = mysql_real_escape_string($_POST['session_conf']); } else { throw new Exception( 'Session Confirmation Required' ); } // Query post data $query = mysql_query("SELECT * FROM users WHERE users='${session}'"); if( mysql_num_rows( $query ) != 0 ) { //Check for Match if ( $session != $session_conf ) { throw new Exception('Session does not match confirmation'); } //Insert value into users table if( !@mysql_query( "INSERT INTO users VALUES ( '${session}' )" ) ) { throw new Exception( mysql_error() ); } // if this executes the script is complete print '<font color="#0F0">Success</font>'; } catch(Exception $objException) { print '<font color="#f00">' . $obj->Exception->getMessage() . '</font><br/>'; } ?> <font color="#fff">Before encrypting your password, a session must be started. We need you to enter a personal session name that you will remember so that you password is protected by this session.</font><br /> <form action="ReH-0.1.php" method="POST"> <label for="session" style="color: #fff;">Session Name: <input type="text" maxlength="10" size="10" name="session"></label><br /> <label for="session_conf" style="color: #fff;">Session Name Confirmation: <input type="text" maxlength="10" size="10" name="session_conf"></label><br /> <input type="submit" value="Create Session"> </form> </center> </body> </html>
  12. Upon further thought this reply was not correct tech help
  13. i was thinking about that too but this wouldn't replace autoload in any way. It could make a useful addition to __autoload in some applications
  14. I'm not sure why I did this just yet but I'm sure I'll figure it out soon enough. Mostly I got sidetracked on a search for Something in the PHP documentation and was intrigued by a couple pages. Sorry, I can't seem to find the specific pages in my history. Anyways if you want to have more control over how classes are loaded in user contributed modules inserted into your application this may help <?php function loadClass( $strClass, $aryArgs = array(), &$varRef = NULL ) { // If a reference variable is not defined then set it to the class name. if( $varRef === NULL ) { global $$strClass; $varRef = &$$strClass; } // If the reference variable is not empty we cant very well declare something in it. if( empty( $varRef ) ) { // Not the prettiest piece of code in the world but i couldn't find a prettier way. eval('$varRef = new $strClass(\'' . implode('\',\'',$aryArgs) . '\');'); return true; } else { return false; } } ?> Well how the hell does this help me you ask? <?php // a couple example classes class myClass { var $strArgs = NULL; function __construct() { $this->strArgs = preg_replace('/\s*/m','',preg_replace('/\n*/m','',print_r(func_get_args(),true))); } function foo() { return 'hello'; } } class myNewClass extends myClass { } print "\r\n"; // This works, // you can declare the variable before-hand but you dont have to. If you do it has to be empty and not null or you will have unexpected results // $myClass = ''; print "\r\n"; var_dump( loadClass( 'myClass' ) ); var_dump( $myClass ); var_dump( $myClass->foo() ); // This will return false and not load the class but continue with the script this saves from classes being created multiple times without our knowledge print "\r\n"; var_dump( loadClass( 'myClass' ) ); // So if we want another one we have to specify a variable to load the class into // This way you have to declare the variable before-hand or the function will see it as null and try to set it as the class name $myClass2 = ''; print "\r\n"; var_dump( loadClass( 'myClass', array(), $myClass2 ) ); var_dump( $myClass2 ); var_dump( $myClass2->foo() ); // another way of doing it $strClass = 'myNewClass'; print "\r\n"; var_dump( loadClass( $strClass ) ); var_dump( $$strClass ); var_dump( $$strClass->foo() ); // Here we make full use of loadClass $strClass = 'myNewClass'; $aryArgs = array( 'foo', 'bar' ); $varRef = $strClass . '2'; $$varRef = ''; print "\r\n"; var_dump( loadClass( 'myNewClass', $aryArgs , $$varRef ) ); var_dump( $$varRef ); var_dump( $$varRef->foo() ); php?> This should output something similar to bool(true) object(myClass)#1 (1) { ["strArgs"]=> string(12) "Array([0]=>)" } string(5) "hello" bool(false) bool(true) object(myClass)#2 (1) { ["strArgs"]=> string(12) "Array([0]=>)" } string(5) "hello" bool(true) object(myNewClass)#3 (1) { ["strArgs"]=> string(12) "Array([0]=>)" } string(5) "hello" bool(true) object(myNewClass)#4 (1) { ["strArgs"]=> string(23) "Array([0]=>foo[1]=>bar)" } string(5) "hello" Just hoping to intrigue someone into helping me make this into something useful
  15. Yes but its not like I can get data from a database if the extension is not installed in php. Why would I want to know if it is installed on the system if it can't be used.
  16. Thanks ignace, I didn't even think of doing that. Now i feel pretty stupid.
  17. Alright I'm designing a database library so that when the user installs my application to their server it will allow you to select the database type out of a list of available database engines. Also allowing you to chose which server/database engine/database/table/format for every piece of data taken from the database, making it extremely easy to install it on a system which uses a series of database engines/databases for data carried across multiple types of applications without needing to modify files. My current issue is generating a list of possible database engines and checking to see which ones are installed on the system and enabled through php. Any help would be much appreciated, thank-you in advance.
  18. add a column to your database using ALTER TABLE `table_name` ADD `image_column` logtext NOT NULL Then populate that with images/image.png And so on then its just an image tag.
  19. I want to create an error logger for a content management system I'm building, I just would like to know what the best way to format an error is and what information should be taken from these errors.
  20. this is my .htaccess file RewriteEngine on RewriteCond %{REQUEST_URI} !=/index.php RewriteRule ^(.+?)\.php$ index.php?page=$1 [QSA] so http://www.example.com/hello-world.php?say=something http://www.example.com/example/hello-world.php?say=something http://www.example.com/index.php?page=hello-world&say=something Turns into http://www.example.com/index.php?page=hello-world&say=something http://www.example.com/index.php?page=example/hello-world&say=something http://www.example.com/index.php?page=hello-world&say=something
  21. Alright with user logging the most essential thing is to make sure that the user is in fact the user, so you need a function to check information against the database whenever i have to deal with users i make sure that there is a unique id in the database and then check everything against what is returned once i get the user id <?php function validate_user($user_password=NULL,$user_id=NULL) { $user_id = ($user_id === NULL || !is_numeric($user_id) ? (isset($_SESSION['user_id']) ? NULL : $_SESSION['user_id']) : $user_id; // set $user_id to a session variable if not supplied, non-numeric or NULL if it can't find the session variable $user_password = $user_password === NULL ? $_SESSION['user_password'] : $user_password; if($user_id !== NULL) { $query = 'SELECT user_password FROM users WHERE user_id="' . $user_id . '"'; if(@mysql_query($query)) { $array = mysql_fetch_array($query); if($array['user_password'] == $user_password) { return TRUE; } else { $_SESSION['errors'][] = 'validate_user() (' . time() . '): Password incorrect'; return FALSE; } } else { $_SESSION['errors'][] = 'validate_user() (' . time() . '): ' . mysql_error(); return FALSE; } } else { $_SESSION['errors'][] = 'validate_user() (' . time() . '): Unable to validate user'; return FALSE; } } ?> If this function returns true then the user is who they say they are. So now we need to use the function to either log the user in or out. <?php session_start(); $login_success_page = ''; // set this to where you want to send your users after they login. if(validate_user()) { session_unset(); print 'You have successfully logged out'; } else { if(isset($_POST['submit'])) { $user_name = mysql_real_escape_string($_POST['user_name']); $query = 'SELECT user_id FROM users WHERE user_name="' . $user_name . '"'; if(@mysql_query($query)) { $array = mysql_fetch_array($query); $user_password = hash('sha512',$_POST['user_password']); // set this to whatever encryption you want to use if(validate_user($user_password,$array['user_id'])) { $_SESSION['user_id'] = $array['user_id']; $_SESSION['user_password'] = $user_password; header('location:' . $login_success_page); } else { print 'Incorrect password'; } } else { $_SESSION['errors'][] = mysql_error(); print 'User name does not exist'; } } ?> <form action="" method="post"> <table align="center" cellpadding="1" cellspacing="0"> <tr> <td> User Name: </td> <td width="100%"> <input type="text" name="user_name" /> </td> </tr> <tr> <td> Pass Word: </td> <td width="100%"> <input type="password" name="user_password" /> </td> </tr> <tr> <td style="text-align: right"> <input type="submit" name="submit" value="Log In" /> </td> </tr> </table> </form> <? } ?>
×
×
  • 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.