简体   繁体   中英

After using cURL function, the session won't work

I have this script which has a log-in user so a user can log in only by using his username/password!

Everything works fine, the only problem is, in the page i use the cURL function, then it won't recognize the user session anymore, once i get out of that page and move to another..

Here is the cURL file code:

<?php session_start(); 
require_once('db.php'); 
include('functions.php'); 
checkLogin('1'); 
$query = 'SELECT * FROM users WHERE ID="'.$_SESSION['user_id'].'"';
$result = mysql_query($query) or die(mysql_error());


while($row = mysql_fetch_array($result)){
    $id_user=$row['user_id'];
    $phone=$row['phone'];
    $name=$row['first_name'];


}

?>

<?php
    if ($points == 250) {
     $b = time (); 
 $date1 =date( "Y-m-d;h:i:s" , mktime(date("h")+6, date("i"), date("s"), date("m") , date("d"), date("Y"))); 
 $str_time = ""; 
 $str_msg = ""; 
 $str_from = ""; 
 $str_zip = ""; 

$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://testext.i-movo.com/api/receivesms.aspx?".$str_from.$str_zip.$phone.$str_time.$date1.$str_msg);
curl_setopt($ch, CURLOPT_HEADER, 0);

// grab URL and pass it to the browser
curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);
}
else if ($points == 500) {
     $b = time (); 
 $date1 =date( "Y-m-d;h:i:s" , mktime(date("h")+6, date("i"), date("s"), date("m") , date("d"), date("Y"))); 
 $str_time = ""; 
 $str_msg = ""; 
 $str_from = ""; 
 $str_zip = ""; 

$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://testext.i-movo.com/api/receivesms.aspx?".$str_from.$str_zip.$phone.$str_time.$date1.$str_msg);
curl_setopt($ch, CURLOPT_HEADER, 0);

// grab URL and pass it to the browser
curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);
}
else {
    echo "We are sorry, you don't possess enough points in order to take the coupon";

}
echo '</div>';

?>

This is quite interesting ... did you know you closed php before calling curl ???

Remove ?> form the middle and put it at the end of the page

Secondly i don't advice to continue using mysql_query

FROM PHP DOC

Use of this extension is discouraged. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM