Avatar billede techboy992 Praktikant
03. februar 2013 - 08:17 Der er 11 kommentarer og
1 løsning

Script vil ikke header

Kan nogen hjealpe med at faa det her script til at header til naeste side hvis success og til error side hvis ikke success:

<?php


$id = isset($_GET['id']) ? $_GET['id'] : '';
if(isset($_GET['tx']))
{
  $tx = $_GET['tx'];

// Init cURL
$request = curl_init();

// Set request options
curl_setopt_array($request, array
(
  CURLOPT_URL => 'https://www.paypal.com/cgi-bin/webscr',
  CURLOPT_POST => TRUE,
  CURLOPT_POSTFIELDS => http_build_query(array
    (
      'cmd' => '_notify-synch',
      'tx' => $tx,
      'at' => 'paypal token',
    )),
  CURLOPT_RETURNTRANSFER => TRUE,
  CURLOPT_HEADER => FALSE,
  // CURLOPT_SSL_VERIFYPEER => TRUE,
  // CURLOPT_CAINFO => 'cacert.pem',
));

// Execute request and get response and status code
$response = curl_exec($request);
$status  = curl_getinfo($request, CURLINFO_HTTP_CODE);
echo $status;
// Close connection
curl_close($request);

if($status == '200' AND strpos($response, 'SUCCESS') === 0)
{
    $con = mysql_connect("localhost","loadport_e1072","Kalabas3417");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("loadport_e1072", $con);
require_once 'class2.php';
$userid = USERID;
    mysql_query("INSERT INTO payments (userid, paypal, product, status)
VALUES ('".$userid."', '".$tx."','".$id."','1')");
header ("location: sendload.php?id=$tx");
}

else {
header ("location: error.php?id=4");
}
}

?>
Avatar billede olsensweb.dk Ekspert
03. februar 2013 - 08:52 #1
har du slået fejl visning til ??
hvad får du af fejl ??

skriver den noget med header already sendt ??

// Execute request and get response and status code
$response = curl_exec($request);
$status  = curl_getinfo($request, CURLINFO_HTTP_CODE);
echo $status; // *
// Close connection
curl_close($request);

* her sender du noget til skærmen og gør dermed at header ikke vil virke længere nede i programmet.

nb: du skal reprogrammerer din mysql da den extension (API) du anvender udgår i en fremtidig vertion af PHP
ref http://php.net/manual/en/mysqlinfo.api.choosing.php
Recommended API

It is recommended to use either the mysqli or PDO_MySQL extensions. It is not recommended to use the old mysql extension for new development, as it has been deprecated as of PHP 5.5.0 and will be removed in the future. A detailed feature comparison matrix is provided below. The overall performance of all three extensions is considered to be about the same. Although the performance of the extension contributes only a fraction of the total run time of a PHP web request. Often, the impact is as low as 0.1%.
Avatar billede techboy992 Praktikant
03. februar 2013 - 11:13 #2
Den kommer ikke med error

http://loadportal.net/online2/frompaypal.php

bare hvid side , naar den kommer tilbage fra paypal

ja jeg skal bare have fundet insert script til mysqli
Avatar billede olsensweb.dk Ekspert
03. februar 2013 - 12:52 #3
sæt dette ind i toppen af din php fil
error_reporting(-1);

når det virker og du sætter det i produktion rettes det til
error_reporting(0);

http://php.net/manual/en/function.error-reporting.php
http://www.php.net/manual/en/errorfunc.configuration.php#ini.error-reporting

brug udviklings værktøjerne i din browser

man bør ikke udvikle uden at have slået fejl visning til, og anvende udviklings værktøjerne i ens browser.
Avatar billede techboy992 Praktikant
03. februar 2013 - 17:12 #4
Errors:

Strict Standards: main() [function.main]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Chicago' for 'CST/-6.0/no DST' instead in /home/loadport/public_html/online2/frompaypal.php on line 46

Notice: Use of undefined constant USERID - assumed 'USERID' in /home/loadport/public_html/online2/frompaypal.php on line 46

Strict Standards: header() [function.header]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Chicago' for 'CST/-6.0/no DST' instead in /home/loadport/public_html/online2/frompaypal.php on line 49

Warning: Cannot modify header information - headers already sent by (output started at /home/loadport/public_html/online2/frompaypal.php:32) in /home/loadport/public_html/online2/frompaypal.php on line 49
Avatar billede techboy992 Praktikant
03. februar 2013 - 17:14 #5
Userid error er fordi jeg fjernede require_once 'class2.php';, for at faa den til at vise fejl rapporten.
Avatar billede arne_v Ekspert
03. februar 2013 - 17:20 #6
Warning: Cannot modify header information - headers already sent by (output started at /home/loadport/public_html/online2/frompaypal.php:32) in /home/loadport/public_html/online2/frompaypal.php on line 49

siger: du startede med at skrive til brugeren i linie 32, saa du kan ikke redirecte i linie 49
Avatar billede arne_v Ekspert
03. februar 2013 - 17:21 #7
It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function.

siger:

date_default_timezone_set('Europe/Copenhagen');

et sted foerst i din kode.
Avatar billede techboy992 Praktikant
03. februar 2013 - 17:24 #8
Hej arne ok hvordan kommer jeg saa til siderne meta opdate ?? med url variabler til de to sider ??
Avatar billede techboy992 Praktikant
03. februar 2013 - 17:36 #9
<?php

error_reporting(-1);
$id = isset($_GET['id']) ? $_GET['id'] : '';
if(isset($_GET['tx']))
{
  $tx = $_GET['tx'];

// Init cURL
$request = curl_init();

// Set request options
curl_setopt_array($request, array
(
  CURLOPT_URL => 'https://www.paypal.com/cgi-bin/webscr',
  CURLOPT_POST => TRUE,
  CURLOPT_POSTFIELDS => http_build_query(array
    (
      'cmd' => '_notify-synch',
      'tx' => $tx,
      'at' => 'paypal token',
    )),
  CURLOPT_RETURNTRANSFER => TRUE,
  CURLOPT_HEADER => FALSE,
  // CURLOPT_SSL_VERIFYPEER => TRUE,
  // CURLOPT_CAINFO => 'cacert.pem',
));

// Execute request and get response and status code
$response = curl_exec($request);
$status  = curl_getinfo($request, CURLINFO_HTTP_CODE);
echo $status;
// Close connection
curl_close($request);

if($status == '200' AND strpos($response, 'SUCCESS') === 0)
{
    $con = mysql_connect("host","database","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("loadport_e1072", $con);

$userid = USERID;
    mysql_query("INSERT INTO payments (userid, paypal, product, status)
VALUES ('".$userid."', '".$tx."','".$id."','1')");
header ("location: sendload.php?id=$tx");
echo"
<meta http-equiv='Refresh' content='1; URL=https://www.loadportal.net/online2/sendload.php?id=$tx' />
";
}

else {
    echo"
<meta http-equiv='Refresh' content='1; URL=https://www.loadportal.net/online2/error.php?id=4' />
";

}
}

?>
Avatar billede olsensweb.dk Ekspert
03. februar 2013 - 17:44 #10
prøv at læse #1 igen
læg mærke til linjen echo $status; i den første blå box. der er din header fejl, hvilke jeg også skriver lige under den blå box
Avatar billede techboy992 Praktikant
03. februar 2013 - 18:32 #11
Ja men den kom jo ikke fejl og mange tak for hurtig svar , kan du hjaelpe med mysqli insert code ron ??
Avatar billede olsensweb.dk Ekspert
03. februar 2013 - 18:59 #12
>Ja men den kom jo ikke fejl og
nej pga. du ikke havde slået fejl visning til ( error_reporting )

>kan du hjaelpe med mysqli insert code
(utested)
$sql = "INSERT INTO payments (userid, paypal, product, status) VALUES ('".$userid."', '".$tx."','".$id."','1')";


mysql_query($sql, $conn);

rettes til i Procedural style
mysqli_query($conn, $sql);

dvs førhen var database connection valgfri som parameter 2, nu er den et krav som parameter 1, bemærk der er byttet om på sql og conn fra den gamle mysql til det forbedret

den gamle http://php.net/mysql_query
det forbedret http://www.php.net/manual/en/mysqli.query.php

du kunne også vælge at bruge OOP tilgangen
$conn->query($sql);


et bedre alternativ efter min mening er at bruge PDO http://www.php.net/manual/en/pdo.query.php
$conn->query($sql);


du kan så forbedre din sikkerhed ved at bruge Prepared Statements 
læs denne guide http://www.eksperten.dk/guide/1480
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester