Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 262
  • Last Modified:

post variables in location

Is there any way to use the POST-method instead
of the GET-method to overgive the variable id
(and maybe some more) to nextPage.php in the
following code:

<?
  header("location: nextPage.php?id=$id");
?>


Thanks for help.

Gamba
0
Gamba
Asked:
Gamba
  • 7
  • 6
  • 2
  • +3
1 Solution
 
manucorpCommented:
no header("location ...")
use the 302 moved location of the HTTP protocol
but you cant try to use cookie if you want to hide the id

0
 
GambaAuthor Commented:
could you give some code example?
i don't know how to implement this.

Thanks,

Gamba
0
 
GambaAuthor Commented:
...I mean, for the moved location,
cause I don't want to use cookies.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ykf2000Commented:
Hi,

If you want to use a post method u'll need some javascript.
See below:


<?
  echo "<form action='nextPage.php' method='post' name='theForm'>";
  echo "<input type='hidden' name='id' value='$id'>";
  echo "</form>";
  echo "<script language='javascript'>";
  echo "document.theForm.submit();";
  echo "</script>";
?>
0
 
fajr_nCommented:
If you don't want use cookies, how about the session. You can found in PHP.

this way still display the id value if the user click viewsource, although using session.

<form method="post" action="nextPage.php">
<input type="hidden" name="id" value="<!--id -->">
<input type="submit" name="submit" value="send">
</form>

better is the value of id variable save in session. Look like you need 2 process.

First,
- Activate the session
- Searching the id value
- Save the id value in session
- Redirect to nextPage.php

let's see source below:

<?
    // You can type the source to search id value here
    require("session.php");
    if(empty($id_user))
    {
      $id_user=$id; //the id value save in session
    }
    else
    {
      header ("Cache-Control: no-cache, must-revalidate");
      header ("Pragma: no-cache");
      header ("Location: nextPage.php");  
    }
?>

Session function in file session.php:
<?
    session_name("NEXTP");
    session_start();
    session_register("id_user");
?>

Below is nextPage.php file:
<?
    require("session.php");
    echo $id_user;
?>

I wish resolve your problem.
0
 
fajr_nCommented:
Ups .. sorry my english and my words not good enough
0
 
us111Commented:
another way
<?
    $id = 10;
    if ($submit)
    {   include("nextPage.php");
         exit();
    }
?>
0
 
MoondancerCommented:
This question is still open today, perhaps it was just overlooked.  Please update it with comments if more information is needed to get your solution.  If you've been helped by the participating expert(s), you may just convert their comment to the accepted answer and then grade and close.  If an answer has ever been proposed you may not have this option to accept the comment as answer, if that is the case, ask the specific expert you wish to award to post an answer.  Finalizing questions benefits you and others who then search our PAQ, and rewards the experts who provided help.  A win/win scenario.  PLEASE DO NOT ACCEPT THIS AS THE ANSWER, IT IS MERELY A REMINDER.  If no response has been received by month-end, I will delete or accept an answer based on the information provided.  Expert input is welcome.

If you wish to award multiple participants, comment here as to which experts you'd like to award and what amounts.  If you'd like to delete this question,  comment here as to the reason, so that the participants may be advised and/or help further.  

Here is the Community Support link:   http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt where you may post zero point questions, include the link for special handling.

Click your Member Profile to see all your open questions, so that you can finalize them as well.  Your responsiveness is appreciated.  

Moondancer
Community Support Moderator @ Experts Exchange
 
0
 
GambaAuthor Commented:
Oops, I did post a comment to the last question,
but it seems not to be submitted.
So, once again:

us111,

this seems to be very near to what I want.
I did check this, but my problem is now, that
whith your solution not only code from nextpage.php
is included, but also the code form currentpage.php.
This is no problem as such, but if I have a lot of
interaction, always including more and more code,
it gets a little bit complicated.
Do you have an idea to solve this?

I increased points a little, cause things seem to
get a bit more complicated.

Thanks for help,

Gamba

0
 
us111Commented:
The other solution is to use session:

<?
if ($PHPSESSID)
 session_start($PHPSESSID);
else
 session_start();

 if ($submit <> "")
{ session_register("id");
  header("Location: nextpage.php")
}
?>

nextpage.php:
<?
if ($PHPSESSID)
 session_start($PHPSESSID);
else
 session_start();

print $id;
?>

or you can use the fsockopen function:
http://www.php.net/manual/en/ref.network.php
0
 
GambaAuthor Commented:
I guess, the session_start-function in PHP
needs cookies, or not?
So if I would use cookies, I would not need
to post the id.

Is there no other way, e.g. manually
setting request method or anything else?

Gamba

0
 
us111Commented:
session doesn't need cookies, it's server-side not client-side
0
 
GambaAuthor Commented:
Are you sure?
Any time, I disable cookies in the browser,
it seems to me, that session-handling would fail.

How could the session-variable reach nextpage.php,
if there is no cookie and it is not included in
currentpage.php via get or post?

0
 
us111Commented:
session_start creates a SID onto the server in /tmp or somewhere else.
the variable is stored into the SID file.

You can test, disable your cookie and you'll see it will work.

have a look at http://www.php.net/manual/en/ref.session.php, all is explained.
0
 
GambaAuthor Commented:
Thank you, but they say:

To continue, <A HREF="nextpage.php?<?=SID?>">click here</A>
   
The <?=SID?> is not necessary, if
    --enable-trans-sid was used to compile PHP.

Does this mean, the session-function does automatically
append the SID as get-request-parameter to the URL,
so that I don't have to do append it myself?

The point for me is, that I don't want it to occur
in the browser-navigation-line (is this correct in english, i don't know). So the session would not
be too useful.

Anyway, you did a lot of work to comment all questions,
so the points are yours.
Maybe you could post another comment, if you could help
me to answer my concern about the php-session.
Otherwise i will also accept your last comment.

Thank you

Gamba
0
 
us111Commented:
By default php is compiled with --enable-trans-sid.
It means that you don't have to specify the SID.

I believe that the better way to understand session is to play with it.
Try the simple script above.

Btw, you need to specify
if ($PHPSESSID)
  session_start($PHPSESSID);
else
  session_start();
if you want to access the variables stored into the session

Try & test. And then if you have further questions don't hesitate to ask
0
 
GambaAuthor Commented:
I will do so.

Thank you,

Gamba
0
 
us111Commented:
you're welcome
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 7
  • 6
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now