PDA

View Full Version : Passing String with URL Problem?



Squintz
08-02-2002, 05:23 PM
im atempting to learn PHP and iv ran into a situation...

Im running apache web server with php and mySQL...This question has nothing to do with mySQL but....

I Created a file called welcome.hml and included the following code...

<html>
<head>
<title>Welcome</title>
</head>

<body>

<Font color = "Black">
<a href="http://localhost/welcome.php?name=Dave"> Hi, I'm Dave!</a>

</body>

</html>

Then i created a filed called welcome.php and included this code...

<html>
<head>
<title>Welcome</title>
</head>

<body>

<?php
echo( "Welcome to our web site, $name!" );
?>

</body>

</html>

and then i goto http://localhost/welcome.html and click on the link and it takes me to welcome.php but heres the problem...

The output on welcome.php says:
Welcome to our web site, !

It doesnt pass the name dave to the page from the URL whats causing that... I got the code straight from a book...

I know php is working cause i used it witha date function and it worked fine

SYP}{ER
08-02-2002, 06:02 PM
Weird... Do you have register_globals turn ON in the php.ini file?

If not, you'll have to use this:

<?="Welcome to our web site, ".$_GET['name']."!"?>

Squintz
08-02-2002, 06:06 PM
yes their turned on...Im not even sure where to look for the problem... so any input will help thanx

Squintz
08-02-2002, 06:10 PM
i put that code you said in and it did work yet globals are turned on

Squintz
08-02-2002, 06:13 PM
i wonder...Is the file supposed to be php.ini or php.ini-dist which is what its named....Also when i make changes to i need to restart apache and if so whats the proper way to shut down apache and restart it

Squintz
08-02-2002, 06:17 PM
Ok i renamed the file and now it works... i changed it from php.ini-dist to php.ini....Im not sure where the -dist came from....

Thanx for your help

Centaur
08-02-2002, 06:27 PM
dist means distribution, that&rsquo;s the default template which you are supposed to copy and modify.

And one advice: leave register_globals off and get a habit of accessing arguments via $_GET and $_POST, this will prevent the situation when you expect a variable to be empty yet someone passes you a value through the query string.

Squintz
08-02-2002, 08:32 PM
thanx for the advice...

SYP}{ER
08-06-2002, 09:31 PM
Plus more and more hosts will eventually be switching register_globals off so your scripts may fall apart on some new-age host ;)

skinme!
08-07-2002, 06:54 PM
But, if you have a html template loading data to show as text depending on say $page:

index.php?page=home

then users won't be able to bookmark your pages. Not totally relevant but I think that hosts turning it off in the ini is not very helpful.

firepages
08-07-2002, 07:29 PM
index.php?page=home

will still work for the user, the only difference is that your script will have to do this (just guessing what $page does here)

include('/home/httpd/include/$_GET[home].php');
instead of this
include('/home/httpd/include/$home.php');

register_globals only changes how we access the varibles nothing else