开发者

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开发者_StackOverflow社区://..../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?


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');


You can do:

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


<?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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜