Jump to content

[SOLVED] How to MAKE the query string show up in the address bar?


sd9sd

Recommended Posts

When I enter a value into the form and press enter, the php file calls itself and the form value is sent as a query string. The problem is that the query string doesn't get displayed in the addressbar.

The strange thing is that when I used the same code earlier, it used to work. But ever since I've used a css file to change colour of the text, it stopped showing the query string. I don't think the css could have affected it, but I need the query string to be shown on the address bar like so: www.somesite.com/index.php?id=4

Any pointers?

 

This is the piece of form HTML code

<form name="form1" method="post" action="<TOONVALUEACTION>">
<span class="biglinks"># </span> 
<input name="toonValue" type="text" id="toonValue" size="6" value="<TOONVALUE>"> 
</form>

 

And this is the last part of the php that replaces the TOONVALUEACTION string:

if (file_exists("abc.html")) $template = implode("", file("abc.html"));
//---for the php file to call itself
$path = empty($_SERVER['PATH_INFO'])?$_SERVER['PHP_SELF']:$_SERVER['PATH_INFO'];

$id=$_POST["toonValue"];
if ($id=="") $id=$_GET["id"];

$template = str_replace("<TOONVALUE>",$id,$template);
$template = str_replace("<TOONVALUEACTION>",$path,$template);

echo $template;//displays the page

 

Link to comment
Share on other sites

erm..that's where the problem is. When I have a GET in the html, the query string shows up in the addressbar, but the toon does not get updated (which means that the toonValue isn't captured). So I changed the $_POST["toonValue"] to $_GET["toonValue"] and now the toonValue variable is captured, but the query string isn't shown in the addressbar.

Link to comment
Share on other sites

The POST method passes the values in the headers, you will never see them in the address bar.

The GET method passes the values in the URL (address bar), you will always see them in the address bar.

 

When you access the variable, you must the corresponding name.

<form method="GET">

...

$var1=$_GET['var1']

Link to comment
Share on other sites

  • 2 weeks later...

Problem solved!!! Using GET in the form and in the PHP worked. Thanks markjoe! :)

 

why would you want to do that?

Lemme guess...if there are two parameters that have to be passed, and you want only one of them to be shown on the addressbar, you can receive one of them as $_GET['user'] and the other as $_POST['password']

 

Am I right unkwntech?

Link to comment
Share on other sites

not quite, as because it is sending ALL data through both methods both would be displayed in both sections,

 

one possible thing is you could use it as a very cheap way to make sure the info came from your form, how many forms out there would send data to your page using both get and post, so you check to see if the $_GET value == the $_POST value, if not then in proborably didnt come from your form, not veryt secure but a possiblility

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.