riad
riad

Reputation: 7194

How send parameter to a url without using form in php?

dear all, I need to send parameters to a URL without using form in php and get value from that page.We can easily send parameters using form like this:

<html>
    <form action="http://..../abc.php" method="get">
    <input name="id" type="text" />
    <input name="name" type="text"/>
    <input  type="submit" value="press" />
    </form>
</html>

But i already have value like this

     <?php 
       $id="123";
       $name="blahblah";
      ?>

Now i need to send values to http://..../abc.php without using form.when the 2 value send to abc.php link then it's show a value OK.Now i have to collect the "OK" msg from abc.php and print on my current page. i need to auto execute the code.when user enter into the page those value automatically send to a the url.So i can't use form or href. because form and href need extra one click.

Is their any kind heart who can help me to solve this issue?

Upvotes: 2

Views: 28792

Answers (3)

&#193;lvaro Gonz&#225;lez
&#193;lvaro Gonz&#225;lez

Reputation: 146370

<?php

$base = 'http://example.com/abc.php';
$id="123";
$name="blahblah";

$data = array(
    'id' => $id,
    'name' => $name,
);

$url = $base . '?' . http_build_query($data);

header("Location: $url");
exit;

Upvotes: 2

codaddict
codaddict

Reputation: 454950

You can do:

$id="123";
$name="blahblah";
echo "<a href = 'http://foo.com/abc.php?id=$id&name=$name'> link </a>";

Upvotes: 2

SW4
SW4

Reputation: 71140

You can pass values via GET using a hyperlink:

<a href='abc.php?id=123&name=blahblah' />

print_r($_GET) would then give you the values, or you can use $_GET['id'] etc in abc.php

Other approaches, depending on your needs, include using AJAX to POST/GET the request asynchronously, or using include/require to pull in abc.php if it only includes specific functioanlity.eg:

   $id="123";
   $name="blahblah";
   require('abc.php');

Upvotes: 8

Related Questions