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/

Starting XAMPP server on Ubuntu Linux

To start XAMPP server on Ubuntu Linux follow the below steps


After installing xampp on Linux or Ubuntu
1.Open the Terminal

2.Execute this command "/opt/lampp/lampp start "

Once this command is run First server(apache) would be started then SQL,FTP  would be started After than ,Check it in your browser by typing http://localhost/


Connected to Internet but browser won't work

Sometimes you may be connected to internet but your browser won’t work

To solve this issue, Follow these steps

a)You have to un-install any ad-ware software

b)You have to run these commands in “CMD” (Command prompt)

c)Resetting WinSock and TCP/IP to defaults: TCP/IP stack repair options for use with Windows XP with SP2.* * For these commands, *Start,Run, CMD, OK* to open a command prompt. 

d)Reset WINSOCK entries to installation defaults: netsh winsock reset catalog Type this in command prompt and press enter 

e)Reset TCP/IP stack to installation defaults. *netsh int ip reset reset.log* Type this in command promt and press enter Now again connect to internet it would work now.

Restarting XAMPP Apache server using command prompt

To restart the XAMPP service using command prompt simply follow the below steps

Steps:
1.Go to the directory where you have installed XAMPP (C:\Program Files\xampp\)

2. To start or stop the apache server,Click on apache_start.cmd or apache_stop.cmd 

To do it from the command prompt
1.Open command prompt 

2.Go the folder where you have installed command prompt 

3.Run 'apache_start.cmd' for starting the apache and 'apache_stop.cmd' for stopping the apache