How to get pframeters from URL string

Links for php scripts

Moderators: macek, egami, gesf

leo
New php-forum User
New php-forum User
Posts: 12
Joined: Thu Mar 11, 2004 7:35 pm

How to get pframeters from URL string

Postby leo » Fri Aug 20, 2004 3:51 pm

Sorry for a stupid question.
I cannot understand how can I get parameters'
names and values from the URL string
(... /myPage.html?param1=xxxx&param2=yyyy&param3=zzzz)
using myPage' s PHP and/or JavaScript code.

:sad:

Thanks!

Leo

User avatar
Virtuoso
php-forum Active User
php-forum Active User
Posts: 268
Joined: Mon Jul 21, 2003 7:05 am
Contact:

Re: How to get pframeters from URL string

Postby Virtuoso » Fri Aug 20, 2004 4:26 pm

leo wrote:Sorry for a stupid question.
I cannot understand how can I get parameters'
names and values from the URL string
(... /myPage.html?param1=xxxx&param2=yyyy&param3=zzzz)
using myPage' s PHP and/or JavaScript code.

:sad:

Thanks!

Leo


for your example,
the varaible $_GET['param1'] will equal "xxxx"
the variable $_GET['param2'] will equal "yyyy"
the variable $_GET['param3'] will equal "zzzz"

User avatar
gesf
Moderator
Moderator
Posts: 1717
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden
Contact:

Postby gesf » Sat Aug 21, 2004 10:28 pm

Virtuoso is right!

But note!
If you send exactly the same url through form with post method, then you´ll catch your pamameters with $_POST!

Example:

Code: Select all

<form name="f" method="post" action="myPage.html">
   <input name="param1" value="xxxx" type="text">
   <input name="param2" value="yyyy" type="text">
   <input name="param3" value="zzzz" type="text">

   <input name="submit" value="Send" type="submit">
</form>

Then you´ll 'get' them with:

$_POST['param1'] equal to 'xxxx'
$_POST['param2'] equal to 'yyyy'
$_POST['param3'] equal to 'zzzz'


So... $_GET won´t work here unless you have the get method in your form!

User avatar
Virtuoso
php-forum Active User
php-forum Active User
Posts: 268
Joined: Mon Jul 21, 2003 7:05 am
Contact:

Postby Virtuoso » Sun Aug 22, 2004 3:09 pm

it'll work if you have it in the link URL. you dont necessary have to have it in a form. You can also put it in the "action" part of the form.

User avatar
gesf
Moderator
Moderator
Posts: 1717
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden
Contact:

Postby gesf » Tue Aug 24, 2004 1:04 am

That´s what i´ve said :D

You can only get it from the url if you have it in the url.
Using a form, you can only access it from the url if you don´t specify any method. Otherwise the sent data will be 'invisible'!


Return to “PHP Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest

cron