-
Posts
2,018 -
Joined
-
Last visited
-
Days Won
1
Content Type
Profiles
Forums
Events
Everything posted by mdshare
-
Faq by Richard Heyes PHP, as it turns out offers quite powerful options for connecting to mailboxes. As with most things, there is more than one option. However to go through all of the code required for such an undertaking is beyond the scope of the CE forums. However, abstractly speaking here are a few options for email access with PHP.. 1.) Connect to the mail server via sockets. This method requires a raw command line interface taylored to the mail protocol. The most common protocols being POP3, or (P)ost (O)ffice (P)rotocol, version 3, and IMAP (I)nternet (M)essage (A)ccess (P)rotocol. The business of connecting to a mailbox requires a great deal of planning and development time. The simple solution to this problem is to use already built applications and taylor them to your specific needs. PHP PEAR (P)HP (E)xtension and (A)pplication ®epository offers serveral already built solutions for this method. Though at the time of this writing, none preform *all* of the backend work required for a PHP socket-based connection. This solution would still require a great deal of development time. Currently PEAR provides the following PHP socket-based solutions: Net_IMAP developed by Damian Alejandro Fernandez Sosa Net_POP3 developed by Richard Heyes (the MIME mail guru) Richard Heyes' Mail_MIME package also has a multipart message parser in addition to the multipart message builder. 2.) Connect to the mail server using the PHP c-client (imap) extension. This method relies on a set of functions that are available in the PHP imap extension. The imap name is a little misleading in that these functions support connection to more than just the imap protocol, those being: POP3, IMAP and NNTP. The advantages to using the c-client extension as opposed to PHP socket-based connections are tremendous, in terms of memory consumption, and overall speediness. Put simply, PHP sockets are slow and cumbersome, c-client is written in C, and consequently this makes it much faster. The imap extension is an extended feature of PHP, meaning that you have to either compile PHP with the extension or, in Windows, download the .dll and uncomment the extension reference in php.ini. The .dll file is available in the .zip download of PHP for Windows, for Linux see the imap manual page for instructions. After I had developed my own webmail application based on the imap extension, I decided to abstract and release it in a PEAR package, Mail_IMAP. This package simplifies the webmail backend and does all the dirty work involved. It allows for a completely customizable aesthetic design and webmail user inferface. It tells you what is in a message, handles attachments, and provides information about the mailbox. It can even detect the user's protocol and port setting, based on nothing more than the server location, the user name and password. (Not to toot my own horn or anything) Mail_IMAP package page How to install Mail_IMAP Mail_IMAP is installable via the PEAR interface. At the command line, cd to the PHP directory (where the pear.bat file is located) Enter: pear install Mail_IMAP If the command line refuses to install the file because a stable version doesn't exist , download it and install it via the file path to the downloaded tarball. pear install C:\path\to\tarball\Mail_IMAP-1.0.0RC3.tgz Verify the installation by going to the PHP install directory. The file should be located here, or wherever PEAR is installed: C:\PHP\PEAR\Mail\IMAP.php Now the class file is available via the base include path. See the php.ini directive include_path (this should have a value of C:\PHP\PEAR\ or wherever PHP and PEAR are installed.) The class may now be included via the following from any script in any directory (via the include_path directive): require_once 'Mail/IMAP.php'; Review the documentation files located at: C:\PHP\PEAR\docs\Mail_IMAP\examples The documentation files include a demonstration inbox and message viewer. Extended documentation is available at: http://www.smilingsouls.net/Mail_IMAP Other pre-built PHP mail solutions also exist. One being Horde: http://www.horde.org Another being Squirrel Mail: http://www.squirrelmail.org
-
Re: [FAQ] How do I redirect users? (Location Header) Using the header you just don't have the back button anymore , no history by using header( Now we could also use the meta refresh (back button is available again) but sadly enough firefox has issues with correct execution of the meta refresh.
-
[info] What webdev language should I learn first ?
mdshare replied to mdshare's topic in Other Programming
Re: [info] What should I learn first ? I fully agree with you, but as potential new programmers on CE I thought it's better to push them towards xhtml. And my mistake for not checking on the w3schools so I had no clue that the info was so sparse on it. -
Re: [FAQ] How do I redirect users? (Location Header) yep that works also, thx killah but don't you have the text parsed first before the refresh ? didn't test it so no clue <?php echo "<p align=\"center\"> User Not Found</p> "; // err msg header('Refresh: 3; url=index.html'); // waits 3 seconds & sends to homepage ?> Explaination: 1. Use of php to set up a simple html message as to what is happening 2. with header, there is a command, "Refresh" and here is how it works: a. 'Refresh: 3; -- start all header commands with a single quote b. Refresh requires a parameter that is in seconds which tells the browser to refresh after this time period has passed. c. The ; is necessary to separate it from the rest of the Refresh parameters d. Refresh must be uppercased 3. After the ; put the url= command and put in your desired web page 4. Location doesn't work! with in this context. 5. Order matters. Refresh first, then it's second parameter, url=
-
You can start programming web pages very quickly - what you should focus on depends on what you want to do. No matter what, having familiarity with xhtml is important, so that is something you can start with immediately in any case. Along with xhtml, you will want to learn about cascading stylesheets (css). These are both fundamental to web development. see http://www.w3schools.com/web/default.asp However, after that there your path will depend on what you are interested in doing. In its most general sense "building websites" covers a a wide variety of skills and knowledge. Website development touches in all these areas (and more): Graphics, layout, art, server setup and administration, security, programming (both client side and server side), general computer knowledge, writing, accessibility, "web centric" things such as html, css, Web 2.0, blogs/wikis/blikis/forums/video/podcasting, dynamic web sites, Ajax, web services, and so on... and etc. It goes on and on. For a hobbiest, you have to get some skill in a number of these areas - but you can start with the basics and follow along into any area that you find interesting. The essential thing to understand is that you can put together simple websites with very little knowledge, and learn the things you need to know to do anything you want to do.
-
Re: Game Monitor [$200] it doesn't run, it's oxi that manually checks all your files and alters them as he finds security issues. so you pay his time, if it's to expensive just check on CE, all mccode security issues are posted with solutions
-
Re: Crime Problem Never give out cpanel access/ftp access a programmer should be able to blackbox code, check forwarded files without having access to the entire game
-
Although this is a PHP/MySQL board, I cannot stress enough of the importance of familiarizing yourselves with the current and up-to-date HTML standards. Some Wrox PHP books are written poorly in terms of addressing HTML standards compliance. And I have seen many many examples of poorly formed HTML documents in the posts in this and the other PHP forums. So I put together this FAQ to address how a PHP programmer *should* utilize the emerging HTML standards. Why: As professional programmers (or aspiring beginners) we are expected by nearly everyone in our professional lives to be knowledgeable and savvy of not only today's standards but those emerging on the horizon. Clients expect not only scalable, cost-effective and user-friendly interfaces but also a site that will function on tomorrow's browsers and be scalable with regards to emerging technologies and the standards dictated by the issuing authority designed to make those technologies function. Making use of PHP's ability to be ambiguous when it comes to HTML design is the first step toward achieving this goal of scalability. Commonly-used mark-up is wrapped in nice user-defined functions or defined in constants or variables. The goal being a template able to conform dynamically to any user agent or be updated to fit any emerging standard future and past. This is especially vital in a large project in which updating thousands of pages to conform to a new standard would be costly in terms of both time and money and not to mention the programmer's sanity. It is also especially vital to pick up on HTML standards early on. In earlier versions of HTML mark-up was designed very loosely with regards to case-insensitive tags, optional quoting of attribute values, single-tagged objects. But the latest and future versions are challenging this inherent looseness more and more. Things like XML and XHTML won't function on this loose-lipped syntax. Even though HTML is not really a language but a method of describing how a page looks it is closely tied to the world of real-language programming, delimiting a value with quotes now not only makes sense in programming terms but also allows HTML to fit in more with its cousins, PHP, ASP, JavaScript... etc. The HTML authority: Like PHP there is a group of people assembled to discuss, plan and create what HTML standards are. The difference between PHP and HTML (besides the obvious) is this group of people does not excerpt complete control over the language, but merely makes recommendations as to how it should be designed, implemented and utilized to the gigantic companies and their proprietary technologies that make use of it. The first stop for any html/css-related question should be the W3C (World Wide Web Consortium) website. http://www.w3c.org/ http://www.w3c.org/MarkUp/ Good practice, how to write standards compliant HTML: Document Type Declaration: First there is the Doctype setting. It is a single statement issued at the beginning of an HTML document before the opening HTML tag. It dictates to the browser what method of 'looseness' to allow in the proceeding HTML code. This is new to HTML and should accompany any well-formed HTML document. Different settings do different things. The strict setting does not allow the use of deprecated tags ( , <font>, etc), it corrects many of the inconsistencies between the different browsers with regards to how positioning and size are rendered. Albeit there are still minor (and very annoying) inconsistencies but the setting does help. http://www.w3.org/TR/REC-html40/struct/global.html Case-sensitive tags: The looseness of HTML and the quickly emerging XML created somewhat of a clash when it came to marrying the two. For this reason the W3C has made the recommendation that tags be case-sensitive. Again, when it comes to programming this seems the only natural progression and path of evolution for mark-up to take. For that reason tags and attributes should be written in all lowercase letters which will avoid namespace problems when and if a transition to XHTML or XML is made. HTML is rapidly moving toward becoming intertwined with XML, this is where XHTML comes from and this will be the HTML of tomorrow. See also: http://www.w3.org/TR/xhtml1/#h-4.2 Quoted values: All HTML attribute values should be delimited with quotations. <FORM METHOD=POST ACTION=some_page.php> Should now be: <form method="post" action="some_page.php"> or <form method='post' action='some_page.php'> Single or double quoting doesn't matter. And when used within the context of PHP the one should be used that would eliminate the need to escape the quote. See also: http://www.w3.org/TR/xhtml1/#h-4.4 Single name attributes: Scattered throughout HTML are a few oddball single name attributes. This is called attribute minimization. Attribute minimization has also been deprecated. <INPUT TYPE=CHECKBOX NAME=my_box CHECKED> Should now be: <input type="checkbox" name="my_box" checked="checked" /> -or- <input type="checkbox" name="my_box" checked="checked">Some checkbox text</input> checked="checked" is back-wards compatible and XHTML compliant. Ending a tag with '... />' is the XHTML compliant method of closing a tag, since XHTML requires both an opening and closing tag this syntax is provided as a shortcut when only one tag is required. As long as the tag is written as ' ' with a space in between the last letter and forward slash, this method is also backwards compatible. See also: http://www.w3.org/TR/xhtml1/#h-4.5 http://www.w3.org/TR/xhtml1/#guidelines Other examples of transitioning from the old method to the standards compliant method: <select name=my_select multiple> <option value=option1>option1 </select> Should really be written: <select name="my_select" multiple="multiple"> <option value="option1">option1</option> </select> <font face=Arial size=10>Some formatted text</font> This tag is now deprecated and should now be translated to a CSS equivilent: <span style="font-family: Arial; font-size: 10pt;">Some formatted text</span> <p style='font-family: Arial; font-size: 10pt;'> ... </p> Style sheets are a much easier method of declaring fonts as well as a smörgåsbord of other visual elements.. borders, margins, padding, positioning, etc. is also a deprecated element and should be translated to a CSS equivalent: <span style="margin-left: 5px;"></span> is now All single name tags should use the slash method to close the tag. See also: http://www.w3.org/TR/xhtml1/#h-4.6 An example of a standards-compliant image tag: [img=some_picture.jpg] Alt text is required to accommodate people with visual disabilities and is now part of the HTML 4.01 standard. Argument separators: URL argument separators should also be standards compliant, the W3C recommends that a semi-colon instead of an ampersand be used to separate URL embedded arguments. PHP.net recommends that & be used (which does not require a php.ini change). The url argument separator is a directive that can be set in php.ini and can be made to either recommendation. [snip from php.ini] ; The separator used in PHP generated URLs to separate arguments. ; Default is "&". ;arg_separator.output = "&" ; List of separator(s) used by PHP to parse input URLs into variables. ; Default is "&". ; NOTE: Every character in this directive is considered as separator! ;arg_separator.input = ";&" See also: http://www.w3.org/TR/html4/appendix/notes.html#h-B.2.2 See also: http://www.php.net/manual/en/function.urlencode.php And: http://www.w3.org/TR/xhtml1/#C_12 XML Compliant Delimiters: The W3C also has recommendations for the use of SERVER-side language delimiters. <?php ?> - Is XML compliant, gauranteed to be portable and is the preferred method. <? ?> - (short tags) NOT XML compliant, not gauranteed to be portable as this can be deactivated in php.ini <% %> - Asp style delimiters, not XML compliant, and again not gauranteed to be portable as this is another php.ini setting (off by default). <script language="php"></script> - (JavaScript style delimiters) NOT XML compliant but is gauranteed to be portable. See also: http://www.php.net/manual/en/language.basic-syntax.php Further resources: http://www.w3.org/TR/html401 http://www.w3.org/TR/xhtml1 http://www.w3c.org/XML
-
Symptom: Warning: session_start(): open(/tmp\sess_9d0fb76e93c38f1824377131f3c2e154, O_RDWR) failed: No such file or directory (2) in {{{ file path }}} on line X Remedy: You do not have a sessiondata directory configured to store session data. This is because the default values of the session.save_path directory is configured for Linux operating systems. Windows PHP installs must specify the value of the session.save_path directive explicitly. Open php.ini located at C:\Windows, or wherever Windows is installed. Change the value of the session.save_path directive to reflect a valid file path, I recommend C:\PHP\sessiondata, or whereever PHP is installed. Create the sessiondata directory, if it doesn't exist. Make sure that the proper write permissions are applied to the directory. Restart your HTTP server if necessary. Symptom: Warning: session_start(): Cannot send session cookie - headers already sent by (output started) in {{{file path}}} on line X Remedy: When session_start() is called it makes changes to the outgoing HTTP headers. As it does such, no output can come from the PHP script before it is called, e.g. any markup, whitespace or other kind of output appearing either before or after the opening <?php delimiter. Remove the output before session_start() and this error goes away. If this error is second, third, etc in a list of session_start() errors, its likely the error was triggered as a result of the errors before it. Symptom: Session variable doesn't persist between page requests. Remedy: Make sure that you are passing the session id between page requests. Since a session is intended to tie one user to data that persists on the server, PHP must have some way of associating the user with the session data. This is done with the session id. The session id is passed using cookies by default. When session_start() is called, it outputs a cookie to the client. The client's browser saves that cookie, then ever time the user requests a page the process starts all over again.. the browser sends the cookie that it stored from the first request back to the server. Then session_start() is called, session_start() looks to see if a session id has been passed to it, e.g. it looks for that cookie. If the cookie is found it says hey, I remember you, and it populates the $_SESSION superglobal with the session data from the previous request. If you are using cookies to pass the session id, you must therefore have first party or session cookies enabled in your browser. A second method of passing the session id, not relying on cookies, is by embedding the session id directly in every URL or form used in the page, for example. <?php session_start(); $_SESSION['foo'] = 'Hello, world!'; echo "[url='other_page.php?sid=".session_id()."']Next page...[/url]"; ?> Here, I've called on session_id() to output the current session id directly in the URL, which frees the user from needing cookies to be enabled in their browser. (some modern browsers disable cookies by default, BTW) Then page 2 can be called to output the value of $_SESSION['foo'] <?php //other_page.php session_start(); echo $_SESSION['foo']; ?> You see that when this test script is run through PHP's sausage maker, that $_SESSION['foo'] still exists! For further reference: http://www.php.net/session
-
In PHP you can redirect a user to another page using the header() function. <?php header('Location: [url]http://www.cegamerspace.com[/url]); ?> http://www.php.net/header This function is used to modify the HTTP response headers sent out from the server. For this example the 'Location' header is modified, the browser then picks up on the modification and makes a new request from the new location specified. Because this function modifies the HTTP headers, it may not be included after output has started from the script. For example: <?php echo 'Hello, world!'; header('Location: [url]http://www.cegamerspace.com[/url]); ?> This throws a warning-level error saying something to the effect of headers cannot be modified, output already started at line x in file z. This, on the other hand, is valid because it uses output control functions to buffer script output. <?php ob_start(); echo 'Hello, world!'; header('Location: http://www.cegamerspace.com'); ob_end_flush(); ?> Output from the script is written to the buffer, therefore, when the script reaches header() it is able to make HTTP header changes since nothing has yet been sent to the browser. Output buffering increases resource consumption slightly because extra memory has to be allocated for the buffer. More on output buffering: http://www.php.net/outcontrol Also, as a side note, it doesn't make any sense to have need of outputting anything before redirecting a user with the 'Location' header since all output will be lost anyway. However, this does come in handy for other functions or header modifications such as session_start() or setcookie() both of which make modifications to the outgoing HTTP headers. If you find you're in need of showing the user output before redirection, this is better done on the client-side with JavaScript.
-
The following outlines all the necessary steps needed to upload a file to a DB and then view the same file using a browser. I've used MySQL here, but this can work with any DB. 1.) Set up the MySQL table CREATE TABLE `files` ( `id` INT( 11 ) NOT NULL AUTO_INCREMENT , `file` MEDIUMBLOB NOT NULL , `mime` VARCHAR( 50 ) NOT NULL , PRIMARY KEY ( `id` ) ); 2.) Write HTML/PHP Basically only two fields are required to upload a file, a 'file' input field, and a 'MAX_FILE_SIZE' hidden field. The latter required, and will prevent the user from trying to upload a file that is too large on the client-side. This can be easily circumvented by the user and should be accompanied by server-side file validation. It accepts a file size in Bytes, I have set this to accept a file of 10000 bytes, or roughly 10KB. One attribute *must* also appear in the form tag to trigger the browser to upload data, and that is: enctype='multipart/form-data'. The following should be pretty straight forward: <?php //upload2db.php if (!isset($_POST['do_action'])) { echo "<html>\n", " <head>\n", " <title>UPLOAD TO DATABASE</title>\n", " </head>\n", " <body>\n", " <form action='{$_SERVER['PHP_SELF']}' method='post' enctype='multipart/form-data'>\n", " <input type='file' name='userfile' />\n", " <input type='hidden' name='MAX_FILE_SIZE' value='10000' />\n", " <input type='submit' name='do_action' value='Upload' />\n", " </form>\n", " </body>\n", "</html>"; } else { // You may also use if (is_uploaded_file($_FILES['userfile']['tmp_name'])) // IMO using if isset is an identical test if (isset($_FILES['userfile']['tmp_name'])) { // In this line I'm examining the file size and the MIME type of the file // to verify that the file is in the acceptable size range and is a jpeg // image. MIME type testing isn't foolproof, it is possible to spoof this. // The size testing, however, is not spoofable. if (($_FILES['userfile']['size'] <= 10000) && ($_FILES['userfile']['type'] == 'image/jpeg' || $_FILES['userfile']['type'] == 'image/pjpeg')) { // Make a database connection here! $link = mysql_connect('localhost', 'user', 'pass'); mysql_select_db('test', $link); // file_get_contents() PHP >= 4.3.0 if (function_exists('file_get_contents')) { $file = addslashes(file_get_contents($_FILES['userfile']['tmp_name'])); } else { // If using PHP < 4.3.0 use the following: $file = addslashes(fread(fopen($_FILES['userfile']['tmp_name'], 'r'), filesize($_FILES['userfile']['tmp_name']))); } if (!mysql_query("INSERT INTO `files` VALUES(null, '{$file}', '{$_FILES['userfile']['type']}')", $link)) { // do database error reporting here... echo 'Upload failed: Unable to insert image into database.'; } else { // Show a link to the image and display the image. // This function retrieves the last value set for the auto-increment field $id = mysql_insert_id(); echo "Upload successful! [url='viewdbfile.php?id={$id}']Click here to view the file![/url] \n"; echo $_FILES['userfile']['name'].":\n "; echo "[img=viewdbfile.php?id={$id}] \n"; } } else { echo 'Upload failed: File must be a JPEG file type and 10KB or less in size'; } } else { echo 'Upload failed: A valid file has not been uploaded!'; } } ?> The following is the viewer script for the database stored file. This script will do everything necessary to mimick the file. For instance, if the file is an image the call to header will trigger the browser to treat the contents as an image using the Content-type header and a valid MIME type. The MIME type of the file is sort of a universal method of easily identifying file contents. <?php // viewdbfile.php // if passing the ID via GET if (isset($_GET['id'])) { $id = $_GET['id']; } $link = mysql_connect('localhost', 'user', 'pass'); mysql_select_db('test', $link); // Make SELECT query $data = mysql_fetch_array(mysql_query("SELECT `file`, `mime` FROM `files` WHERE `id` = '{$id}'", $link), MYSQL_ASSOC); // Set the content type header header('Content-type: '.$data['mime']); // Also notice that I am not stripping the slashes, // Doing so may corrupt data in certain file types, // while you may need to do so for others. echo $data['file']; ?> Also have a look at: http://www.php.net/manual/en/features.f ... ost-method Which explains the $_FILES superglobal and the information available in it. Beware that a DB may not be the appropriate place for your files. Often times it is better to place your files in the normal file system. Large files in your DB can create potential bottlenecks (e.g. significantly effect DB preformance). A DB is fine for small files, but consider that DB storage of files creates extra steps in the retrieval of a file. Instead of pulling directly from the file system a DB query must be made, and then the server-side language must also interpret and output the file. Instead of the HTTP server simply querying the file system and outputting the file. Arguably marginal in some cases, but becomes more and more substantial as usage grows. Read this FAQ for storing in the file system: http://criminalexistence.com/ceforums/i ... ic=18418.0
-
Troubleshooting file uploads 1st, read the [FAQ] entry for uploading a file to make sure you have each component necessary present in your script. Uploading files to a directory: http://criminalexistence.com/ceforums/i ... ic=18418.0 Uploading files to a database: http://criminalexistence.com/ceforums/i ... ic=18420.0 If you are absolutely sure that all the necessary HTML form components are present, Follow each of the steps present in this article in detail: Go to your php.ini configuration file and locate the following snippet... ;;;;;;;;;;;;;;;; ; File Uploads ; ;;;;;;;;;;;;;;;; ; Whether to allow HTTP file uploads. file_uploads = On ; Temporary directory for HTTP uploaded files (will use system default if not ; specified). upload_tmp_dir = C:\PHP\uploadtemp ; temporary directory for HTTP uploaded files (will use system default if not specified) ; Maximum allowed size for uploaded files. upload_max_filesize = 2M Verify that C:\PHP\uploadtemp exists and has the proper write permissions. If the directory does not exist, create it and give it the proper write permissions, or change the value of upload_tmp_dir to another directory and apply the proper write permissions there. Verify that file uploads are turned on via the file_uploads directive. Verify that you are not trying to upload a file larger than 2MB in size, or larger than the value specified in upload_max_filesize. If you can verify each of the above then you will be able to output the $_FILES superglobal after an upload attempt, as in: echo "<pre>"; var_dump($_FILES); echo "</pre>"; If the variable is empty, then there is a problem with one of the above. If the variable contains the various data associated with the file then the problem is elsewhere. Be sure to restart your HTTP server, if necessary, after applying any php.ini changes.
-
The following outlines all the necessary steps needed to upload a file to the server, and then relocate the file to another directory. Also see the FAQ on permissions at: http://criminalexistence.com/ceforums/i ... ic=18419.0 Permissions must be set on the destination directory before this method will work. Basically only two fields are required to upload a file, a 'file' input field, and a 'MAX_FILE_SIZE' hidden field. This is required, and will prevent the user from trying to upload a file that is too large on the client-side. This can be easily circumvented by the user and should be accompanied by server-side file validation. It accepts a file size in Bytes, I have set this to accept a file of 10000 bytes, or roughly 10KB. One attribute *must* also appear in the form tag to trigger the browser to upload data, and that is: enctype='multipart/form-data'. The following should be pretty straight forward: <?php //upload2dir.php echo "<html>\n", " <head>\n", " <title>UPLOAD TO A DIRECTORY</title>\n", " </head>\n", " <body>\n"; if (!isset($_POST['do_action'])) { echo " <form action='{$_SERVER['PHP_SELF']}' method='post' enctype='multipart/form-data'>\n", " <input type='file' name='userfile' />\n", " <input type='hidden' name='MAX_FILE_SIZE' value='10000' />\n", " <input type='submit' name='do_action' value='Upload' />\n", " </form>\n"; } else { // You may also use if (is_uploaded_file($_FILES['userfile']['tmp_name'])) // IMO using if isset is an identical test if (isset($_FILES['userfile']['tmp_name'])) { // In this line I'm examining the file size and the MIME type of the file // to verify that the file is in the acceptable size range and is a jpeg // image. MIME type testing isn't foolproof, it is possible to spoof this. // The size testing, however, is not spoofable. if (($_FILES['userfile']['size'] <= 10000) && ($_FILES['userfile']['type'] == 'image/jpeg' || $_FILES['userfile']['type'] == 'image/pjpeg')) { // Give the file a new name to prevent one user from overwriting files // uploaded by another. mktime(), which creates a UNIX timestamp in // addition to the user name is good for this. $new_file_name = mktime().'.jpg'; // $_SERVER['DOCUMENT_ROOT'] will provide an absolute path to the base directory // fill in the rest of the path from there, if necessary. // echo the value of $_SERVER['DOCUMENT_ROOT'] to do this! $file_path = '/images/users/'.$new_file_name; if (move_uploaded_file($_FILES['userfile']['tmp_name'], $_SERVER['DOCUMENT_ROOT'].$file_path)) { echo "Upload successful! \n"; echo 'File: '.$_FILES['userfile']['name'].' ('.$_FILES['userfile']['size'].") Bytes \n"; echo "Renamed: $new_file_name \n"; } else { echo 'Upload failed: There was likely a permissions error.'; } } else { echo 'Upload failed: File must be a JPEG file type and 10KB or less in size'; } } else { echo 'Upload failed: A valid file has not been uploaded!'; } } echo " </body>\n", "</html>"; ?> Also have a look at: http://www.php.net/manual/en/features.f ... ost-method Which explains the $_FILES superglobal and the information available in it.
-
The following is intended to outline some common conventions used by programmers to enhance both the readability and understandablity of code. If you've been referred to this page its likely because *someone* couldn't read what the hell you were posting! Please take the following to heart, as its information that will save us and you headaches. Take for instance the following block of sloppy, unreadable code: if ( ! $_POST['submit'] ) showform(); else { mysql_connect("localhost", "...", "...") or die("Could not connect to database."); mysql_select_db("...") or die("Could not use database"); $query = "select id from referee where id=" . $_POST['id']; $result = mysql_query($query) or die("Error in the query: $query"); if (mysql_num_rows($result) == 0) { echo("<font color='#FF0000'>Invalid Login</font>"); showform(); } else { echo("<font color='#FFFFFF'>Logged In</font>"); if ( ! $_POST['submitted'] ) { login(); ?> <form action="index.php" TARGET="_top" method="post"> <input type="submit" name="submitted" value="Logout"> </form> <?php } else logout(); } } This is a real user-submitted snippet of code BTW, if you're sitting there thinking to yourself; WTF? You're not the only one. Deviations from HTML standards not-with-standing, posting a mess like this makes it difficult for us to answer your questions quickly and easily. Here's the same code written for the PEAR convention by Richard York, for the sake of completeness he has also adjusted non-standard HTML and enhanced the logic using isset() and empty(): if (!isset($_POST['submit'])) { showform(); } else { mysql_connect('localhost', '...', '...') or die('Could not connect to database.'); mysql_select_db('...') or die('Could not use database'); $query = "SELECT `field` FROM `table` WHERE `id`=". $_POST['id']; $result = mysql_query($query) or die('Error in the query: '.mysql_error()); if (mysql_num_rows($result) == 0) { echo "<span style=\"color: red;\">Invalid Login</span> \n"; showform(); } else { echo "<span style=\"color: white;\">Logged In</span> \n"; if (!isset($_POST['submitted']) || empty($_POST['submitted'])) { login(); echo " <form action=\"index.php\" TARGET=\"_top\" method=\"post\"> <input type=\"submit\" name=\"submitted\" value=\"Logout\" /> </form>\n"; } else { logout(); } } } You can find the full PHP PEAR Group's coding convention documented here: http://pear.php.net/manual/en/standards.php And then the other popular method, and Richards personal favorite, is the one true brace convention: if (!isset($_POST['submit'])) { showform(); } else { mysql_connect('localhost', '...', '...') or die('Could not connect to database.'); mysql_select_db('...') or die('Could not use database'); $query = "SELECT `field` FROM `table` WHERE `id`=". $_POST['id']; $result = mysql_query($query) or die('Error in the query: '.mysql_error()); if (mysql_num_rows($result) == 0) { echo "<span style=\"color: red;\">Invalid Login</span> \n"; showform(); } else { echo "<span style=\"color: white;\">Logged In</span> \n"; if (!isset($_POST['submitted']) || empty($_POST['submitted'])) { login(); echo " <form action=\"index.php\" TARGET=\"_top\" method=\"post\"> <input type=\"submit\" name=\"submitted\" value=\"Logout\" /> </form>\n"; } else { logout(); } } } Can you see why we're much more likely to respond to people who post code that is indented and easy to read? We're all busy folks, and no one wants to take the time to reformat your code just so it can be read. Personally, I would also avoid opening and closing PHP blocks, IMO, that just clutters the code more.
-
JavaScript cannot actively read variables from the server, but when a page loads, PHP can pass variables to JavaScript by writing to the page the JavaScript is on. <?php $username = "Snib"; ?> ... <script language="javascript" type="text/javascript"> var sStr = "My name is <?php echo $username ?>."; document.write(sStr); </script> ... This code will output this text: By editing the JavaScript on the page, PHP can set JavaScript variables. This is very useful for passing database values to JavaScript to compare with a JavaScript variable or number. Let's say that there is a MySQL database called db1, with a table called table1, which has two columns, 'userid' and 'usernum'. To retrieve information about Snib, you can use code like this: <?php $connection = mysql_connect('localhost', 'username', 'password'); $sql = mysql_select_db('db1', $connection); $userid = "Snib"; $query = "SELECT * FROM `table1` WHERE userid='$userid'"; $result = mysql_query($query); $data = mysql_fetch_assoc($result); $usernum = $data['usernum']; ?> <script language="javascript" type="text/javascript"> var userid = "<?php echo $userid; ?>"; var usernum = "<?php echo $usernum; ?>"; //if usernum is less than or equal to 50 if (usernum <= 50) { alert("You are not allowed on this page, " + userid); setTimeout('window.location = "otherpage.php"', 3000); // user leaves in 3 seconds } else { alert('Welcome to this page, ' + userid); } </script> <?php mysql_close($connection); ?> Although setting JavaScript variables with PHP is helpful, it cannot always be done. For instance, PHP cannot modify external .js documents temporarily. It changes them for good. Reference: MySQL with PHP: http://php.net/mysql JavaScript: http://javascript.com http://msdn.microsoft.com/library/default.asp (JScript and DHTML)
-
Gangster Legends The Gangster legends engine is as it is. Deprecated Game Engine/Script by the developers. ### General Information ### Gangster Legends: Source is a text-based MMO gangster game written in php. The base of GL: Source is the v0,75 script that has been available for download for a while now. We decided to code additional updates for it because there was a lot of interest for it. We plan on releasing a new update package once every few months. We do charge a small fee for these updates to cover the amount of time we spent on coding these updates. The Start version can be downloaded for free. The main idea behind GL: Source is to provide a basic game for you to build further upon to make it unique. ### Frequently Asked Questions ### Why are some parts open source and others not? GL Source was given out in order to see what people can come up with. The start updates are being given out for a small fee to cover the costs and time we spent on coding. Are the scripts Bug free? I would be lying if I said yes but its free of any big bugs and all features work as they should when hosted correctly. Will you help me when something goes wrong with my game? No we wont help you fix your game. The scripts are given out as is. There are some occasions when we will provide you with a fix if its a known problem. ### Download ### Can be found at our Scripts vault
-
Re: Wich OS do you prefer? WFW 3.11 was the most stable version as shell over ms-dos and actually have to check which version of NT forgotten... but wfw is/was super for small peer to peer networks, way better than novel lite that had more hickups than anything else, Novell itself super ,Novel lite... well like all downgraded versions of good software... they kill it. And history well Compaq as old HP is quality you pay a lil bit more but it kinda lasts forever.. all my modern systems are HP till now no issues... allthoug I always buy business line so can't compare it with their normal line of PCs that are way cheaper and where I have no experience with. If I would co locate a server it would be a HP pro reliant, not a dell like everyone uses
-
Re: Wich OS do you prefer? my triton and helix irc servers run on freebsd laptop screwing around with selinuxthat receives 100 updates a day... welcome to the world of linux gaming desktop, xp ... dev desktop, xp again ... pda windows mobile nokia phone runs on symbian as my psion my old armada 700 compaq laptop, wonderfull msdos with wfw 3.11 connected to the old compaq deskpro which runs NT... both see still some electricity as my GF is stuck at old Word and Excell. And she doesn't need more, for her it's a luxery typewriter. These 2 have switched often between novel lite and wfw 3.11/NT but last install years ago was wfw so it stays on it. (tells also something of the super quality of Compaq, can't be killed ;) ) Next gaming machine I'll buy is the HP blackbird that receives 100 updates a day... welcome to the world of linux
-
These are 2 of my fav javascripts which make the development of a browser game to a higher level. wz_tooltip.js v. 4.12 The latest version is available at http://www.walterzorn.com or http://www.devira.com or http://www.walterzorn.de and Yahoos User Interface Library http://developer.yahoo.com/yui/
-
Re: Hi Peeps I loved clipper s87 as language, was THE language to make money from ;) , made several db apps and accounting software which sold nice and easy. I've learned Turbo Pascal as first step to C, was basicly the way to learn to code object oriented. Surprisingly my first job was .... COBOL on a AS/400 :s but learned fast that the market was small/medium sized businesses and that's where clipper s87 came to play. One nasty bit of clipper s87 was that it was so easy to decompile , but soon there where some security features against it... actually most of the compiled apps (whatever language) could be decompiled back than. Was a good source to learn also. The decompiler I used was uhmmm Valkery or something like that.... was really powerfull. And yea it's fun to see some old timers ;) allthough I'm prob like 10-15y younger than you.
-
Re: Hi Peeps Do people ever read ??? I said that Nyna did not say 30y exp with php etc... pdp's the old omnibus machines... my parents have still one in the warehouse collecting dust... they can't get rid of what they once paid a fortune for. Never seen it in action even if I was to young to remember... And Basic wasn't so bad... actually interpreter languages back than can be compared now with the web scripting languages.. The name BASIC sounds simple, but most forget that it was a high level programming language. As Basic was dependend on IBM if I recall correct we learned back than turbo basic (same dev of turbo pascal, Borland). Microsoft had on the pc's where ms-dos was installed qbasic I think... gah this is all so long ago. But it was fun, I would love to step back to the old days with no GUIs, previews, etc... I would make a fortune just on service providing and teaching people how to use command line syntax.
-
Re: Hi Peeps actually 20y ago I didn't see any html, php, css than again Nyna doesn't say experience in php etc 30y ago I was still busy with old BBS systems and using clipper s87 for database apps, and was I proud to be co-sysop of the Pioneer brand BBS... got a nice superfast devlonics 9600bps modem than (the card was the size of 1/3rd of a a minitower...and YES bps not kbps or mbps) If you refer to hypertext script languages, this was the birth of it... (20y ago) and was slowly used, first was compuserve... wow that was a nice switch from text based BBS to a graphics based compuserve. some history lessons... 1991 HTML had birth 1994 PHP had birth 1995 mySQL had birth 1996 CSS had birth but only at 2000 browsers supported it edit1: 30y ago, must still have been forthran, cobol as I had to learn those also 20y ago and my prof was prob stuck in time cuz he was talking about 10mb HD while I had already a 40mb HD... edit2: oh and 30y ago it was still 8inch floppydisks and a monster of a computer size of a bureau desk
-
Re: Hello Everybody! welcome I'll check your game out a bit later, signed up but didn't loaded outlook yet ;) to verify my account. md
-
Re: Court (v2) nice job ellil and your first mod, don't be so modest.... yea maybe first mccode mod..
-
Re: Add a Radio to your site [Free mod] v 0.01 thx that you all like it you can add extra radio channels easy to the xml allthough you will need images for the popup and you will have to change the height of the popup. BB tag is broadband RP tag is realplayer WM tag is windows media player Note that realplayer support is 5.0 For modwriters it shouldn't be difficult to make it as a mccode mod as it would be just translating the xml to a mysql and adding a lil admin cp to edit the mysql contents. I do not want to see from someone who makes it a mccode mod to ask a single dime for it. Else I make the changes and put it up for free.