f.ismayil Posted May 18, 2011 Share Posted May 18, 2011 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'> ? Quote Link to comment https://forums.phpfreaks.com/topic/236785-how-to-send-_post-into-php-file/ Share on other sites More sharing options...
fugix Posted May 18, 2011 Share Posted May 18, 2011 so in your products.php file how are you grabbing $_POST['userid'] now? Quote Link to comment https://forums.phpfreaks.com/topic/236785-how-to-send-_post-into-php-file/#findComment-1217223 Share on other sites More sharing options...
pornophobic Posted May 18, 2011 Share Posted May 18, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/236785-how-to-send-_post-into-php-file/#findComment-1217246 Share on other sites More sharing options...
f.ismayil Posted May 19, 2011 Author Share Posted May 19, 2011 Should I write something like that? $userid = $_POST['userid']; http_post_data("product.php", $userid); If this code is correct should I call products php before this code or after? I would highly appreciate working code? Quote Link to comment https://forums.phpfreaks.com/topic/236785-how-to-send-_post-into-php-file/#findComment-1217387 Share on other sites More sharing options...
wepnop Posted May 19, 2011 Share Posted May 19, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/236785-how-to-send-_post-into-php-file/#findComment-1217403 Share on other sites More sharing options...
trq Posted May 19, 2011 Share Posted May 19, 2011 @wepnop, are you sure your in the right thread? Quote Link to comment https://forums.phpfreaks.com/topic/236785-how-to-send-_post-into-php-file/#findComment-1217416 Share on other sites More sharing options...
f.ismayil Posted May 20, 2011 Author Share Posted May 20, 2011 Before openning products.php I need to send $_POST variable to it. How to do it? who has ready code? Quote Link to comment https://forums.phpfreaks.com/topic/236785-how-to-send-_post-into-php-file/#findComment-1218230 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.