Getting Parameters from URL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lextar
Forum Newbie
Posts: 2
Joined: Tue May 04, 2010 12:49 pm

Getting Parameters from URL

Post 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
rnoack
Forum Commoner
Posts: 34
Joined: Mon May 03, 2010 12:38 am

Re: Getting Parameters from URL

Post 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?
lextar
Forum Newbie
Posts: 2
Joined: Tue May 04, 2010 12:49 pm

Re: Getting Parameters from URL

Post 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:"
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: Getting Parameters from URL

Post 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)
rnoack
Forum Commoner
Posts: 34
Joined: Mon May 03, 2010 12:38 am

Re: Getting Parameters from URL

Post 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'];
Post Reply