Jump to content
xisto Community

Search the Community

Showing results for tags 'php'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Help & Support
    • Alerts, News & Announcements
    • Web Hosting Support
    • Introductions
  • Computers & Tech
    • Science and Technology
    • Software
    • The Internet
    • Search Engines
    • Graphics, Design & Animation
    • Computer Gaming
    • Websites and Web Designing
    • Mobile Phones
    • Operating Systems
    • Programming
    • Online Advertising
    • Hardware Workshop
    • Computer Networks
    • Security issues & Exploits
  • Others
    • General Discussion
    • Business Forum
    • Photography
    • Health & Fitness
    • Dating And Relationships
    • The Vent
    • Art & Creativity
    • Home & Garden

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


Location


Interests

Found 12 results

  1. I want to do some calculator php script without calculator can any one help with hints or simple script
  2. To save your time I'll assume that my readers know what Moodle is otherwise this post will not be relevant to them. For info. about Moodle please visit the official website The Problem: Moodle has it's own reports module where you can use a well organized interface for pulling out different reports about the activities of the users. For me as a course tutor, I need to have a quick check on the assignments submitted by my students in a certain course, certain course topic. The current reports module in Moodle is not straight forward with that regard. It pulls more data than I need which kind of doesn't highlight the parts that I'm interested in. I also hate to login every time I need to check the assignments submission. Moodle usually is a bit slow script. The Solution: It would be more practical to write a code that queries the Moodle data base and displays only what I need. A wizard interface would be ideal in my situation. Just to be specific, I'm using: Moodle version: 1.9 PHP version 5.2.17 MySQL version 5.5.29-log Application Outline: 1- A code to connect to the database : db-config.php, that will be included wheneverf we need to query the database 2- The index.php includes the db-config.php and: connects to the Moodle DB query table mdl_course to select the id and fullname fields to populate a drop-down list for the user to choose. posts the user input to sections.php 3- The sections.php will: connect to the Moodle DB query table mdl_course_sections and select the sections field that match the previously selected course id. populate a drop-down list for the user to choose posts the user input to report.php 4- Finally the report.php will: connect to the Moodle DB query mdl_assignment, mdl_assignment_submissions and mdl_user using RIGHT JOIN on the id field select only the submitted assignments using WHERE ( --- OR ----) AND ------ based on the user input, ie the course and section you selected in the previous steps in the wizard. use a while loop to display the record set in a table The Code: I tried to post the code using the BBcode but it doesn't show in the preview, so I'll try to attach it. Your feedbak is most welcome Thank you db-config.phpindex.phpsections.phpreport.php
  3. Pretty soon, all the mysql_ functions that we have been using in PHP scripts could go the way of the dinosaur. Well, not literally, because there are still some PHP scripts out there that are dependent on PHP 4 so some web hosting providers still provide PHP 4 hosting. Also, we hardly have anyone running PHP 5.5 so it could be at least a few months before we are going to have to worry about getting all of our scripts updated.Now that the mysql_ functions are deprecated, what next? MySQLi and PDO_MySQL are the answer. MySQLi provides some pretty nifty features, such as being able to send multiple SQL statements to the server in one go, thus reducing the overhead of going back and forth for the execution of SQL statements, which was associated with the older MySQL API. PDO has the advantage of being able to write database-independent code, assuming that the SQL statements themselves were written with portability in mind. Both APIs are the future for PHP web developers, so what better a time to start learning than right now?
  4. Just wondering if any members might like to see a series of Tutorials on some basic PHP language?If so, reply to this Topic with the stuff you might like to have a tutorial written for and I can write one up for you to read.Thanks.Just a test. don't panic
  5. The purpose of this short tutorial is to show how fast and easy can be to use classes within your PHP code, it may help you to manage and maintain easily your web applications. What we’ll do here is to create a folder which will contain your php classes and a small script that will aloud your pages to load this classes on the fly avoiding repetitive declarations. As example we’ll create two classes, one will manage the post form and variables, the other will display the html headers and footers. Then we’ll simply call them trough a php page. Test environement To run this examples, it’s easier to do it in a WAMP (a full featured web laboratory installed in your computer). This topic assumes that you installed it as shown in this topic: http://forums.xisto.com/topic/78567-optimize-your-virtual-hosts-separate-your-files-from-the-wamp/#entry517983 Otherwise, just make the appropriate changes in the paths used in the examples shown below. Create the myClasses folder This folder will contain all the classes you’ll use in you php code. You can put the myClasses folder wherever you want. For security reasons you should put it outside of the folders publicly accessible, like the top level directory: Test environement Z:\home\yoursite\yourclasses\ Server /home/yoursite/yourclasses/ Create the classloader.php file This file will load automatically the classes stored in the ‘yourclasses’ file when needed. Test environement Z:\home\yoursite\classloader.php Server /home/yoursite/classloader.php Code <?phpfunction __autoload($class){require_once ( '/home/yoursite/yourclasses/'.$class.'.php' );}?> Note: We put this code in a separate file to simplify improvements, like changes of method. You can also add here the session_start, or manage your page compression. The class_test_post.php file In this class you’ll have some functions who will read the infos posted and manage the post form. Test environement Z:\home\yoursite\yourclasses\class_test_post.php Server /home/yoursite/yourclasses/class_test_post.php Code <?php class class_test_post {var $yourname = "";var $yourmusic = "";function __construct(){if(isset($_POST['yourname']) || @$_POST['yourname']<>""){$this->yourname = $_POST['yourname'];$this->yourmusic = $_POST['yourmusic'];}}function display_info(){$string ="";if(isset($_POST['yourname']) || @$_POST['yourname']<>""){$string = "<b>Your name is </b>".$this->yourname." <br /><b>and you like </b>".$this->yourmusic."<hr/>";}else{$string = "Please fill in the form:<hr/>";}return $string;}function display_form(){return <<<DFR<form action="" method="post" >Your name <input name="yourname" value="$this->yourname" /><br/>Your music <input name="yourmusic" value="$this->yourmusic" /><br/><input type="submit" name="submit" value="Submit Form"</form>DFR;}}?> Important: You noticed that the class name is the same as its name file without extention. Create the class_test_html.php file This class will simply display the header and footer of the html page. We’ll just pass the page title as variable. Test environement Z:\home\yoursite\yourclasses\class_test_html.php Server /home/yoursite/yourclasses/class_test_html.php Code <?php class class_test_html {static function display_header($pagetitle){return <<<DHD<html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>$pagetitle</title></head><body>DHD;}static function display_footer(){return <<<DFT</body></html>DFT;}}?> Note: in case you need some google tips about the ‘<<<DHD’ ending with ‘DHD;’ this notation is called Heredoc. Create the test_post.php file This is the main page that will call and use the classes. Put it in a place accessible from your browser. Test environement Z:\home\yoursite\public_html\yoursite.com\test_post.php Server /home/yoursite/public_html/yoursite.com/test_post.php Code <?phpinclude("/home/yoursite/classloader.php");$post = new class_test_post();$str = class_test_html::display_header("The Title of Your Page");$str .= $post->display_info();$str .= $post->display_form();$str .= class_test_html::display_footer();echo $str;?> Now, you can test it. Some Explanations The first row of this code includes the class loader file. This way you need only one row in each php page you’ll do, with whatever classes you’ll use. If you need to change the way you load classes, or add whatever code to every pages, like statistics, a session manager, or change the path to the class folder, you can do it at once in this file: the class loader. The second row declares a class as an object, ‘$post’ will contain every function and variables enclosed in ‘class_test_post()’. You noticed that the classes have the same name as their file without extension, now you can imagine why... From the third row until the sixth, we just store the contents returned by the classes before displaying it in the seventh row. You noticed that we used two distinct ways to call the classes. Lets say a few words about this. When we declared the $post as a new class_test_post, we did create an entire object that we can use with an arrow to call functions or set/return values. Concerning the class_test_html, as we don’t really need any object, we can call the class functions directly just using the ‘::’ symbol. This is quite practical to store some home made functions, but don’t forget to declare this functions as ‘static’ in the class... Ok, now you see how easy is to work with classes, I hope you liked it
  6. In the prior topic we saw how to install a WAMP and customize it to easily switch between virtual and real hosts typing the same address in the browser: ‘yoursite.com’. Now, we’ll separate the Virtual Host’s files from the WAMP program to make virtual management easier. To see the prior tutorial, follow this link (if you have any issue, please live a comment): 3 Steps To Create And Manage Virtual Hosts To Test And Combine Offline And Online Explanation To store the programs we used the folder: C:\Program Files\EasyPHP-12.1\ And the virtual hosts are physically located in: C:\Program Files\EasyPHP-12.1\www\ As it doesn’t make many sense to store Virtual Host’s files within the programs, we’ll bring them here: Z:\home\yoursite\public_html\yoursite.com\ Note: If you don’t have a ‘Z:/’ partition, you can easily create one using a partition editor like MagicPartition or Easeus, or whatever program you prefer. Of course, you can also choose an another location for your files ... We’ll create this folders assuming that you use xisto's services and that your top-level directory in your real web hosting is: /home/yoursite/ and that your domain’s files are located in: /home/yoursite/public_html/yoursite.com/ This way your virtual and real hosts will have the most similar directory structures as possible. (To do the appropriate changes, you can find your Home Directory at the left side of your cPanel below the 'Main Domain') Changes to do in yoursite.conf Goal: To change the folder location of ‘yoursite.com’ in Apache. Open the Apache configuration folder: C:\Program Files\EasyPHP-12.1\apache\conf\ Make a backup of ‘yoursite.conf’ before modifying it, and then open it to make the changes as follow: <VirtualHost 127.0.0.1>DocumentRoot "Z:/home/yoursite/public_html/yoursite.com/"ServerName yoursite.com<Directory "Z:/home/yoursite/public_html/yoursite.com/">Options FollowSymLinks IndexesAllowOverride AllOrder deny,allowAllow from 127.0.0.1Deny from allRequire all granted</Directory></VirtualHost>Stop and run Apache, then go with your browser to: http://ww38.yoursite.com/ You should acceed to the new location. Advantages: - It’ll be easier for you to manage your stuff, as you’ll have a better view on your files and they’ll be easier to access, maintain, backup, upload, etc. - If you do the appropriate changes, you’ll have almost a similar structure as you real web hosting. - An another advantage is that you can install an another WAMP with a different configuration and map some Virtual Hosts to the same place if you wish so... I hope you’ll enjoy it at least as I do, Cheers :-) ------------------------------------------------------------------------ PS: In case EasyPhp shows a warning message accessing to the new location, you can try this:) Mapping the ‘Z:\’ in EasyPhp Goal: To aloud EasyPhp to access files located in ‘Z:\’ In your browser, go to the administration panel: http://forums.xisto.com/no_longer_exists/ In the local files click in add an alias, name it ‘z’ or whatever you like, and write Z:\ as the path to the directory. Stop and run Apache, with your browser you should be able to access to http://forums.xisto.com/no_longer_exists/ ------------------------------------------------------------------------
  7. The purpose of this short tutorial – my first one – is to help you to manage your web laboratory, combining online and offline stuffs, and switch easily between virtual and real host using the same address. Let’s say that you want to test in a safe and clean way some codes in your own PC before to upload them to the web. Your websites use external stuff, like fonts, javascripts, datas or whatever offered by Google, Bloomberg or Facebook, and are located to their websites. The question is: how to switch easily between the testing environment (the virtual host located in your PC, only accessible to you) and real host (located in the real world, the Web), and reverse using the same address: ‘yoursite.com’? Half answer is: the latest version of EasyPHP includes an optional module called ‘Virtual Hosts Manager’. It’s perfects for simple needs and is easy to install... but it has some issues that makes it useless. We'll solve this here. At first you’ll have to install once the environment Server in your PC, then we'll see how to create in 3 easy steps your web laboratory with as many domains and subdomains as you wish into your computer, and switch between virtual and real web, __________________________________________________________________________ Installation and configuration of your WAMP __________________________________________________________________________ Install your WAMP – Windows Apache MySQL PHP Goal: to get a virtual web server environment full featured in you PC. Go to http://www.easyphp.org/ and install the version and modules of your choice. (Wordpress, Drupal, Prestashop, Joomla, etc.) By default it will be installed in this folder: C:Program FilesEasyPHP-12.1 Note: if you want to install it elsewhere, make sure to do the appropriate modifications in the further steps. __________________________________________________________________________ Install the Virtual Hosts Manager in your WAMP Goal: configure your WAMP to support Virtual Hosts Go to http://www.easyphp.org/ to get the latest Virtual Hosts Manager, or download it directly using this link: http://forums.xisto.com/no_longer_exists/ Install it in the same folder as EasyPHP: C:Program FilesEasyPHP-12.1 In the EasyPHP program, make sure that Apache is running and go to ‘Administration’, or press the touches ‘ctrl+A’, or go directly in your browser to: http://forums.xisto.com/no_longer_exists/ (If it doesn’t work, do the appropriate changes as described in the next step, and come back here) In the list of modules, you’ll see Virtual Hosts Manager, and at it’s left a button saying ‘add virtual host’. Feel free to use it, personally I avoid it. This module doesn’t offer all the flexibility and liability that you deserve, you’ll probably get several heavy warning messages while you use it, and switching often between virtual and real Host may become a nightmare when you do many tests, instead of exiting as it should be: it doesn’t activate/deactivate virtual hosts properly. But, if it works well enough for you and meets all your needs, you can use it ‘as is’ and won’t need to walk through the further steps. At this point: We installed a module that alouds easyPhp to support Virtual Hosting. __________________________________________________________________________ Apache - Edit the port of your localhost Goal: simplify the configuration of your localhost Make a backup and open the Apache configuration file: C:Program FilesEasyPHP-12.1conf_fileshttpd.conf Go to the row 62, normally you should see this: Listen 127.0.0.1:80 Then it’s ok and you can go to the next step. Otherwise, if you see something like: Listen 127.0.0.1:8887 Below this row, add this one: Listen 127.0.0.1:80 Note: if you want to deactivate this for whatever reason, you can comment this row just adding a ‘#’ at the beginning of the row. At this point: now you can access to your localhost just typing 127.0.0.1 in your browser and will be able to edit properly the hosts file as described below. __________________________________________________________________________ The 3 easy Steps to configure your Virtual Hosts __________________________________________________________________________ Step 1: Edit your ‘Hosts’ file Goal: redirect ‘yoursite.com’ to your localhost With Wordpad, open the file: C:WINDOWSsystem32driversetchosts It’s a file without extension, make first a backup copy. Add the following row to your ‘hosts’ file: 127.0.0.1 yoursite.com Optional tip: If you want to access to your localhost just typing ‘localhost’, then add this row if it’s missing: 127.0.0.1 localhost Save your modifications and make sure that your text editor didn’t add a ‘.txt’ extension to your file, otherwise it won’t work, and that’s why I recommend Wordpad to do it. At this point, if you visit ‘yoursite.com’ with your browser, you should access to the contents of your ‘localhost’ witch files are located in your PC. __________________________________________________________________________ Step 2: Apache - Create a configuration file for ‘yoursite.com’ Goal: define the specific folder for ‘yoursite.com’ in your localhost First, create the main folder for your offline works: C:Program FilesEasyPHP-12.1wwwyoursite Now, open the Apache configuration folder C:Program FilesEasyPHP-12.1apacheconf Create a new text file and add the following rows: <VirtualHost 127.0.0.1> DocumentRoot "C:/Program Files/EasyPHP-12.1/www/yoursite" ServerName yoursite.com <Directory "C:/Program Files/EasyPHP-12.1/www/yoursite"> Options FollowSymLinks Indexes AllowOverride All Order deny,allow Allow from 127.0.0.1 Deny from all Require all granted </Directory> </VirtualHost> Note: be aware, Apache makes a difference between ‘/’ and ‘’ Save this file as: C:Program FilesEasyPHP-12.1apacheconfyoursite.conf At this point: you just created a configuration file for the Apache server that you can activate/deactivate in the next step. __________________________________________________________________________ Step 3: Apache – Activate your configuration file Goal: Activate the configuration of your Virtual Host in you local server With your text editor, open the Apache configuration file: C:PROGRAM FILESEASYPHP-12.1conf_fileshttpd.conf At the end of the file, add the following row: Include conf/yoursite.conf Important: with your EasyPhp console, first: STOP Apache, then: START Apache, just restarting may not always work properly either. At this point: if you visit ‘yoursite.com’ with your browser, you’ll access to the empty file you just created for your virtual host. __________________________________________________________________________ How to Activate/Deactivate Virtual Hosts Like in Step 1, open your ‘Hosts’ file, and then, to deactivate, the Virtual Host of your choice just add a ‘#’ at the beginning of it’s row, and save it. To reactivate it, just remove the ‘#’: # 127.0.0.1 yoursite.com Then you’ll access directly to the web. Note: Apache doesn’t need to restart, as you don’t need to touch the configuration files. __________________________________________________________________________ Conclusion Now you can install and test everything you wish safely and combine online and offline stuffs using the same address, and switch easily between your online and offline websites, just adding or removing a ‘#’ from your ‘Hosts’ file. It may seem tricky in a first view, but the result is very simple, quick and reliable. Note: This is my first tutorial, if you find whatever mistake, something unclear, know a better way to do or say it, I will really appreciate.
  8. I have had my website hosted with Xisto for over two years now. The plan is a shared hosting plan, which I have no complaints about. But recently I ran into a problem that made my wonder the structure of shared hosting and allaction of resources to various hosted websites. The exact problem is that I am getting this strange error in the admin section of my wordrpress based website when I try to view all the pages I have created. Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 4096 bytes) in /home/mananato/public_html/wp-includes/cache.php on line 505 I did some research about the issue and about the possible solutions for it. What I came to know is that I am getting this error because the memory allocated to my website is not enough any more and I need to increase it to a reasonable value. And to solve this error, I need to increase the memory allocated to php that my website uses. This thing has made me think about a lot of questions like: How is memory allocated to different services in a shared hosting scenario? Does a shared hosting scenario have a single or multiple installs of required tools like php, mysql? Whether the installation of tools is single or multiple, how are the resources of the server distributed? What are the effects of increasing the resources to a service on other services hosted on the same shared server? And many more....... So I decided to open a topic about it and place it in the "Internet and Websites" category so that it becomes a general issue that is not related to my website or Xisto. Any productive addition to the topic is appreciated.
  9. I got this code from this form.. from developer... who posted but he is nt replying me anything for any update so i like to do open discussion so it can make workable code.. please... First of all when i setup everything correct..... while using admin: admin and password : password and i hit login... nothing hppns stays same page, now when i enter ip and click yes to block i recievied this error "Could not Block Ip, MySql Error" ok.... after this was nt working i went to mysql db and entered ip and time by manually in that table.. now i visited .. the ipadmin.php again.. now same problem.. except.. in blocked ip list... i can see the ip added. hence my db is working connected to ... now when i select 1 ip and try to remove.. again it doesnt do anything.. ip remains der.. please some1 try this code... its very easy .. but very useful... and help me to fix the issue.. thank you the First thing we are going to do is make the form that is actually blocking the site. Note: You Must have this in a PHP file to work, it must be at the VERY TOP!!!!! klist.php ][color=#666600]<?[/color][color=#000000]php[/color][color=#000000]$vip [/color][color=#666600]=[/color][color=#000000] $_SERVER[/color][color=#666600][[/color][color=#008800]'REMOTE_ADDR'[/color][color=#666600]];[/color][color=#000000]include [/color][color=#008800]"config.php"[/color][color=#666600];[/color][color=#880000]##############################[/color][color=#880000]# See if the Ip is in the blocked list #[/color][color=#880000]##############################[/color][color=#000000]$get_info [/color][color=#666600]=[/color][color=#000000] mysql_query[/color][color=#666600]([/color][color=#008800]"SELECT * FROM blocked WHERE ip = '$vip'"[/color][color=#666600]);[/color][color=#000000]$do_block [/color][color=#666600]=[/color][color=#000000] mysql_fetch_array[/color][color=#666600]([/color][color=#000000]$get_info[/color][color=#666600]);[/color][color=#880000]############################################[/color][color=#880000]# Now we are just checking to see if we need to block the user #[/color][color=#880000]############################################[/color][color=#000000] [/color][color=#000088]if[/color][color=#666600]([/color][color=#000000] $do_block[/color][color=#666600][[/color][color=#008800]'ip'[/color][color=#666600]][/color][color=#000000] [/color][color=#666600]==[/color][color=#000000] [/color][color=#008800]"$vip"[/color][color=#000000] [/color][color=#666600]){[/color][color=#000000] [/color][color=#000088]die[/color][color=#666600]([/color][color=#008800]"Sorry! Your Ip has been blocked from viewing our sites content"[/color][color=#666600]);[/color][color=#666600]}[/color][color=#666600]?>[/color] The above just save it however you want to... I would recommend ipblochp before that works we need to create the table inside of a database that will have the ip's stored inside of them So in phpMyAdmin or your MySql Query Window type in USE 'databasename'; Excute it... CREATE TABLE blocked( id int not null auto_increment primary key, ip varchar(15), added datetime); Excute... Now you are set up! Ok, Good Job on the MySql Database set up... Now, we need to create a config file which will store how we are connecting and what database we are using [color=#666600]<?[/color][color=#000000]php[/color][color=#880000]#########################[/color][color=#880000]# Config File #[/color][color=#880000]#########################[/color][color=#000000]$dbhost [/color][color=#666600]=[/color][color=#000000] [/color][color=#008800]"localhost"[/color][color=#666600];[/color][color=#000000] [/color][color=#880000]// This is your database host name usally localhost[/color][color=#000000]$dbuser [/color][color=#666600]=[/color][color=#000000] [/color][color=#008800]"user"[/color][color=#666600];[/color][color=#000000] [/color][color=#880000]// This is your database user name...[/color][color=#000000]$dbpass [/color][color=#666600]=[/color][color=#000000] [/color][color=#008800]"pass"[/color][color=#666600];[/color][color=#000000] [/color][color=#880000]// this is your password used to login to the database[/color][color=#000000]$dbname [/color][color=#666600]=[/color][color=#000000] [/color][color=#008800]"database"[/color][color=#666600];[/color][color=#000000] [/color][color=#880000]// this is your database name.[/color][color=#880000]##########################[/color][color=#880000]# Edit the above to suit your needs ##[/color][color=#880000]##########################[/color][color=#000000] $conn [/color][color=#666600]=[/color][color=#000000] mysql_connect[/color][color=#666600]([/color][color=#008800]"$dbhost"[/color][color=#666600],[/color][color=#008800]"$dbuser"[/color][color=#666600],[/color][color=#008800]"$dbpass"[/color][color=#666600]);[/color][color=#000000] mysql_select_db[/color][color=#666600]([/color][color=#008800]"$dbname"[/color][color=#666600],[/color][color=#000000] $conn [/color][color=#666600]);[/color][color=#666600]?>[/color] Then Your Done... I would save this as config.php because thats what we imported into our ip checker file (e.g. inlcude "config.php"; ) Ok, as I said you need to put this line of code on your first line after <?php or if you are using session_start(); after that it's should like this [color=#666600]<?[/color][color=#000000]phpinclude [/color][color=#008800]"ipblocklist.php"[/color][color=#666600];[/color][color=#880000]// The rest of your code[/color][color=#666600]?>[/color][color=#282828][font=helvetica, arial, sans-serif]Now, it's time to make a admin type area so you can add or remove blocked Ip's...[/font][/color][color=#666600]<?[/color][color=#000000]phpsession_start[/color][color=#666600]();[/color][color=#880000]#####################[/color][color=#880000]# Get the Config File #[/color][color=#880000]#####################[/color][color=#000000]include [/color][color=#008800]"config.php"[/color][color=#666600];[/color][color=#880000]#########################[/color][color=#880000]# Set the admin credentials # [/color][color=#880000]#########################[/color][color=#000000]$admin [/color][color=#666600]=[/color][color=#000000] [/color][color=#008800]'admin'[/color][color=#666600];[/color][color=#000000]$pass [/color][color=#666600]=[/color][color=#000000] [/color][color=#008800]'password'[/color][color=#666600];[/color][color=#000000]$s_user [/color][color=#666600]=[/color][color=#000000] $_POST[/color][color=#666600][[/color][color=#008800]"admin"[/color][color=#666600]];[/color][color=#000000]$s_pass [/color][color=#666600]=[/color][color=#000000] $_POST[/color][color=#666600][[/color][color=#008800]"pass"[/color][color=#666600]];[/color][color=#000088]if[/color][color=#666600]([/color][color=#000000] $ses_user [/color][color=#666600]<=[/color][color=#000000] [/color][color=#008800]" "[/color][color=#000000] [/color][color=#666600]){[/color][color=#880000]#########################[/color][color=#880000]# Admin Login Form #[/color][color=#880000]#########################[/color][color=#000000]echo [/color][color=#008800]"<form action='ipadmin.php' method='post'>"[/color][color=#666600];[/color][color=#000000]echo [/color][color=#008800]"Admin: <input type='text' name='admin'><br>"[/color][color=#666600];[/color][color=#000000]echo [/color][color=#008800]"Pass: <input type='password' name='pass'><br>"[/color][color=#666600];[/color][color=#000000]echo [/color][color=#008800]"<input type='submit' value='Login'>"[/color][color=#666600];[/color][color=#000000]echo [/color][color=#008800]"</form>"[/color][color=#666600];[/color][color=#666600]}[/color][color=#000000] [/color][color=#000088]if[/color][color=#666600]([/color][color=#000000] $s_user [/color][color=#666600]==[/color][color=#000000] $admin [/color][color=#000088]and[/color][color=#000000] $s_pass [/color][color=#666600]==[/color][color=#000000] $pass [/color][color=#666600]){[/color][color=#000000] $ses_user [/color][color=#666600]=[/color][color=#000000] $_SESSION[/color][color=#666600][[/color][color=#008800]'admin'[/color][color=#666600]][/color][color=#000000] [/color][color=#666600]=[/color][color=#000000] $s_pass[/color][color=#666600];[/color][color=#000000] $go [/color][color=#666600]=[/color][color=#000000] [/color][color=#006666]1[/color][color=#666600];[/color][color=#666600]}[/color][color=#000088]if[/color][color=#666600]([/color][color=#000000] $go [/color][color=#666600]=[/color][color=#000000] [/color][color=#006666]1[/color][color=#000000] [/color][color=#666600]){[/color][color=#000000]echo [/color][color=#008800]"Add a Ip to the Blocked List"[/color][color=#666600];[/color][color=#000000]echo [/color][color=#008800]"<form action='ipadmin.php' method='post'>Ip: <input type='text' name='ip'><input type=submit value='Block Ip'></form>"[/color][color=#666600];[/color][color=#666600]}[/color][color=#000088]if[/color][color=#666600]([/color][color=#000000] $_POST[/color][color=#666600][[/color][color=#008800]"ip"[/color][color=#666600]][/color][color=#000000] [/color][color=#666600]>[/color][color=#000000] [/color][color=#008800]" "[/color][color=#000000] [/color][color=#666600]){[/color][color=#000000]$ip2 [/color][color=#666600]=[/color][color=#000000] $_POST[/color][color=#666600][[/color][color=#008800]"ip"[/color][color=#666600]];[/color][color=#000000]echo [/color][color=#008800]"Are you sure you want to block $ip2"[/color][color=#666600];[/color][color=#000000]echo [/color][color=#008800]"<form action='ipadmin.php' method='post'><input type='hidden' name='ip2' value='$ip2'><input type='submit' name='block' value='yes'>"[/color][color=#666600];[/color][color=#666600]}[/color][color=#000088]if[/color][color=#666600]([/color][color=#000000] $_POST[/color][color=#666600][[/color][color=#008800]"block"[/color][color=#666600]][/color][color=#000000] [/color][color=#666600]==[/color][color=#000000] [/color][color=#008800]"yes"[/color][color=#000000] [/color][color=#666600]){[/color][color=#000000] mysql_query[/color][color=#666600]([/color][color=#008800]"INSERT INTO blocked SET ip = '$ip2' added = NOW()"[/color][color=#666600])[/color][color=#000000] [/color][color=#000088]or[/color][color=#000000] [/color][color=#000088]die[/color][color=#666600]([/color][color=#008800]"Could not Block Ip, MySql Error"[/color][color=#666600]);[/color][color=#666600]}[/color][color=#000000]echo [/color][color=#008800]"<center>Remove Blocked Ips<br><br>"[/color][color=#666600];[/color][color=#000000]echo [/color][color=#008800]"<form action='ipadmin.php' method='post'><select name='remove'><option value=''>Select One</option>"[/color][color=#666600];[/color][color=#000000]$ips [/color][color=#666600]=[/color][color=#000000] mysql_query[/color][color=#666600]([/color][color=#008800]"SELECT * FROM blocked"[/color][color=#666600]);[/color][color=#000088]while[/color][color=#666600]([/color][color=#000000] $showips [/color][color=#666600]=[/color][color=#000000] mysql_fetch_array[/color][color=#666600]([/color][color=#000000]$ips[/color][color=#666600])){[/color][color=#000000]$ip_value [/color][color=#666600]=[/color][color=#000000] $showips[/color][color=#666600][[/color][color=#008800]'ip'[/color][color=#666600]];[/color][color=#000000]echo [/color][color=#008800]"<option value='$ip_value'>$ip_value</option>"[/color][color=#666600];[/color][color=#666600]}[/color][color=#000000]echo [/color][color=#008800]"<input type='submit' value='RemoveIp' name='Remove Ip'>"[/color][color=#666600];[/color][color=#000000]echo [/color][color=#008800]"</form>"[/color][color=#666600];[/color][color=#000088]if[/color][color=#666600]([/color][color=#000000] $_POST[/color][color=#666600][[/color][color=#008800]"Remove Ip"[/color][color=#666600]][/color][color=#000000] [/color][color=#666600]==[/color][color=#000000] [/color][color=#008800]"RemoveIp"[/color][color=#000000] [/color][color=#666600]){[/color][color=#000000]$del_ip [/color][color=#666600]=[/color][color=#000000] $_POST[/color][color=#666600][[/color][color=#008800]'remove'[/color][color=#666600]];[/color][color=#000000]mysql_query[/color][color=#666600]([/color][color=#008800]"DELETE FROM blocked WHERE ip = '$del_ip' LIMIT 1"[/color][color=#666600]);[/color][color=#000000]echo [/color][color=#008800]"The Ip $del_ip has been removed from the blocked list!"[/color][color=#666600];[/color][color=#666600]}[/color][color=#666600]?>[/color] OK now save that above as ipadmin.php Everything Should work succesfully any question
  10. I need help with my PHP form validation as it isn't showing they have been successful registering and also errors not showing if they don't enter email etc. There it is. If there is a better solution you can tell me i will be very happy :-) Thanks <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[url="https://w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"]http://www.w3.org/TRtml1-strict.dtd;<html xmlns="[url="https://w3.org/1999/xhtml"]http://www.w3.org/1999/xhtml/; xml:lang="en" lang="en"><head><title>Sign Up to our Mailing List!</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body><?php//arrays$output = '';$cleans = array();//checks submitif (isset($_POST['submit']) && $_POST['submit'] != 'Logout'){ if (isset ($_POST['First Name'])) { ($_POST['First Name']) trim($_POST['First Name']); // only allowed alphanumeric characters $nospaces = str_replace(' ', '', $_POST['First Name']); if($_POST['First Name'] != '' && ctype_alpha) { $cleans['First Name'] = $_POST['First Name']; } $output .= '<p>First Name: '.htmlentities [$clean['First Name']).'</p>'; else { $output .= 'First Name is required with alphanumeric characters.'; }} else {$output .= '<p>First Name: Not submitted</p>'; // alphabet characters only if (isset ($_POST['Last Name'])){ $_POST['Last Name'] = trim($_POST['Last Name']); $nospaces = str_replace(' ', '', $_POST['Last Name']); if($_POST['Last Name'] != '' && ctype_alpha) { $cleans['Last Name'] = $_POST['Last Name']; $output .= '<p>Last Name: '.htmlentities [$clean['Last Name']).'</p>';} else { $output .= 'Last Name is required.'; }//making sure @ is inserted if (isset ($_POST['Email address'])) {$_POST['Email address'] = trim($_POST['Email address']) : ''); $email_parts = explode([email=""]'@'[/email], $_POST['Email address']); $num_email_parts = count ($email_parts); if ($num_email_parts == 2) { { $email_domain = $email_parts[1]; if (strpos($email_domain, '.') !== false) { { $cleans['Email address'] = $_POST['Email address']; $output .= '<p>Email address: '.htmlentities($clean['Email address']).'</p>'; } else { $output .= '<p>Your email is not correct please try again.'</p>; } } else { $output .= 'Incorrect email.'; } $_POST['Username'] = (isset($_POST['Username']) ? trim($_POST['Username']) : ''); if($_POST['Username'] != '' && ctype_alnum) { $cleans['Username'] = $_POST['Username']; } else { $output .= 'Please supply username with alphnumeric character.'; }//correctly formatted $_POST['password'] = (isset($_POST['password']) ? trim($_POST['password']) : ''); // allows the alphnumeric characters if($_POST['password'] != ' ' && ctype_alnum( $_POST['password'])) { $cleans['password'] = $_POST['password']; } else { $output .= <p>'Please use alphnumiric characters.'</p>; }}$output = '';// counts errors{ if ($_POST['submit'] == 'Logout') { // Time line set $output .= ""; unset($_SESSION['Username']); $_SESSION = array(); setcookie('Username','',time()-42000); $_COOKIE = array(); session_destroy(); header("Location: logout.php"); } else { // writes into file and closes $handle = fopen('..user.txt','a'); if(!$handle){ echo " Please try later"; die(); } fwrite($handle, $info); fwrite($handle, "n"); fclose($handle); setcookie('Username',$cleans['Username']); $_SESSION['Username'] = $cleans['Username'];?><h5><?php echo "Thank you for registering with us. Now please log in.";?> <meta http-equiv="Refresh" content="5;URL=logon.php"></h5> <?php }}else{// counts errors and produces some security { { $output .= '<li>'.htmlentities($data).'</li>'; } $output .= '</ul>'; } $output .= '<form action="'.htmlentities($_SERVER['PHP_SELF']).'" method="post"> <fieldset>'; if(!isset($_SESSION['Username'])) {?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/1999/xhtml/; xml:lang="en" lang="en"><head><title>Registered Page</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body><!--Navigation starts here....--><h1>Welcome</h1><a href="page1.php"> Page 1</a> <a href="page2.php">Page 2</a> <a href="page3.php">Page 3</a><?php //form included in the php page $output .= ' <form>; First Name: <input type="text" name="First Name"/><br/> Last Name: <input type="text" name="Last Name" /><br /> <label for="ea">Email address:</label><input type="text" name="Email address"/><br> Username:<input type="text" name="Username"/><br <label for="password">Password:</label><input type="password"name="password"id="password"size="20" /> <input type="submit" name="submit" value="Register" />'; } if (isset($_SESSION['Username'])) { $output .= '<input type="submit" name="submit" value="Logout" />'; } $output .= '</fieldset> </form>';}echo $output;?></body></html>
  11. I am trying to get into the Object Oriented Programming (OOP) in the PHP. For this I have installed a local apache server to test my work and experiment with my scripting techniques. Until today everything was going fine and my learning speed was good. But I have come to face a problem to which I have no answer. I am trying to create a user class for a test project. The code of the user class is as follows: <?phprequire_once("database.php");class User {public $id;public $username;public $password;public $first_name;public $last_name;public static function find_all() { return self::find_by_sql("select * from users");}public static function find_by_id($id=0) { global $database; $result_array=self::find_by_sql("Select * from users where id={$id} limit 1"); if (!empty($result_array)) { return array_shift($result_array); } else { return FALSE; }}public function find_by_sql($sql="") { global $database; $result_set=$database->query($sql); $object_array=array(); while ($row=$database->fetch_array($result_set)) { $object_array[]=self::instantiate($row); } return $object_array;}public function full_name() { if (isset($this->first_name)&& isset($this->last_name)) { return $this->first_name." ".$this->lastname; } else { return ""; }}private static function instantiate($record) { $object=new self; $object->id=$record['id']; $object->username=$record['username']; $object->passwrod=$record['password']; $object->first_name=$record['first_name']; $object->last_name=$record['last_name']; return $object;}}?> As you can see in the code, I have created a User class with few attributes and methods. The code is clean and there is no problem in it. On the index page, I have the following code: $user=User::find_by_id(1);echo $user->full_name(); Theoretically, the code should return the full name of a user but instead when I run the code, I get the following error: ( ! ) Fatal error: Call to a member function full_name() on a non-object in C:\wamp\www\imagepro\public\index.php on line 8Call Stack# Time Memory Function Location1 0.0014 669408 {main}( ) ..\index.php:0 And I don't understand why I am getting this error. It says that I am making a call to an object function from a non-object. But as per the code in the instantiate method of the user class, the object should get automatically instantiated. I have spend more than an hour just to figure out any mistake in the code but I am unable to find it. So the last guess that is left with me is that there are some settings that I need to change in the php.ini file on my localhost. Any help from the experts is appreciated. Thanks in advance
  12. dhi

    Cron Job

    hello phpgeeks, I have created a php file which i want to run in the background even if my site is not used by any1. How to add this file in cron job using c-panel of linux hosting.
×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.