Jump to content

im learning PHP but wont execute :(


reza777

Recommended Posts

basically i am learning php and i have copied the following code from a book and saved it on my server but everytime i run it it wont execute properly and all i get is this:

[a href=\"http://www.persian-princes.com/learnphp/phpinfo.php\" target=\"_blank\"]http://www.persian-princes.com/learnphp/phpinfo.php[/a]

i know there is nothing wrong with the code as it works on my cousins server:

[a href=\"http://lucylayton.com/phpinfo.php\" target=\"_blank\"]http://lucylayton.com/phpinfo.php[/a]

i contacted my host (im running a dedicated server so i have root access) and they said:

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Thank you for contacting customer support. There may be a custom configuration that you have to set on the server such as with the php.ini file. Unfortunately, we do not provide assistance with third party coding issues.[/quote]

does anyone know why i am having this proble?


ok it wouldnt let me copy the code here, but what it does is basically display the users browser, ip address and name of the file thats all
Link to comment
Share on other sites

Are you using echo or print to output the information? Also what variables are you using to get the filename, user agent (web browser) and ip address.

Also could you paste you code here, you should be able to. If you code has functions add a space before the parenthesis like so:
[code]function_name ()[/code]
Link to comment
Share on other sites

[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Information</title>
</head>
<body>
<?php

# This page lists some cool information for the user

echo "You are running the file <b>$PHP_SELF</b>.<br />\n";
echo 'You are viewing this page using: <b>', $HTTP_USER_AGENT, '</b>.<br />from IP address ', $REMOTE_ADDR;

?>

</body>
</html>[/code]
Link to comment
Share on other sites

Umm,. just as I thought! The book is teaching you old code, well not old, but deperciated code. Try this instead:
[code]<?php

# This page lists some cool information for the user

echo "You are running the file <b>$_SERVER['PHP_SELF']</b>.<br />\n";
echo 'You are viewing this page using: <b>', $_SERVER['HTTP_USER_AGENT'], '</b>.<br />from IP address ', $_SERVER['REMOTE_ADDR'];

?>[/code]
The problem is to do with a PHP setting called [a href=\"http://uk.php.net/register_globals\" target=\"_blank\"]register_globals[/a]
Link to comment
Share on other sites

ok i see you have added $_SERVER before the variables
so do i now have to add this to every variable when writing php regardless og wot the book says?
i dont quite understand why u have done this?
i read the register_globals link u sent me but couldnt make much sense of it

should i just change the register global setting on my server? im running a mambo site on my server also, would doing this harm my site?!!

really confused
thank u for ur help i appreciate it :)
Link to comment
Share on other sites

Please read the section on [a href=\"http://www.php.net/register_globals\" target=\"_blank\"]register_globals[/a] in the manual on php.net. Also read the section on [a href=\"http://www.php.net/manual/en/language.variables.external.php\" target=\"_blank\"]Variables from outside PHP[/a].

Ken
Link to comment
Share on other sites

Dont change the register_globals setting at all as can create a security issue.

The variable I used is part of a group of variables called [a href=\"http://uk2.php.net/manual/en/language.variables.predefined.php#language.variables.superglobals\" target=\"_blank\"]super globals[/a]

You only use these variables when you need to access server information, cookie, session, post'd and get data etc.

I would suggest you get a book that is uptodate and doesnt use register_globals for its examples.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.