查看: 3099|回复: 0
打印 上一主题 下一主题

[提问] unity3D外网读数据库怎么都连不上,本地没问题

[复制链接]
wsk94    

0

主题

1

听众

88

积分

设计初学者

Rank: 1

纳金币
2
精华
0

活跃会员 灌水之王

跳转到指定楼层
楼主
发表于 2014-1-21 09:53:16 |只看该作者 |倒序浏览
申请了个网站空间(云动力的)做测试,把本地做好的文件上传到网站连不上,连接改了估计是不到位大家帮忙看看!*******************************************************************************************

开始在本地测试很好一点问题也没,一上到网络空间就有问题想请教大家指点下,困扰几天了
连接网络有两个问题请教(我是学美术的,希望大家不要笑话我!):
1、数据库我是从PHPadmin管理:http://111.229.239.249:999进入建立的,这样做完不知道数据库位置是不是对的?是不是要放到ftp目录下的databases里面,还是建好就不管了?
2、下面php代码里面连接数据库和unity3d代码中连接地址不知道对不对。帮忙看看各位高手!!
*******************************************************************************************

下面是我网站的基本情况
送的三级域名假设是 :wsk94.ydlkfree1.tzhytl.com
                            ip  :111.229.239.249
假设
PHPadmin管理:http://111.229.239.249:999
数据库地址:111.229.239.249
数据库名称:sp_wsk94
数据库用户名:sp_wsk
数据库密码:123456


假设
网站ftp地址:111.229.239.249
用户名:haha
密码:123
网站目录结构
01.jpg

数据库结构
02.jpg


php代码如下,已经拷贝到ftp的wwwroot下了
  1. <?
  2. // 连接数据库
  3. $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$host = "111.229.239.249"; //主机名
  4. $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$user = "sp_wsk"; //用户名
  5. $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$password = "123456"; //密码
  6. $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$dbname = "sp_wsk94"; //数据库名称
  7. mysql_connect($$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$host, $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$user, $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$password) or die("Cant connect into database");//连接失败输出错误提示
  8. mysql_select_db($$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$dbname)or die("Cant connect into database");
  9. // =============================================================================
  10. $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$unityHash =$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$_POST["hash"];//接收unity3d发送给程序的哈希值
  11. $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$phpHash = "hashcode"; //另外,要说的是hash值在此其实相当于二重保险,避免sql注入
  12. //所以为了简化程序我这里也去了,只要保证unity3d和php内的哈希值相等即可
  13. $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$nick = $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$_POST["name"]; //接收unity3d发送给程序的用户名
  14. $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$pass = $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$_POST["password"];//接收unity3d发送给程序的密码
  15. //先判断发送值是否为空
  16. if(!$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$nick || !$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$pass)
  17. {
  18. echo "昵称或密码不能为空!";//昵称或密码不能为空。
  19. } else
  20. {
  21. if ($$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$unityHash != $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$phpHash)
  22. {
  23. echo "HASH code is diferent from your game, you infidel.";//判断哈希值是否相等
  24. } else
  25. {
  26. $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$SQL = "SELECT * FROM `scores` WHERE `scores`.name = '" . $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$nick . "' and `scores`.password = '".$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$pass."'";//查看用
  27. $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$result = mysql_query($$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$SQL) or die("DATABASE ERROR!");

  28. if(mysql_num_rows($$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$result)==0)//php函数
  29. {
  30. echo "昵称或密码错误!"; //输出昵称或密码错误

  31. }else
  32. {
  33. echo "Welcome to unity3D !\n";//成功提示,“\n”只是为了能在unity中实现换行
  34. $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$sql = "SELECT * FROM `scores` WHERE `scores`.name = '" . $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$nick . "' and `scores`.password = '".$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$pass."'";
  35. $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$result = mysql_query($$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$sql);
  36. while($$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$row = mysql_fetch_array($$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$result))//输出用户表信息
  37. {
  38. echo "ID:".$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$row['id']."\n";
  39. echo "NAME:".$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$row['name']."\n " ;
  40. echo "PASSWORD:".$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$row['password']."\n ";
  41. echo "INFO:".$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$row['info']."\n ";
  42. }
  43. }
  44. }
  45. }
  46. // Close mySQL Connection
  47. mysql_close();
  48. ?>
复制代码
unity 3D js代码
  1. #pragma strict
  2. private var formName = "";//创建私有变量formName,记录文本框内输出的用户名变量
  3. private var formPassword = "";//创建私有变量 formPassword记录文本框内输出的密码变量
  4. var formText = "";//创建变量formText显示php发送给web端的信息

  5. var URL = "http://111.229.239.249/wsk94/wwwroot/check.php";//提交表单的网址

  6. var hash = "hashcode";//与php中相同的哈希值
  7. private var textrect = Rect (10, 150, 500, 100); //建立GUI的文本输入框

  8. function OnGUI()
  9. {
  10. GUI.Label( Rect (10, 10, 80, 20), "姓名:"); //用户名
  11. GUI.Label ( Rect (10, 30, 80, 20), "密码:" );//密码
  12. formName = GUI.TextField ( Rect (90, 10, 100, 20), formName ); //这里,你可将你输入的用户名赋值给formName变量
  13. formPassword = GUI.PasswordField ( Rect (90, 30, 100, 20), formPassword ,"*"[0], 25);
  14. //同理,这里是给formPassword 赋值
  15. if ( GUI.Button ( Rect (10, 60, 100, 20) , "登录" ) )
  16. { //如果单击登录按钮会执行Login()函数
  17. Login();
  18. }
  19. GUI.TextArea( textrect, formText );//显示文本信息
  20. }


  21. function Login()
  22. {
  23. var form = new WWWForm();//建立新表单变量
  24. //print(hash);//print的内容会在console选项卡中输出
  25. //print(formName);//我在这里添加三个输出语句是为了检验用户名和密码是否复制正确,以便之后调试php文件
  26. //print(formPassword);

  27. form.AddField("hash",hash);//创建表单各项
  28. form.AddField("name",formName);
  29. form.AddField("password",formPassword);
  30. var w = WWW(URL,form);//建立名为“w”的变量,并且将表单提交的URL和表单内容同步
  31. yield w;//我们等待表单响应php程序的返回,让程序把控制权交给其他应用
  32. if(w.error != null)//如果返回信息为错误信息,在console中输出错误信息
  33. {
  34. print(w.error);
  35. }
  36. else
  37. {
  38. print("OK!");//在console中输出ok
  39. formText = w.text;//将返回的web短信息赋值给formText ,在 执行GUI.TextArea( textrect, formText );时输出
  40. }
  41. formName = "";//点击查询完用户信息后清空用户名及密码
  42. formPassword = "";
  43. }
复制代码
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2024-11-11 10:24 , Processed in 0.108495 second(s), 32 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部