Page 1 of 1

Getting Parameters from URL

Posted: Tue May 04, 2010 1:02 pm
by lextar
Its been a while since I used PHP so trying to install some scripts onto my new web host, and the parameters being passed via the URL no longer seem to work.

So the url is basically

a_story.php?called=MyLife

My previous code and web host works fine as I didn't need to use $_GET to access the variable. However I presume things have moved on. However when I update my code so I do

$tmpvar = $_GET['called'];
echo "Storyname=".$tmpvar;

I still get nothing output at all. The host I am with is JustHost, and the only thing I can think that may is preventing me using this is register_globals = off (still reading up on this).

Can anyone help and probably point me to a good tutorial if I need to use an alternative?

Thanks

Re: Getting Parameters from URL

Posted: Tue May 04, 2010 1:28 pm
by rnoack
it should work with register globals off.

the code you posted looks ok, can you post the full php file including php tags?
are you getting an error? or just nothing?

Re: Getting Parameters from URL

Posted: Tue May 04, 2010 2:00 pm
by lextar
All I have in my file is the html code that displays fine.

Then within the html code I have

<?php
$_SESSION['$called'];
$tmpv = $_GET['$called'];
echo "Called:".$tmpv."<P>";
?>

But nothing is displayed other than "Called:"

Re: Getting Parameters from URL

Posted: Wed May 05, 2010 1:48 am
by Apollo
lextar wrote:$tmpv = $_GET['$called'];
Here's your error, remove the $.
You only use $ to specify variable names (and then it still only works in double quotes, if you include it in strings).
called is not a variable name here, but just a key to identify an element in the $_GET array.


On a side note, I don't know why you're doing this: :?:
$_SESSION['$called'];
(It doesn't do anything, and it's wrong)

Re: Getting Parameters from URL

Posted: Wed May 05, 2010 9:16 am
by rnoack
to be more specific, remove the final $, remove the $ is vague because there are 3 of them

the correct code is:

Code: Select all

$tmpv = $_GET['called'];