نمایش نتایج 1 تا 7 از 7

نام تاپیک: دنیای $_SERVER

  1. #1
    کاربر دائمی آواتار رضا قربانی
    تاریخ عضویت
    خرداد 1389
    محل زندگی
    ܓܨ_| ı̴̴̡ ̡̡͡|̲̲̲͡͡͡ ̲▫̲͡ ̲̲̲͡͡π̲̲͡͡ ̲̲͡▫̲̲͡͡ ̲|̡̡̡ _
    پست
    1,824

    دنیای $_SERVER

    با سلام خدمت تمامی دوستان

    یه آرایه بسیار کارآمد که من عاشقش هستم و در همه جا از یک قسمتش استفاده می کنم $_SERVER هست و گفتم اطلاعات کلیش رو به صورت انگلیسی براتون بذارم ، چون هر قسمتش یه کاری رو انجام می ده .

    اگر خواستید توضیحش رو فارسی بخونید از گوگل استفاده کنید


    برای نمایش این نوع تابع ها به صورت های گوناگون می تونید در برنامه هاتون استفاده کنید :
    برای مثال من در کد زیر صفحه ای که کاربر از اونجا اومده رو به خودش لینک می دم :

    echo '<a href="'.$_SERVER['HTTP_REFERER'].'">برگشت</a>';


    خیلی راحت
    و شما هم می تونید به این صورت تست کنید ، کلمات زیر را در $_SERVER جایگزین کنید
      <?php
    echo $_SERVER['SERVER_NAME'];
    ?>



    من لیست کامل رو براتون میذارم و امیدوارم که در کارهاتون ازش استفاده ببرید


    'PHP_SELF'
    The filename of the currently executing script, relative to the document root. For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar would be /test.php/foo.bar. The __FILE__ constant contains the full path and filename of the current (i.e. included) file. If PHP is running as a command-line processor this variable contains the script name since PHP 4.3.0. Previously it was not available.
    'argv'
    Array of arguments passed to the script. When the script is run on the command line, this gives C-style access to the command line parameters. When called via the GET method, this will contain the query string.
    'argc'
    Contains the number of command line parameters passed to the script (if run on the command line).
    'GATEWAY_INTERFACE'
    What revision of the CGI specification the server is using; i.e. 'CGI/1.1'.
    'SERVER_ADDR'
    The IP address of the server under which the current script is executing.
    'SERVER_NAME'
    The name of the server host under which the current script is executing. If the script is running on a virtual host, this will be the value defined for that virtual host.
    'SERVER_SOFTWARE'
    Server identification string, given in the headers when responding to requests.
    'SERVER_PROTOCOL'
    Name and revision of the information protocol via which the page was requested; i.e. 'HTTP/1.0';
    'REQUEST_METHOD'
    Which request method was used to access the page; i.e. 'GET', 'HEAD', 'POST', 'PUT'.
    Note:
    PHP script is terminated after sending headers (it means after producing any output without output buffering) if the request method was HEAD.
    'REQUEST_TIME'
    The timestamp of the start of the request. Available since PHP 5.1.0.
    'QUERY_STRING'
    The query string, if any, via which the page was accessed.
    'DOCUMENT_ROOT'
    The document root directory under which the current script is executing, as defined in the server's configuration file.
    'HTTP_ACCEPT'
    Contents of the Accept: header from the current request, if there is one.
    'HTTP_ACCEPT_CHARSET'
    Contents of the Accept-Charset: header from the current request, if there is one. Example: 'iso-8859-1,*,utf-8'.
    'HTTP_ACCEPT_ENCODING'
    Contents of the Accept-Encoding: header from the current request, if there is one. Example: 'gzip'.
    'HTTP_ACCEPT_LANGUAGE'
    Contents of the Accept-Language: header from the current request, if there is one. Example: 'en'.
    'HTTP_CONNECTION'
    Contents of the Connection: header from the current request, if there is one. Example: 'Keep-Alive'.
    'HTTP_HOST'
    Contents of the Host: header from the current request, if there is one.
    'HTTP_REFERER'
    The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.
    'HTTP_USER_AGENT'
    Contents of the User-Agent: header from the current request, if there is one. This is a string denoting the user agent being which is accessing the page. A typical example is: Mozilla/4.5 [en] (X11; U; Linux 2.2.9 i586). Among other things, you can use this value with get_browser() to tailor your page's output to the capabilities of the user agent.
    'HTTPS'
    Set to a non-empty value if the script was queried through the HTTPS protocol.
    Note: Note that when using ISAPI with IIS, the value will be off if the request was not made through the HTTPS protocol.
    'REMOTE_ADDR'
    The IP address from which the user is viewing the current page.
    'REMOTE_HOST'
    The Host name from which the user is viewing the current page. The reverse dns lookup is based off the REMOTE_ADDR of the user.
    Note: Your web server must be configured to create this variable. For example in Apache you'll need HostnameLookups On inside httpd.conf for it to exist. See also gethostbyaddr().
    'REMOTE_PORT'
    The port being used on the user's machine to communicate with the web server.
    'SCRIPT_FILENAME'
    The absolute pathname of the currently executing script.
    Note:
    If a script is executed with the CLI, as a relative path, such as file.php or ../file.php, $_SERVER['SCRIPT_FILENAME'] will contain the relative path specified by the user.
    'SERVER_ADMIN'
    The value given to the SERVER_ADMIN (for Apache) directive in the web server configuration file. If the script is running on a virtual host, this will be the value defined for that virtual host.
    'SERVER_PORT'
    The port on the server machine being used by the web server for communication. For default setups, this will be '80'; using SSL, for instance, will change this to whatever your defined secure HTTP port is.
    'SERVER_SIGNATURE'
    String containing the server version and virtual host name which are added to server-generated pages, if enabled.
    'PATH_TRANSLATED'
    Filesystem- (not document root-) based path to the current script, after the server has done any virtual-to-real mapping.
    Note: As of PHP 4.3.2, PATH_TRANSLATED is no longer set implicitly under the Apache 2 SAPI in contrast to the situation in Apache 1, where it's set to the same value as the SCRIPT_FILENAME server variable when it's not populated by Apache. This change was made to comply with the CGI specification that PATH_TRANSLATED should only exist if PATH_INFO is defined. Apache 2 users may use AcceptPathInfo = On inside httpd.conf to define PATH_INFO.
    'SCRIPT_NAME'
    Contains the current script's path. This is useful for pages which need to point to themselves. The __FILE__ constant contains the full path and filename of the current (i.e. included) file.
    'REQUEST_URI'
    The URI which was given in order to access this page; for instance, '/index.html'.
    'PHP_AUTH_DIGEST'
    When doing Digest HTTP authentication this variable is set to the 'Authorization' header sent by the client (which you should then use to make the appropriate validation).
    'PHP_AUTH_USER'
    When doing HTTP authentication this variable is set to the username provided by the user.
    'PHP_AUTH_PW'
    When doing HTTP authentication this variable is set to the password provided by the user.
    'AUTH_TYPE'
    When doing HTTP authenticated this variable is set to the authentication type.
    'PATH_INFO'
    Contains any client-provided pathname information trailing the actual script filename but preceding the query string, if available. For instance, if the current script was accessed via the URL http://www.example.com/php/path_info.../stuff?foo=bar, then $_SERVER['PATH_INFO'] would contain /some/stuff.
    'ORIG_PATH_INFO'
    Original version of 'PATH_INFO' before processed by PHP.



    و در آخر هم اگر من چیزی رو جای گذاشتم و بیان نکردم ممنون می شم عزیزان تکمیلش کنند

    اینم لیست کامل از این نوع آرایه که می توانید به صورت مستقیم در کنار خودتون داشته باشید



    echo "<table border=\"1\">";
    echo "<tr><td>" .$_SERVER['argv'] ."</td><td>argv</td></tr>";
    echo "<tr><td>" .$_SERVER['argc'] ."</td><td>argc</td></tr>";
    echo "<tr><td>" .$_SERVER['GATEWAY_INTERFACE'] ."</td><td>GATEWAY_INTERFACE</td></tr>";
    echo "<tr><td>" .$_SERVER['SERVER_ADDR'] ."</td><td>SERVER_ADDR</td></tr>";
    echo "<tr><td>" .$_SERVER['SERVER_NAME'] ."</td><td>SERVER_NAME</td></tr>";
    echo "<tr><td>" .$_SERVER['SERVER_SOFTWARE'] ."</td><td>SERVER_SOFTWARE</td></tr>";
    echo "<tr><td>" .$_SERVER['SERVER_PROTOCOL'] ."</td><td>SERVER_PROTOCOL</td></tr>";
    echo "<tr><td>" .$_SERVER['REQUEST_METHOD'] ."</td><td>REQUEST_METHOD</td></tr>";
    echo "<tr><td>" .$_SERVER['REQUEST_TIME'] ."</td><td>REQUEST_TIME</td></tr>";
    echo "<tr><td>" .$_SERVER['QUERY_STRING'] ."</td><td>QUERY_STRING</td></tr>";
    echo "<tr><td>" .$_SERVER['DOCUMENT_ROOT'] ."</td><td>DOCUMENT_ROOT</td></tr>";
    echo "<tr><td>" .$_SERVER['HTTP_ACCEPT'] ."</td><td>HTTP_ACCEPT</td></tr>";
    echo "<tr><td>" .$_SERVER['HTTP_ACCEPT_CHARSET'] ."</td><td>HTTP_ACCEPT_CHARSET</td></tr>";
    echo "<tr><td>" .$_SERVER['HTTP_ACCEPT_ENCODING'] ."</td><td>HTTP_ACCEPT_ENCODING</td></tr>";
    echo "<tr><td>" .$_SERVER['HTTP_ACCEPT_LANGUAGE'] ."</td><td>HTTP_ACCEPT_LANGUAGE</td></tr>";
    echo "<tr><td>" .$_SERVER['HTTP_CONNECTION'] ."</td><td>HTTP_CONNECTION</td></tr>";
    echo "<tr><td>" .$_SERVER['HTTP_HOST'] ."</td><td>HTTP_HOST</td></tr>";
    echo "<tr><td>" .$_SERVER['HTTP_REFERER'] ."</td><td>HTTP_REFERER</td></tr>";
    echo "<tr><td>" .$_SERVER['HTTP_USER_AGENT'] ."</td><td>HTTP_USER_AGENT</td></tr>";
    echo "<tr><td>" .$_SERVER['HTTPS'] ."</td><td>HTTPS</td></tr>";
    echo "<tr><td>" .$_SERVER['REMOTE_ADDR'] ."</td><td>REMOTE_ADDR</td></tr>";
    echo "<tr><td>" .$_SERVER['REMOTE_HOST'] ."</td><td>REMOTE_HOST</td></tr>";
    echo "<tr><td>" .$_SERVER['REMOTE_PORT'] ."</td><td>REMOTE_PORT</td></tr>";
    echo "<tr><td>" .$_SERVER['SCRIPT_FILENAME'] ."</td><td>SCRIPT_FILENAME</td></tr>";
    echo "<tr><td>" .$_SERVER['SERVER_ADMIN'] ."</td><td>SERVER_ADMIN</td></tr>";
    echo "<tr><td>" .$_SERVER['SERVER_PORT'] ."</td><td>SERVER_PORT</td></tr>";
    echo "<tr><td>" .$_SERVER['SERVER_SIGNATURE'] ."</td><td>SERVER_SIGNATURE</td></tr>";
    echo "<tr><td>" .$_SERVER['PATH_TRANSLATED'] ."</td><td>PATH_TRANSLATED</td></tr>";
    echo "<tr><td>" .$_SERVER['SCRIPT_NAME'] ."</td><td>SCRIPT_NAME</td></tr>";
    echo "<tr><td>" .$_SERVER['REQUEST_URI'] ."</td><td>REQUEST_URI</td></tr>";
    echo "<tr><td>" .$_SERVER['PHP_AUTH_DIGEST'] ."</td><td>PHP_AUTH_DIGEST</td></tr>";
    echo "<tr><td>" .$_SERVER['PHP_AUTH_USER'] ."</td><td>PHP_AUTH_USER</td></tr>";
    echo "<tr><td>" .$_SERVER['PHP_AUTH_PW'] ."</td><td>PHP_AUTH_PW</td></tr>";
    echo "<tr><td>" .$_SERVER['AUTH_TYPE'] ."</td><td>AUTH_TYPE</td></tr>";
    echo "</table>"



    موفق باشید دوستان
    آخرین ویرایش به وسیله رضا قربانی : یک شنبه 21 فروردین 1390 در 20:46 عصر

  2. #2
    کاربر دائمی آواتار sargardoon
    تاریخ عضویت
    بهمن 1389
    محل زندگی
    دبی
    سن
    43
    پست
    172

    نقل قول: دنیای $_SERVER

    این هم چند توضیح مختصر که من میدونم و تا به حال ازش استفاده کردم:
    $_SERVER['HTTP_USER_AGENT'];

    نمایش نوع مرورگر و نوع سیستم عامل که خروجی به صورت زیر میباشد.
    Mozilla/5.0 (Windows NT 5.1; rv:2.0) Gecko/20100101 Firefox/4.0


    گرفتن IP
    $_SERVER['REMOTE_ADDR'];


    گرفتن نام هاست
    $ip = $_SERVER['REMOTE_ADDR'];
    $hostaddress = gethostbyaddr($ip);


    خروجی میشه localhost

    از کجا به این صفحه وارد شده؟
    $referred = $_SERVER['HTTP_REFERER'];


    برای مثال:
    if ($referred == "") {
    print "Page was directly requested";
    } else {
    print "$referred";
    }


    زبان سیستم عامل
    $_SERVER['HTTP_ACCEPT_LANGUAGE'];

    خروجی en-us,en;q=0.5

    موفق باشید.

  3. #3
    VIP آواتار Sajjad.Aghapour
    تاریخ عضویت
    مهر 1386
    محل زندگی
    اهل کاشانم .. روزگارم بد نیست
    پست
    1,265

    نقل قول: دنیای $_SERVER

    مراقب استفاده کردن هاتون باشید. مثلا
    http://www.webadminblog.com/index.ph...-ever-written/

    سعی میکنم اگه وقت کردم مقاله ای در این مورد بنویسم. ولی شما هم بیکار ننشینید D:
    Close your eyes, take a deep breath, click your heels three times, and say, "There's no better thing than Inversion of Control and Dependency Injection, generic specialization, the decorator pattern, chains of responsibilities, and extensible software."

  4. #4
    کاربر جدید آواتار iranh00
    تاریخ عضویت
    تیر 1388
    محل زندگی
    تربت حیدریه
    پست
    6

    نقل قول: دنیای $_SERVER

    با توجه به مشکلی که واسم بوجود اومده بود، نشد این تاپیک زیرخاکلی رو بالا نکشم :D .

    یک مسأله که ممکنه واسه خیلی ها بوجود اومده باشه ( چه php و چه asp.net ) اینه که چطوری میتونم ادرس دهی سایت رو به عنوان روت انجام بدم .

    مثلاً الان من داخل منو گزینه "تماس با ما - localhost/rootsite/contactus.php " رو قرار دادم .
    اما زمانی که میخوام از صفحه مدیریت ، یا پنل کاربری ( کلاً هر صفحه ای که داخل یه پوشه قرار داشته باشه) وارد اون پوشه بشم، اسم اون پوشه رو قبل این صفحه اضافه میکنه که باعث میشه صفحه من باز نشه .

    مثلاً :مثلاً این ساختار رو دقت کنید .
    فایل اصلی در ریشه خود سایت کنار فایل index.php قرار دارد.
    localhost/rootsite/contactus.php

    حالا من داخل صفحه admin_cp.php با این آدرس هستم:
    localhost/rootsite/admin/admin_cp.php

    اگه الان، روی منو تماس با ما کلیک کنم، آدرس به این عوض میشه :
    localhost/rootsite/admin/contact.php


    ممنون میشم راهنماییم کنید. البته نمیخوام زیاد حرفه ای باشه، فقط در حد یه پروژه دانشجویی طراحی سایت فروشگاه اینترنتی کافی هست.

  5. #5

    نقل قول: دنیای $_SERVER

    سلام با كدام تابع ميشه فهميد تولبار الكسا نصب هست يا نه؟
    agent قبلاً جو.اب ميداد ولي الان نه ديگه

  6. #6
    کاربر دائمی آواتار رضا قربانی
    تاریخ عضویت
    خرداد 1389
    محل زندگی
    ܓܨ_| ı̴̴̡ ̡̡͡|̲̲̲͡͡͡ ̲▫̲͡ ̲̲̲͡͡π̲̲͡͡ ̲̲͡▫̲̲͡͡ ̲|̡̡̡ _
    پست
    1,824

    نقل قول: دنیای $_SERVER

    نقل قول نوشته شده توسط iranh00 مشاهده تاپیک
    با توجه به مشکلی که واسم بوجود اومده بود، نشد این تاپیک زیرخاکلی رو بالا نکشم :D .

    یک مسأله که ممکنه واسه خیلی ها بوجود اومده باشه ( چه php و چه asp.net ) اینه که چطوری میتونم ادرس دهی سایت رو به عنوان روت انجام بدم .

    مثلاً الان من داخل منو گزینه "تماس با ما - localhost/rootsite/contactus.php " رو قرار دادم .
    اما زمانی که میخوام از صفحه مدیریت ، یا پنل کاربری ( کلاً هر صفحه ای که داخل یه پوشه قرار داشته باشه) وارد اون پوشه بشم، اسم اون پوشه رو قبل این صفحه اضافه میکنه که باعث میشه صفحه من باز نشه .

    مثلاً :مثلاً این ساختار رو دقت کنید .
    فایل اصلی در ریشه خود سایت کنار فایل index.php قرار دارد.
    localhost/rootsite/contactus.php

    حالا من داخل صفحه admin_cp.php با این آدرس هستم:
    localhost/rootsite/admin/admin_cp.php

    اگه الان، روی منو تماس با ما کلیک کنم، آدرس به این عوض میشه :
    localhost/rootsite/admin/contact.php


    ممنون میشم راهنماییم کنید. البته نمیخوام زیاد حرفه ای باشه، فقط در حد یه پروژه دانشجویی طراحی سایت فروشگاه اینترنتی کافی هست.
    کافیه موقع آدرس دهی لینک ها به این صورت در ادمین آدرس بدید

    کد HTML:
    ../contact.php
    یا در ابتدای صفحه در قسمت head این کدو وارد کنید و آدرس بدید
    کد HTML:
    <base href="http://yourdomain.com/" />

  7. #7
    کاربر دائمی آواتار رضا قربانی
    تاریخ عضویت
    خرداد 1389
    محل زندگی
    ܓܨ_| ı̴̴̡ ̡̡͡|̲̲̲͡͡͡ ̲▫̲͡ ̲̲̲͡͡π̲̲͡͡ ̲̲͡▫̲̲͡͡ ̲|̡̡̡ _
    پست
    1,824

    نقل قول: دنیای $_SERVER

    نقل قول نوشته شده توسط skarimi1369 مشاهده تاپیک
    سلام با كدام تابع ميشه فهميد تولبار الكسا نصب هست يا نه؟
    agent قبلاً جو.اب ميداد ولي الان نه ديگه
    HTTP_USER_AGENT
    اینجا کمکت می کنه : http://php.net/manual/en/reserved.variables.server.php

برچسب های این تاپیک

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •