How to pass the URL via GET method?

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
charoo1983
Forum Newbie
Posts: 4
Joined: Sun May 24, 2009 11:57 pm

How to pass the URL via GET method?

Post by charoo1983 »

Hello !

Plz hep me out. What will be the procedure to pass the URL via GET method.
Like-
If I make a form of Name & Email address and Submit button.When the user fills name, email and click submit button the next page should be of Thankyou page which will take the user directly to my offer page.

Looking fwd for earliest reply.

Thanks & Regards,
Charoo
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: How to pass the URL via GET method?

Post by mikemike »

Hi Charoo,

I'm not sure what you mean by the first question.
Plz hep me out. What will be the procedure to pass the URL via GET method.
But I can help you with the later.

Page 1:

Code: Select all

<form action="page2.php" method="get">
  <label for="name">Name</label>
  <input type="text" name="name" id="name" />
  <label for="email">Email</label>
  <input type="text" name="email" id="email" />
  <button type="submit">Continue</button>
</form>
 
This will page all variables across to 'page2.php' which are accessible via GET...

Page 2:

Code: Select all

<?PHP
echo 'Thanks, '.$_GET['name'].' for registering with the email address: '.$_GET['email'].'.';
?>
Hope this helps.
Mike
Last edited by Benjamin on Tue May 26, 2009 10:33 am, edited 1 time in total.
Reason: Changed code type from text to php.
charoo1983
Forum Newbie
Posts: 4
Joined: Sun May 24, 2009 11:57 pm

Re: How to pass the URL via GET method?

Post by charoo1983 »

Thanks Mike :) for the earliest reply. Well I just want to know there is some procedure from which website address can be made passed...
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: How to pass the URL via GET method?

Post by mikemike »

Again I'm not 100% sure what you're after.

If you want the full website address (http://www.example.com/page.html?this=is&a=query) then here is a function you may find useful.

Code: Select all

function selfURL() { 
  $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; 
  
  $protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s; 
 
  $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]); 
 
  return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI']; 
} 
 
function strleft($s1, $s2) { 
  return substr($s1, 0, strpos($s1, $s2)); 
}
Last edited by Benjamin on Tue May 26, 2009 10:33 am, edited 1 time in total.
Reason: Changed code type from text to php.
charoo1983
Forum Newbie
Posts: 4
Joined: Sun May 24, 2009 11:57 pm

Re: How to pass the URL via GET method?

Post by charoo1983 »

Mike I just want to connect my website through GET method...
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: How to pass the URL via GET method?

Post by mikemike »

You're going to have to explain exactly what you're trying to do, you've asked for 3 different things now and I've given you good, thorough answers to each of them - explain exactly what you mean and what you're trying to do. To me 'connecting to my website through get' means using sockets to grab a webpage using GET - but I doubt that's what you're after if you're on about registration forms :?
charoo1983
Forum Newbie
Posts: 4
Joined: Sun May 24, 2009 11:57 pm

Re: How to pass the URL via GET method?

Post by charoo1983 »

Do you have skype ID?
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: How to pass the URL via GET method?

Post by mikemike »

I'm afraid not no. I'm behind all sorts of anti-freedom devices (firewall, etc) too so it wouldn't work even if I did.

Just post here so that others can help too.
Post Reply