Jump to content

Archived

This topic is now archived and is closed to further replies.

reza777

im learning PHP but wont execute :(

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

Share this post


Link to post
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]

Share this post


Link to post
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]

Share this post


Link to post
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]

Share this post


Link to post
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 :)

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

×

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.