Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/168745-solved-curl-follow/
Share on other sites

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"  ::)

Link to comment
https://forums.phpfreaks.com/topic/168745-solved-curl-follow/#findComment-890308
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/168745-solved-curl-follow/#findComment-890658
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/168745-solved-curl-follow/#findComment-890695
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/168745-solved-curl-follow/#findComment-890739
Share on other sites

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

}

 

Link to comment
https://forums.phpfreaks.com/topic/168745-solved-curl-follow/#findComment-890763
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.