存档

文章标签 ‘操作系统’

修改Ubuntu启动菜单 - 使XP变为默认操作系统

2007年11月29日 渴慕晨光 没有评论

装了Ubuntu和XP双系统后,变得很麻烦,每次都得在启动菜单上选来选去,浪费了不少时间,而且万一那次想进windows,结果开机的时候忘记了,那就更加令人头疼了。
想修改使XP成为默认的操作系统,其实很简单,修改 /boot/grub/menu.lst 文件,使其中default值变动一下即可。
过程如下:

1、 打开命令行终端;
2、输入:
sudo cp /boot/grub/menu.lst /boot/grub/menu.lst.bak //第一句做备份用。
sudo gedit /boot/grub/menu.lst
3、假设文件内容如下:
======================================
# menu.lst - See: grub(8), info grub, update-grub(8)
#            grub-install(8), grub-floppy(8),
#            grub-md5-crypt, /usr/share/doc/grub
#            and /usr/share/doc/grub-doc/.

## default num
# Set the default entry to the entry number NUM. Numbering starts from 0, and
# the entry number 0 is the default if the command is not used.
#
# You can specify 'saved' instead of a number. In this case, the default entry
# is the entry saved with the command 'savedefault'.
# WARNING: If you are using dmraid do not change this entry to 'saved' or your
# array will desync and will not let you boot your system.
default        6

## timeout sec
# Set a timeout, in SEC seconds, before automatically booting the default entry
# (normally the first entry defined).
timeout        10

## hiddenmenu
# Hides the menu by default (press ESC to see the menu)
#hiddenmenu

# Pretty colours
#color cyan/blue white/blue

## password ['--md5'] passwd
# If used in the first section of a menu file, disable all interactive editing
# control (menu entry editor and command-line)  and entries protected by the
# command 'lock'
# e.g. password topsecret
#      password --md5 $1$gLhU0/$aW78kHK1QfV3P2b2znUoe/
# password topsecret

#
# examples
#
# title        Windows 95/98/NT/2000
# root        (hd0,0)
# makeactive
# chainloader    +1
#
# title        Linux
# root        (hd0,1)
# kernel    /vmlinuz root=/dev/hda2 ro
#

#
# Put static boot stanzas before and/or after AUTOMAGIC KERNEL LIST

### BEGIN AUTOMAGIC KERNELS LIST
## lines between the AUTOMAGIC KERNELS LIST markers will be modified
## by the debian update-grub script except for the default options below

## DO NOT UNCOMMENT THEM, Just edit them to your needs

## ## Start Default Options ##
## default kernel options
## default kernel options for automagic boot options
## If you want special options for specific kernels use kopt_x_y_z
## where x.y.z is kernel version. Minor versions can be omitted.
## e.g. kopt=root=/dev/hda1 ro
##      kopt_2_6_8=root=/dev/hdc1 ro
##      kopt_2_6_8_2_686=root=/dev/hdc2 ro
# kopt=root=UUID=2d1136cb-416a-4329-8c6d-703537a2d578 ro

## Setup crashdump menu entries
## e.g. crashdump=1
# crashdump=0

## default grub root device
## e.g. groot=(hd0,0)
# groot=(hd0,7)

## should update-grub create alternative automagic boot options
## e.g. alternative=true
##      alternative=false
# alternative=true

## should update-grub lock alternative automagic boot options
## e.g. lockalternative=true
##      lockalternative=false
# lockalternative=false

## additional options to use with the default boot option, but not with the
## alternatives
## e.g. defoptions=vga=791 resume=/dev/hda5
# defoptions=quiet splash locale=zh_CN

## should update-grub lock old automagic boot options
## e.g. lockold=false
##      lockold=true
# lockold=false

## Xen hypervisor options to use with the default Xen boot option
# xenhopt=

## Xen Linux kernel options to use with the default Xen boot option
# xenkopt=console=tty0

## altoption boot targets option
## multiple altoptions lines are allowed
## e.g. altoptions=(extra menu suffix) extra boot options
##      altoptions=(recovery) single
# altoptions=(recovery mode) single

## controls how many kernels should be put into the menu.lst
## only counts the first occurence of a kernel, not the
## alternative kernel options
## e.g. howmany=all
##      howmany=7
# howmany=all

## should update-grub create memtest86 boot option
## e.g. memtest86=true
##      memtest86=false
# memtest86=true

## should update-grub adjust the value of the default booted system
## can be true or false
# updatedefaultentry=false

## ## End Default Options ##

title        Ubuntu, kernel 2.6.20-16-generic
root        (hd0,7)
kernel        /boot/vmlinuz-2.6.20-16-generic root=UUID=2d1136cb-416a-4329-8c6d-703537a2d578 ro quiet splash locale=zh_CN
initrd        /boot/initrd.img-2.6.20-16-generic
quiet
savedefault

title        Ubuntu, kernel 2.6.20-16-generic (recovery mode)
root        (hd0,7)
kernel        /boot/vmlinuz-2.6.20-16-generic root=UUID=2d1136cb-416a-4329-8c6d-703537a2d578 ro single
initrd        /boot/initrd.img-2.6.20-16-generic

title        Ubuntu, kernel 2.6.20-15-generic
root        (hd0,7)
kernel        /boot/vmlinuz-2.6.20-15-generic root=UUID=2d1136cb-416a-4329-8c6d-703537a2d578 ro quiet splash locale=zh_CN
initrd        /boot/initrd.img-2.6.20-15-generic
quiet
savedefault

title        Ubuntu, kernel 2.6.20-15-generic (recovery mode)
root        (hd0,7)
kernel        /boot/vmlinuz-2.6.20-15-generic root=UUID=2d1136cb-416a-4329-8c6d-703537a2d578 ro single
initrd        /boot/initrd.img-2.6.20-15-generic

title        Ubuntu, memtest86+
root        (hd0,7)
kernel        /boot/memtest86+.bin
quiet

### END DEBIAN AUTOMAGIC KERNELS LIST

# This is a divider, added to separate the menu items below from the Debian
# ones.
title        Other operating systems:
root

# This entry automatically added by the Debian installer for a non-linux OS
# on /dev/sda1
title        Microsoft Windows XP Professional
root        (hd0,0)
savedefault
makeactive
chainloader    +1
-------------------------------------------------------------
原本的default值为0,意即启动排行第一的操作系统,这里代表的就是title        Ubuntu, kernel 2.6.20-16-generic。
现在把它修改成“default 6”,那么XP就成为默认的操作系统了。
因为从零数起,以title打头的Microsoft Windows XP Professional这一行排序为6。
还可以通过修改timeout的值来变更默认等待时间。


php取得客户端(浏览器/IP/操作系统) 信息

2007年10月15日 渴慕晨光 没有评论

把下面的代码保存成类.

PHP代码
  1. <?php class clientGetObj   
  2. {   
  3. function getBrowse()   
  4. {   
  5. global $_SERVER;   
  6. $Agent = $_SERVER['HTTP_USER_AGENT'];   
  7. $browser = '';   
  8. $browserver = '';   
  9. $Browser = array('Lynx''MOSAIC''AOL''Opera''JAVA''MacWeb''WebExplorer''OmniWeb');   
  10. for($i = 0; $i <= 7; $i ++){   
  11. if(strpos($Agent$Browsers[$i])){   
  12. $browser = $Browsers[$i];   
  13. $browserver = '';   
  14. }   
  15. }   
  16. if(ereg('Mozilla'$Agent) && !ereg('MSIE'$Agent)){   
  17. $temp = explode('('$Agent);   
  18. $Part = $temp[0];   
  19. $temp = explode('/'$Part);   
  20. $browserver = $temp[1];   
  21. $temp = explode(' '$browserver);   
  22. $browserver = $temp[0];   
  23. $browserver = preg_replace('/([d.]+)/''1'$browserver);   
  24. $browserver = $browserver;   
  25. $browser = 'Netscape Navigator';   
  26. }   
  27. if(ereg('Mozilla'$Agent) && ereg('Opera'$Agent)) {   
  28. $temp = explode('('$Agent);   
  29. $Part = $temp[1];   
  30. $temp = explode(')'$Part);   
  31. $browserver = $temp[1];   
  32. $temp = explode(' '$browserver);   
  33. $browserver = $temp[2];   
  34. $browserver = preg_replace('/([d.]+)/''1'$browserver);   
  35. $browserver = $browserver;   
  36. $browser = 'Opera';   
  37. }   
  38. if(ereg('Mozilla'$Agent) && ereg('MSIE'$Agent)){   
  39. $temp = explode('('$Agent);   
  40. $Part = $temp[1];   
  41. $temp = explode(';'$Part);   
  42. $Part = $temp[1];   
  43. $temp = explode(' '$Part);   
  44. $browserver = $temp[2];   
  45. $browserver = preg_replace('/([d.]+)/','1',$browserver);   
  46. $browserver = $browserver;   
  47. $browser = 'Internet Explorer';   
  48. }   
  49. if($browser != ''){   
  50. $browseinfo = $browser.' '.$browserver;   
  51. else {   
  52. $browseinfo = false;   
  53. }   
  54. return $browseinfo;   
  55. }   
  56.   
  57. function getIP ()   
  58. {   
  59. global $_SERVER;   
  60. if (getenv('HTTP_CLIENT_IP')) {   
  61. $ip = getenv('HTTP_CLIENT_IP');   
  62. else if (getenv('HTTP_X_FORWARDED_FOR')) {   
  63. $ip = getenv('HTTP_X_FORWARDED_FOR');   
  64. else if (getenv('REMOTE_ADDR')) {   
  65. $ip = getenv('REMOTE_ADDR');   
  66. else {   
  67. $ip = $_SERVER['REMOTE_ADDR'];   
  68. }   
  69. return $ip;   
  70. }   
  71.   
  72. function getOS ()   
  73. {   
  74. global $_SERVER;   
  75. $agent = $_SERVER['HTTP_USER_AGENT'];   
  76. $os = false;   
  77. if (eregi('win'$agent) && strpos($agent'95')){   
  78. $os = 'Windows 95';   
  79. }   
  80. else if (eregi('win 9x'$agent) && strpos($agent'4.90')){   
  81. $os = 'Windows ME';   
  82. }   
  83. else if (eregi('win'$agent) && ereg('98'$agent)){   
  84. $os = 'Windows 98';   
  85. }   
  86. else if (eregi('win'$agent) && eregi('nt 5.1'$agent)){   
  87. $os = 'Windows XP';   
  88. }   
  89. else if (eregi('win'$agent) && eregi('nt 5'$agent)){   
  90. $os = 'Windows 2000';   
  91. }   
  92. else if (eregi('win'$agent) && eregi('nt'$agent)){   
  93. $os = 'Windows NT';   
  94. }   
  95. else if (eregi('win'$agent) && ereg('32'$agent)){   
  96. $os = 'Windows 32';   
  97. }   
  98. else if (eregi('linux'$agent)){   
  99. $os = 'Linux';   
  100. }   
  101. else if (eregi('unix'$agent)){   
  102. $os = 'Unix';   
  103. }   
  104. else if (eregi('sun'$agent) && eregi('os'$agent)){   
  105. $os = 'SunOS';   
  106. }   
  107. else if (eregi('ibm'$agent) && eregi('os'$agent)){   
  108. $os = 'IBM OS/2';   
  109. }   
  110. else if (eregi('Mac'$agent) && eregi('PC'$agent)){   
  111. $os = 'Macintosh';   
  112. }   
  113. else if (eregi('PowerPC'$agent)){   
  114. $os = 'PowerPC';   
  115. }   
  116. else if (eregi('AIX'$agent)){   
  117. $os = 'AIX';   
  118. }   
  119. else if (eregi('HPUX'$agent)){   
  120. $os = 'HPUX';   
  121. }   
  122. else if (eregi('NetBSD'$agent)){   
  123. $os = 'NetBSD';   
  124. }   
  125. else if (eregi('BSD'$agent)){   
  126. $os = 'BSD';   
  127. }   
  128. else if (ereg('OSF1'$agent)){   
  129. $os = 'OSF1';   
  130. }   
  131. else if (ereg('IRIX'$agent)){   
  132. $os = 'IRIX';   
  133. }   
  134. else if (eregi('FreeBSD'$agent)){   
  135. $os = 'FreeBSD';   
  136. }   
  137. else if (eregi('teleport'$agent)){   
  138. $os = 'teleport';   
  139. }   
  140. else if (eregi('flashget'$agent)){   
  141. $os = 'flashget';   
  142. }   
  143. else if (eregi('webzip'$agent)){   
  144. $os = 'webzip';   
  145. }   
  146. else if (eregi('offline'$agent)){   
  147. $os = 'offline';   
  148. }   
  149. else {   
  150. $os = 'Unknown';   
  151. }   
  152. return $os;   
  153. }   
  154. }?>  

使用是条用上面的类就就可以了.

PHP代码
  1. <?php   
  2. $code = new clientGetObj;   
  3. $str1 = $code->getBrowse();//浏览器:   
  4. $str2 = $code->getIP();//IP地址:   
  5. $str3 = $code->getOS();//操作系统:   
  6. ?>