Jump to content

How to send $_POST into php file


f.ismayil

Recommended Posts

I have tilbud.php file that has no output. Just receives data and adds them into MySQL table. Inside tilbud.php file I have JavaScript code that calls products.php. Product.php has the following code:

 

if(!isset($_POST['userid'])) {

  echo "<script type='text/javascript'>";

    echo "window.location = 'index.php'";

  echo "</script>";

 

  exit;

}

 

So, I you call product.php without submitting $_POST['userid'] it redirects you into index.php. How to submit $_POST['userid'] into products php without using <form method='POST' action='product.php'> ?

Link to comment
Share on other sites

if(!isset($_POST['userid'])) {
  echo "<script type='text/javascript'>";
    echo "window.location = 'index.php'";
  echo "</script>";
  
  exit;
}

 

This is rather inefficient, it would be wise to have the server handle redirects.

 

if(!isset($_POST['userid'])) {
header('Location: /index.php');
}

 

As for submitting post data without using a form, you have a few options.

http://ca.php.net/manual/en/function.http-post-data.php]http://php.net/manual/en/book.curl.php[/curl]

http://ca.php.net/manual/en/function.http-post-data.php

http://ca.php.net/manual/en/function.stream-context-create.php

 

I'm sure there are others. I would go with the cURL option and possibly AJAX if you need it.

Link to comment
Share on other sites

I want linux compatibility for that application. My problem now is, i can get the complete path of the application using some php function?

 

What i will do is that the application is created and saved the first time you execute the application in the index page(tr level), and saved in my singleton class of global registry thats its in S_SESSION.  So the first time its instancied, it will get the complete path.

 

The problem here i see is that the user may execute first some file in the categorias directory. Then it will get that path as a base. I will check for that as the directory structrue of the application is fixed.

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.