Monday 28 November 2011

Base64 encoding and decoding in Php

To encode a string in base64 you need to use the below code Base64 encoding
$a="Shan"; $b=base64_encode($a); echo $b
Base 64 decoding $c=base64_decode($b); echo $c

Monday 21 November 2011

Restarting a machine via command prompt

To restart a machine via command prompt you just need to the follow the below steps listed below

1.Go to Start -> Run and Type 'cmd' and click on 'OK'

2.Once the command prompt window opens up type the below command

shutdown -r -f -t 5


or you can just go

1.Go to Start-> Run and type 'shutdown -r -f -t 5'

Where
r ----> stands for restart
f ----> forceful Shutdown/restart
t ----> no of seconds the system has to wait (A pop will showup)

Shutting down a machine via command prompt

To shut down a machine via command prompt you just need to the follow the below steps listed below

1.Go to Start -> Run and Type 'cmd' and click on 'OK'

2.Once the command prompt window opens up type the below command

shutdown -s -f -t 5

Where
s ----> stands for Shutdown for Restart use r
f ----> forceful Shutdown
t ----> no of seconds the system has to wait (A pop will showup)






Friday 18 November 2011

Python code for inserting a row into MySQL database

Here is the code that can be used to insert a row into MySQL using Python

#!C:/Python25/python.exe -u
import MySQLdb print "Content-type: text/html" db=MySQLdb.connect(host="localhost",user="xxxx",passwd="",db="xxxxxx") cursor=db.cursor() \
import socket \
timeout=10
a=1
socket.setdefaulttimeout(timeout)
from urllib2 import Request, urlopen, URLError, HTTPError
url="http://www.rediff.com"
req = Request(url)
try:
response = urlopen(req)
except:
print 'error'

the_page=response.read()
no=1
cursor.execute('INSERT INTO testing values("%s","%s")' % \ (no,the_page))

Apache server in XAMPP not starting

If your Apache server is Xampp is not starting there might be a host of problems Instead of starting it via Xampp control panel ,I would better suggest you to start via command prompt

Step 1
Open the command prompt and go to C:/Program Files/Xampp directory (whereever xampp is installed,In this case my default directory is the above one)

Step 2:
Execute this command apache_start  and you may get the error message or what prevents apache from starting.  


Step 3: From the screenshot above ,we can clearly infer that the problem is with the http.conf file (Xampp/apache/bin/)and in addition of virtual hosts.So edit it and rerun the command again to get apache started in Xampp

Apache may not start because of these reasons
a)httpd.conf  - Incorrect format for Virtual hosts

b)Clash of port numbers with another program see this post to know more details about it if you have the second problem

Adding a subdomain in XAMPP

Adding a subdomain in Xampp
Follow the below steps to Add a subdomain in Xampp
1.Open the file "http-vhosts" in a text editor from the below location /Xampp/Apache/conf/extra/

2.Uncomment this line # NameVirtualHost *:80 To uncomment a line (just remove # in the line)

3.Then to add a subdomain add these lines at the end of file DocumentRoot
"C:/Program Files/Xampp/htdocs/site/" ServerName site1.com

4.You can additional options with Virtual host like the below
Server Admin shan@shan.com
DocumentRoot "C:/Program Files/Xampp/htdocs/site/"
ServerName site1.com Server alias site1.com
Error log "C:/Program Files/Xampp/htdocs/site/a2.log"
Transfer log "C:/Program Files/Xampp/htdocs/site/a1.log"

Default username and passwords in XAMPP

Please find below the list of default username and passwords in XAMPP

MySQL:
username: root

password: " " (blank)

You can change the password for MySQL by logging into PhpMyAdmin and changing the default password for Root user.Also you can create new users with appropriate privileges for them along with the passwords

FTP
username: root

password: " "(blank)
Sameway you can log into the local FTP server by clicking on Admin link from XAMPP control panel and change your password.




PhpMyAdmin

username: root

password: " "(blank)

You can access PhpMyAdmin by this url http://localhos/phpmyadmin/