zVirx Posted August 4, 2009 Share Posted August 4, 2009 Hello, i got a problem with cURL which i couldn't solve after 2hrs of googling >.> Well heres the problem.. I wanted to pass variables between my php pages so i was left to choose between $_COOKIE, $_GET and $_POST.. i've decided that $_COOKIE and $_GET are impractical so i went with $_POST and to do that i needed to use cURL to the post the information from page to page OR fake a form with javascript ( which was ugly :-\ ) anyway i did the following function: public function post( $url, $post ) { $curl = curl_init( $url ); curl_setopt( $curl, CURLOPT_POST, 1 ); curl_setopt( $curl, CURLOPT_POSTFIELDS, $post ); curl_exec( $curl ); curl_close( $curl ); } but the function didn't follow the URL declared, i've tried CURLOPT_FOLLOWLOCATION and CURLOPT_HEADER but nothing worked! i know thats the whole idea of cURL to get pages and view them on the current page, but is there an option to follow the destination URL and keep my post vlaues ? Help. Quote Link to comment https://forums.phpfreaks.com/topic/168745-solved-curl-follow/ Share on other sites More sharing options...
The Little Guy Posted August 4, 2009 Share Posted August 4, 2009 What is your value for $post? Quote Link to comment https://forums.phpfreaks.com/topic/168745-solved-curl-follow/#findComment-890301 Share on other sites More sharing options...
zVirx Posted August 4, 2009 Author Share Posted August 4, 2009 Its text something like "blabla=blabla", the function works fine as intended but the thing is.. its on the current page not the $url page.. what i wanted is that cURL would leave the current page and follow the $url page and keep my post values all at the same time! EDIT: More explaining of the problem.. for example if your passing variable between page "x.php" and "y.php", you would use that function on "x.php" to post values to "y.php" but cURL will not leave "x.php" it would include result of the post function inside "x.php" and stays on it ... logically you would want your end-user on "y.php" not "x.php" Quote Link to comment https://forums.phpfreaks.com/topic/168745-solved-curl-follow/#findComment-890308 Share on other sites More sharing options...
zVirx Posted August 4, 2009 Author Share Posted August 4, 2009 Unfortunately after some more research i've found this answer: Link Is this true ? Quote Link to comment https://forums.phpfreaks.com/topic/168745-solved-curl-follow/#findComment-890625 Share on other sites More sharing options...
patrickmvi Posted August 4, 2009 Share Posted August 4, 2009 What is your ultimate goal here? Are you trying to post data from your site onto someone else's site for which you have no access to? If you're using this to try and pass information internally in your site, I would think that this would not be the correct way to do this. Please give a better description as to what you're trying to accomplish. Quote Link to comment https://forums.phpfreaks.com/topic/168745-solved-curl-follow/#findComment-890658 Share on other sites More sharing options...
zVirx Posted August 4, 2009 Author Share Posted August 4, 2009 No, iam trying to pass information internally in my site.. Ok heres the goal: Iam trying to pass information between my "register.php" and "login.php" when a user successfully register on "register.php" i want to redirect him to "login.php" with a note of "Registration Successful" on it.. so as i said, ways i've thought of to do that are: 1. Set a cookie on successful registeration on "register.php" and read it on "login.php" and delete the cookie immediately. 2. Using $_GET, just setting the "login.php" to recieve $_GET variable and redirect the user to something like "login.php?register=success" 3. Using $_POST and cURL <-- having trouble redirecting the user to "login.php" 4. Making a dummy form with javascript and simulate a click to "login.php" .. which will not work if the end-user disabled javascript. So the best out of 4 (i think) is number 3 which is the $_POST method.. If there is anyway to do this except for these 4 methods i'd really like to know them, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/168745-solved-curl-follow/#findComment-890695 Share on other sites More sharing options...
TeNDoLLA Posted August 4, 2009 Share Posted August 4, 2009 Why not use just header redirect when register was succesful? if (register_succesful) { header('Location: login.php?register=succesful'); } Quote Link to comment https://forums.phpfreaks.com/topic/168745-solved-curl-follow/#findComment-890699 Share on other sites More sharing options...
zVirx Posted August 4, 2009 Author Share Posted August 4, 2009 For two main reasons: 1. When the user refreshes the page it would still show "Registration Successful". 2. Iam using the var to keep the username alive on the login form so it would be like "login.php?register=userName", thus i don't want the user to be in control of that just by editing the url. Quote Link to comment https://forums.phpfreaks.com/topic/168745-solved-curl-follow/#findComment-890739 Share on other sites More sharing options...
xphoid Posted August 4, 2009 Share Posted August 4, 2009 Why not show your "registration successful" text on the registration page with a link (or timed meta-redirect, or both) to the login page? As for passing data server-side from page to page you can use sessions. session_start(); if($registration_successful) { $_SESSION['new_registration'] = true; } session_start(); if(isset($_SESSION['new_registration'])) { // delete so message isn't repeated unset($_SESSION['new_registration']); // show message } Quote Link to comment https://forums.phpfreaks.com/topic/168745-solved-curl-follow/#findComment-890763 Share on other sites More sharing options...
zVirx Posted August 4, 2009 Author Share Posted August 4, 2009 Agh i feel so dumb how the heck did i not think of sessions!, Thanks man. Btw: I've found that you can NOT post data and redirect at the same time its against RFC rules, so it would have been impossible to do that with cURL !! Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/168745-solved-curl-follow/#findComment-890778 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.