За последние 24 часа нас посетили 17718 программистов и 1648 роботов. Сейчас ищут 994 программиста ...

[Помогите] Как сделать правильный инклюд? [Решено]

Тема в разделе "Решения, алгоритмы", создана пользователем yura29, 14 авг 2013.

  1. yura29

    yura29 Новичок

    С нами с:
    16 июл 2013
    Сообщения:
    11
    Симпатии:
    0
    В программировании я совсем недавно, поэтому возникают совершенно дурацкие вопросы, о которых даже стыдно спрашивать

    Но моя проблема состоит вот в чем:
    Есть 3 файла
    index.php
    config.php
    backend/backend.php

    Вся система открывается через index.php, который использует в своей работе backend.php
    И в том самом backend.php есть адрес, который лучше заменить на переменную, прописываемую в config.php

    Я пробовал инклюдить и в сам index.php и в сам backend.php, но ничего не получается. Он не видит эту переменную

    Ну вот и сами файлики

    config.php
    Код (Text):
    1. <?php
    2.  
    3. $skin_path = 'http://s3.amazonaws.com/MinecraftSkins/';
    4.  
    5. ?>
    index.php
    Код (Text):
    1. <!--
    2. 3-D Minecraft Skin Viewer
    3. By Kent Rasmussen @ earthiverse.ath.cx
    4. Using Three.Js HTML5 3D Engine from https://github.com/mrdoob/three.js/
    5. Add ?user=USERNAME to render a specific username
    6. Add &refresh to re-grab the skin and generate new parts
    7. Add &webgl to render in webgl
    8. -->
    9. <?php
    10. include('backend/backend.php');
    11. include('config.php');
    12. if(!isset($user)) $user = earthiverse;
    13. if(isset($refresh)) minecraft_skin_delete($user);
    14. minecraft_skin_download($user);?>
    15. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    16. <html xmlns="http://www.w3.org/1999/xhtml">
    17. <head>
    18. <script type="text/javascript" src="backend/resources/3d/Three.js"></script>
    19. <script type="text/javascript" src="backend/resources/3d/Cube.js"></script>
    20. <script type="text/javascript" src="backend/resources/3d/ImageUtils.js"></script>
    21. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    22. <link href="style.css" rel="stylesheet" type="text/css" />
    23. <title>3d minecraft body test v1.0</title>
    24. </head>
    25.  
    26. <body>
    27. <script type="text/javascript">
    28.  var camera, scene, renderer;
    29.  init();
    30.  setInterval( loop, 1000 / 60 );
    31.  function init() {
    32.   camera = new THREE.Camera(20, window.innerWidth / window.innerHeight, 1, 1000);
    33.   scene = new THREE.Scene();
    34.  
    35.   var head_materials = [new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/head_right.png')}),new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/head_left.png')}),new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/head_top.png')}),new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/head_bottom.png')}),new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/head_back.png')}),new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/head_front.png')})];
    36.  
    37.   head = new THREE.Mesh( new Cube(8, 8, 8, 1, 1, head_materials), new THREE.MeshFaceMaterial());
    38.   head.position.x = 0;
    39.   head.position.y = 0;
    40.   head.position.z = 0;
    41.   scene.addObject(head);
    42.  
    43.   var body_materials = [new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/body_right.png')}),new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/body_left.png')}),new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/body_top.png')}),new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/body_bottom.png')}),new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/body_back.png')}),new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/body_front.png')})];
    44.  
    45.   body = new THREE.Mesh( new Cube(8, 12, 4, 1, 1, body_materials), new THREE.MeshFaceMaterial());
    46.   body.position.x = 0;
    47.   body.position.y = -10;
    48.   body.position.z = 0;
    49.   scene.addObject(body);
    50.  
    51.   var arm_left_materials = [new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/arm_left_inner.png')}),new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/arm_left_outer.png')}),new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/arm_left_top.png')}),new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/arm_left_bottom.png')}),new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/arm_left_back.png')}),new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/arm_left_front.png')})];
    52.  
    53.   arm_left = new THREE.Mesh( new Cube(4, 12, 4, 1, 1, arm_left_materials), new THREE.MeshFaceMaterial());
    54.   arm_left.position.x = 6;
    55.   arm_left.position.y = -10;
    56.   arm_left.position.z = 0;
    57.   scene.addObject(arm_left);
    58.  
    59.   var arm_right_materials = [new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/arm_right_outer.png')}),new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/arm_right_inner.png')}),new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/arm_right_top.png')}),new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/arm_right_bottom.png')}),new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/arm_right_back.png')}),new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/arm_right_front.png')})];
    60.  
    61.   arm_right = new THREE.Mesh( new Cube(4, 12, 4, 1, 0, arm_right_materials), new THREE.MeshFaceMaterial());
    62.   arm_right.position.x = -6;
    63.   arm_right.position.y = -10;
    64.   arm_right.position.z = 0;
    65.   scene.addObject(arm_right);
    66.  
    67.   var leg_left_materials = [new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/leg_left_inner.png')}),new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/leg_left_outer.png')}),new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/leg_left_top.png')}),new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/leg_left_bottom.png')}),new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/leg_left_back.png')}),new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/leg_left_front.png')})];
    68.  
    69.   leg_left = new THREE.Mesh( new Cube(4, 12, 4, 1, 1, leg_left_materials), new THREE.MeshFaceMaterial());
    70.   leg_left.position.x = 2;
    71.   leg_left.position.y = -22;
    72.   leg_left.position.z = 0;
    73.   leg_left.rotation.y = 180 * Math.PI;
    74.   scene.addObject(leg_left);
    75.  
    76.   var leg_right_materials = [new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/leg_right_outer.png')}),new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/leg_right_inner.png')}),new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/leg_right_top.png')}),new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/leg_right_bottom.png')}),new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/leg_right_back.png')}),new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/leg_right_front.png')})];
    77.  
    78.   leg_right = new THREE.Mesh( new Cube(4, 12, 4, 1, 1, leg_right_materials), new THREE.MeshFaceMaterial());
    79.   leg_right.position.x = -2;
    80.   leg_right.position.y = -22;
    81.   leg_right.position.z = 0;
    82.   scene.addObject(leg_right);
    83.  
    84.   var hat_materials = [new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/hat_right.png')}),new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/hat_left.png')}),new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/hat_top.png')}),new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/hat_bottom.png')}),new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/hat_back.png')}),new THREE.MeshBasicMaterial({map:ImageUtils.loadTexture('images/skins/<?php echo $user; ?>/hat_front.png')})];
    85.  
    86.   hat = new THREE.Mesh( new Cube(9, 9, 9, 1, 1, hat_materials), new THREE.MeshFaceMaterial());
    87.   hat.position.x = 0;
    88.   hat.position.y = 0;
    89.   hat.position.z = 0;
    90.   scene.addObject(hat);
    91.  
    92.   <?php if(isset($_GET['webgl'])) echo 'renderer = new THREE.WebGLRenderer();'; else echo 'renderer = new THREE.CanvasRenderer();'; ?>
    93.  
    94.   renderer.setSize( window.innerWidth, window.innerHeight );
    95.   document.body.appendChild( renderer.domElement );
    96.  }
    97.  var xvar = 0;
    98.  function loop() {
    99.   xvar += Math.PI/90
    100.   camera.target.position.x = 0;
    101.   camera.target.position.y = -11;
    102.   camera.target.position.z = 0;
    103.  
    104.   //Leg Swing
    105.   leg_left.rotation.x = Math.cos(xvar);
    106.   leg_left.position.z = 0 - 6*Math.sin(leg_left.rotation.x);
    107.   leg_left.position.y = -16 - 6*Math.abs(Math.cos(leg_left.rotation.x));
    108.   leg_right.rotation.x = Math.cos(xvar + (Math.PI));
    109.   leg_right.position.z = 0 - 6*Math.sin(leg_right.rotation.x);
    110.   leg_right.position.y = -16 - 6*Math.abs(Math.cos(leg_right.rotation.x));
    111.  
    112.   //Arm Swing
    113.   arm_left.rotation.x = Math.cos(xvar + (Math.PI));
    114.   arm_left.position.z = 0 - 6*Math.sin(arm_left.rotation.x);
    115.   arm_left.position.y = -4 - 6*Math.abs(Math.cos(arm_left.rotation.x));
    116.   arm_right.rotation.x = Math.cos(xvar);
    117.   arm_right.position.z = 0 - 6*Math.sin(arm_right.rotation.x);
    118.   arm_right.position.y = -4 - 6*Math.abs(Math.cos(arm_right.rotation.x));
    119.  
    120.   camera.position.x = 0 - 100*Math.sin(xvar);
    121.   camera.position.y = 0 - 30*Math.sin(xvar);
    122.   camera.position.z = 0 - 100*Math.cos(xvar);
    123.   renderer.render( scene, camera );
    124.  }
    125. </script>
    126.  
    127. </body>
    128. </html>
    backend.php
    Код (Text):
    1. <?php
    2. error_reporting(E_ALL);
    3.  
    4. //List of Variables used on the site
    5. if(isset($_GET['user'])) $user = htmlentities($_GET['user'],ENT_QUOTES); //Minecraft Username
    6. if(isset($_GET['refresh'])) $refresh = htmlentities($_GET['refresh'],ENT_QUOTES); //Used for refreshing minecraft skins
    7.  
    8. //Check for hooligans
    9. if(isset($_GET['refresh']) && $user == "") {
    10.     // If this was executed, all skins would be erased.
    11.     echo "Please don't try and glitch things.<br/>\nThanks.";
    12.     exit;
    13. }
    14.  
    15. function minecraft_skin_3d_part($original, $user, $xpos, $ypos, $width, $height, $texturesize, $name, $flipx, $flipy) {
    16.    $temp = imagecreatetruecolor($texturesize,$texturesize);
    17.    imagealphablending($temp, false);
    18.    imagesavealpha($temp, true);
    19.    if($flipx == TRUE && $flipy == TRUE) {
    20.     $xpos = $xpos + $width -1;
    21.     $width = 0 - $width;
    22.     $ypos = $ypos + $height -1;
    23.     $height = 0 - $height;
    24.    } else if($flipx == TRUE) {
    25.     $xpos = $xpos + $width-1;
    26.     $width = 0 - $width;
    27.    } else if($flipy == TRUE) {
    28.     $ypos = $ypos + $height-1;
    29.     $height = 0 - $height;
    30.    }
    31.    imagecopyresampled($temp, $original, 0, 0, $xpos, $ypos, $texturesize, $texturesize, $width, $height);
    32.    imagepng($temp, "images/skins/".$user."/".$name.".png");
    33.    imagedestroy($temp);
    34. }
    35.  
    36. function minecraft_skin_download($user) {
    37.  if(!file_exists('images/skins/'.$user.'/base.png')) {
    38.   if(@getimagesize($skin_path.$user.'.png')) {
    39.    //Make a new directory
    40.    If(!is_dir('images/skins/'.$user)) {
    41.     mkdir('images/skins/'.$user,0777);
    42.    }
    43.    //Download the skin from Minecraft.net and put it in /images/skins/
    44.    $url = $skin_path.$user.'.png';
    45.    $img = 'images/skins/'.$user.'/base.png';
    46.    file_put_contents($img, file_get_contents($url));
    47.    
    48.    //Create another image twice the size
    49.    $original = imagecreatefrompng('images/skins/'.$user.'/base.png');
    50.  
    51.    //Create Base_x2
    52.    //If you want, you can delete the next 6 rows after these comments without worrying.
    53.    //I just use these to add faces to usernames in the stats lists with some css magic.
    54.    $temp = imagecreatetruecolor(128,64);
    55.    imagealphablending($temp, false);
    56.    imagesavealpha($temp, true);
    57.    imagecopyresized($temp, $original, 0, 0, 0, 0, 128, 64, 64, 32);
    58.    imagepng($temp, "images/skins/".$user."/base_x2.png");
    59.    imagedestroy($temp);
    60.    
    61.    /////////////////////////
    62.    // Body Parts (for 3D) //
    63.    /////////////////////////
    64.  
    65.    minecraft_skin_3d_part($original,$user,40,0,8,8,256,"hat_top", TRUE, TRUE);
    66.    minecraft_skin_3d_part($original,$user,48,0,8,8,256,"hat_bottom", TRUE, TRUE);
    67.    minecraft_skin_3d_part($original,$user,32,8,8,8,256,"hat_left", FALSE, FALSE);
    68.    minecraft_skin_3d_part($original,$user,40,8,8,8,256,"hat_front", FALSE, FALSE);
    69.    minecraft_skin_3d_part($original,$user,48,8,8,8,256,"hat_right", FALSE, FALSE);
    70.    minecraft_skin_3d_part($original,$user,56,8,8,8,256,"hat_back", FALSE, FALSE);
    71.    
    72.    minecraft_skin_3d_part($original,$user,8,0,8,8,256,"head_top", TRUE, TRUE);
    73.    minecraft_skin_3d_part($original,$user,16,0,8,8,256,"head_bottom", TRUE, TRUE);
    74.    minecraft_skin_3d_part($original,$user,0,8,8,8,256,"head_left", TRUE, FALSE);
    75.    minecraft_skin_3d_part($original,$user,8,8,8,8,256,"head_front", FALSE, FALSE);
    76.    minecraft_skin_3d_part($original,$user,16,8,8,8,256,"head_right", TRUE, FALSE);
    77.    minecraft_skin_3d_part($original,$user,24,8,8,8,256,"head_back", FALSE, FALSE);
    78.  
    79.    minecraft_skin_3d_part($original,$user,20,16,8,4,256,"body_top", FALSE, TRUE);
    80.    minecraft_skin_3d_part($original,$user,28,16,8,4,256,"body_bottom", FALSE, TRUE);
    81.    minecraft_skin_3d_part($original,$user,16,20,4,12,256,"body_right", TRUE, FALSE);
    82.    minecraft_skin_3d_part($original,$user,20,20,8,12,256,"body_front", FALSE, FALSE);
    83.    minecraft_skin_3d_part($original,$user,28,20,4,12,256,"body_left", TRUE, FALSE);
    84.    minecraft_skin_3d_part($original,$user,32,20,8,12,256,"body_back", FALSE, FALSE);
    85.  
    86.    minecraft_skin_3d_part($original,$user,44,16,4,4,256,"arm_left_top", FALSE, TRUE);
    87.    minecraft_skin_3d_part($original,$user,48,16,4,4,256,"arm_left_bottom", FALSE, TRUE);
    88.    minecraft_skin_3d_part($original,$user,40,20,4,12,256,"arm_left_outer", FALSE, FALSE);
    89.    minecraft_skin_3d_part($original,$user,44,20,4,12,256,"arm_left_front", FALSE, FALSE);
    90.    minecraft_skin_3d_part($original,$user,48,20,4,12,256,"arm_left_inner", FALSE, FALSE);
    91.    minecraft_skin_3d_part($original,$user,52,20,4,12,256,"arm_left_back", FALSE, FALSE);
    92.  
    93.    minecraft_skin_3d_part($original,$user,44,16,4,4,256,"arm_right_top", TRUE, TRUE);
    94.    minecraft_skin_3d_part($original,$user,48,16,4,4,256,"arm_right_bottom", TRUE, TRUE);
    95.    minecraft_skin_3d_part($original,$user,40,20,4,12,256,"arm_right_outer", TRUE, FALSE);
    96.    minecraft_skin_3d_part($original,$user,44,20,4,12,256,"arm_right_front", TRUE, FALSE);
    97.    minecraft_skin_3d_part($original,$user,48,20,4,12,256,"arm_right_inner", FALSE, FALSE);
    98.    minecraft_skin_3d_part($original,$user,52,20,4,12,256,"arm_right_back", TRUE, FALSE);
    99.  
    100.    minecraft_skin_3d_part($original,$user,4,16,4,4,256,"leg_left_top", FALSE, TRUE);
    101.    minecraft_skin_3d_part($original,$user,8,16,4,4,256,"leg_left_bottom", FALSE, TRUE);
    102.    minecraft_skin_3d_part($original,$user,0,20,4,12,256,"leg_left_outer", FALSE, FALSE);
    103.    minecraft_skin_3d_part($original,$user,4,20,4,12,256,"leg_left_front", FALSE, FALSE);
    104.    minecraft_skin_3d_part($original,$user,8,20,4,12,256,"leg_left_inner", FALSE, FALSE);
    105.    minecraft_skin_3d_part($original,$user,12,20,4,12,256,"leg_left_back", FALSE, FALSE);
    106.  
    107.    minecraft_skin_3d_part($original,$user,4,16,4,4,256,"leg_right_top", TRUE, TRUE);
    108.    minecraft_skin_3d_part($original,$user,8,16,4,4,256,"leg_right_bottom", TRUE, TRUE);
    109.    minecraft_skin_3d_part($original,$user,0,20,4,12,256,"leg_right_outer", TRUE, FALSE);
    110.    minecraft_skin_3d_part($original,$user,4,20,4,12,256,"leg_right_front", TRUE, FALSE);
    111.    minecraft_skin_3d_part($original,$user,8,20,4,12,256,"leg_right_inner", TRUE, FALSE);
    112.    minecraft_skin_3d_part($original,$user,12,20,4,12,256,"leg_right_back", TRUE, FALSE);
    113.    
    114.    //Release original from memory (Skin from minecraft.net)
    115.    imagedestroy($original);
    116.   }
    117.  }
    118. }
    119.  
    120. function minecraft_skin_delete($user) {
    121.  rrmdir('images/skins/'.$user);
    122. }
    123.  
    124. // Functions not created by me
    125. include_once('rmdir.php'); // Script found on php.net that removes all the files in a folder, then the folder itself
    126. ?>
    Заранее благодарен
     
  2. YSandro

    YSandro Старожил

    С нами с:
    7 апр 2011
    Сообщения:
    2.523
    Симпатии:
    2
    Правильно я понял, что в функции minecraft_skin_download($user) не видна переменная $skin_path?
    Если да, то добавьте в функцию объявление global $skin_path:
    Код (PHP):
    1. function minecraft_skin_download($user) {
    2.   global $skin_path;
    3.   ...
     
  3. yura29

    yura29 Новичок

    С нами с:
    16 июл 2013
    Сообщения:
    11
    Симпатии:
    0
    Re: [Помогите] Как сделать правильный инклюд?

    YSandro спасибо! Всё работает))