Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Przekazywanie zmiennych
Forum PHP.pl > Forum > PHP
qubec26
Mam taki kod:
  1. <?php
  2.  
  3. echo "<form name='form1' method='post' action=''>";
  4. echo "<strong>".$_SESSION['nazwa1']."</strong>";
  5. echo "<tr>";
  6. echo "<td><strong>ID</strong></td>";
  7. echo "<td><strong>Part number</strong></td>";
  8. echo "<td><strong>Quantity</strong></td>";
  9. echo "<td><strong>Planned date of delivery</strong></td>";
  10. echo "<td><strong>Supplier code</strong></td>";
  11. echo "<td><strong>Supplier name</strong></td>";
  12. echo "<td><strong>Order number</strong></td>";
  13. echo "<td><strong>Line number</strong></td>";
  14. echo "<td><strong>Date of delivery</strong></td>";
  15. echo "<td><strong>Quantity delivered</strong></td>";
  16. echo "<td><strong>Declare</strong></td>";
  17. echo "<td><strong>PRINT</strong></td>";
  18. echo "</tr>";
  19.  
  20. $k = 0; //Licznik kolorów na 0
  21. $i = 0; //ustawienie licznika na 0
  22. $_SESSION['url'] = array();
  23. while($r = mssql_fetch_assoc($result)) {
  24. include('kolor.php');
  25. echo "<tr bgcolor='$kolor'>";
  26. echo "<td>".$_SESSION['url'] = $r['ID']; $idec=$r['ID']; $r['ID']."</td>";
  27. echo "<td>".$nrdet[] = $r['NR_DET']; $r['NR_DET']."</td>";
  28. echo "<td>".$r['ILOSC']."</td>";
  29. echo "<td>".$r['PLAN_DATA_DOST']."</td>";
  30. echo "<td>".$r['KOD_DOSTAWCY']."</td>";
  31. echo "<td>".$r['NAZ_DOSTAWCY']."</td>";
  32. echo "<td>".$nrzam[] = $r['NR_ZAMOWIENIA']; $r['NR_ZAMOWIENIA']."</td>";
  33. echo "<td>".$nrlin[] = $r['NR_LINII']; $r['NR_LINII']."</td>";
  34. echo "<td>".$r['DATA_DOST']."</td>";
  35. echo "<td>".$r['ILOSC_DOSTAWY']."</td>";
  36.  
  37. if($r['DADI']<=14){
  38.  
  39. echo '<td class="backwhitetable"><input type="submit" value="Declare" name="Declare" onclick="window.open(\'declare.php?idec='.$idec.'\', \'Declare\', \'height=350,width=500\');"></td>';
  40. echo '<td class="backwhitetable"><input type="submit" value="SHIP" name="PRINT" onclick="window.open(\'printstick.php?'.$_session['url'].'\', \'Drukuj\', \'height=350,width=500\');"></td>';
  41.  
  42. }
  43. echo "</tr>";
  44. $i++; //licznik + 1
  45. }
  46. echo "</form>";
  47. echo "</table>";
  48. $count=mssql_num_rows($result);
  49.  
  50. mssql_close($dbhandle);
  51. ?>

I dwa przyciski w każdym wierszu (o ile spełniają założenia). - declare i print
Declare przekazuje jawnie w linku wartość idec - i działa dobrze:
  1. echo '<td class="backwhitetable"><input type="submit" value="Declare" name="Declare" onclick="window.open(\'declare.php?idec='.$idec.'\', \'Declare\', \'height=350,width=500\');"></td>';

Natomiast print nie działa dobrze - bo zawsze prezentuje wartość ostatniego wiersza:
  1. echo '<td class="backwhitetable"><input type="submit" value="SHIP" name="PRINT" onclick="window.open(\'printstick.php?'.$_session['url'].'\', \'Drukuj\', \'height=350,width=500\');"></td>';

Jeszcze tutaj plik printstick.php:
  1. <?php
  2. session_start($_GET['id']);
  3. require ('sess.php');
  4. require('fpdf.php');
  5. $gt = $_SESSION['url'];
  6. include ('connect.php');
  7. include ('query.php');
  8.  
  9. $pdf=new FPDF();
  10. $pdf->AddPage();
  11. $pdf->SetFont('Arial','B',10);
  12. $pdf->AddFont('code39','','code39.php');
  13.  
  14.  
  15. $result17 = mssql_query($query17);
  16. $result16 = mssql_query($query16);
  17. $r = mssql_fetch_assoc($result16);
  18. $pdf->Cell(50,8,'Zmienna gt: '.$gt,1);
  19. $pdf->Ln(8);
  20. $pdf->Cell(40,10,''.$_SESSION['nazwa1']);
  21. $pdf->Ln(8);
  22. $pdf->Cell(80,10,'Part number: '.$r['NR_DET'],1);
  23. $pdf->Cell(80,10,'Quantity: '.$r['ILOSC'],1);
  24. $pdf->Ln(10);
  25. $pdf->Cell(80,10,'Planned date of delivery: '.$r['PLAN_DATA_DOST'],1);
  26. $pdf->Cell(80,10,'Supplier code: '.$r['KOD_DOSTAWCY'],1);
  27. $pdf->Ln(10);
  28. $pdf->Cell(80,10,'Order number: '.$r['NR_ZAMOWIENIA'],1);
  29. $pdf->Cell(80,10,'Line number: '.$r['NR_LINII'],1);
  30. $pdf->Ln(10);
  31. $pdf->Cell(80,10,'Date of delivery: '.$r['DATA_DOST'],1);
  32. $pdf->Cell(80,10,'Quantity delivered: '.$r['DATA_DOST'],1);
  33. $pdf->Ln(10);
  34. $pdf->SetFont('code39','',40);
  35. $pdf->Cell(160,22,'*'.$r['CODE'].'*',1,0,'C');
  36. $pdf->Ln(20);
  37. $pdf->SetFont('Arial','',8);
  38. $pdf->Cell(80,10,'These messages are extremely important for our company.');
  39. $pdf->Ln(6);
  40. $pdf->Cell(80,10,'Print this email and publish on the shipment. This will help us work faster.');
  41. $pdf->Output();
  42.  
  43.  
  44. include('footer.php');
  45. ?>


Jak można zmienić ten kod aby zaczął działać poprawnie?
CuteOne
Popraw i sprawdź:


  1. echo '<td class="backwhitetable"><input type="submit" value="SHIP" name="PRINT" onclick="window.open(\'printstick.php?id='.$_SESSION['url'].'\', \'Drukuj\', \'height=350,width=500\');"></td>';
qubec26
Wszystko ok. Tylko znowu to jest jawne przekazanie w linku zmiennej id. A ja chcę zrobić to żeby było ukryte.

Może jakoś zaszyfrować tą zmienną?
CuteOne
Nie wiem czy zadziała ;p

  1.  
  2. <?php
  3.  
  4. echo "<form name='form1' method='post' action=''>
  5. <strong>".$_SESSION['nazwa1']."</strong>
  6. <tr>
  7. <td><strong>ID</strong></td>
  8. <td><strong>Part number</strong></td>
  9. <td><strong>Quantity</strong></td>
  10. <td><strong>Planned date of delivery</strong></td>
  11. <td><strong>Supplier code</strong></td>
  12. <td><strong>Supplier name</strong></td>
  13. <td><strong>Order number</strong></td>
  14. <td><strong>Line number</strong></td>
  15. <td><strong>Date of delivery</strong></td>
  16. <td><strong>Quantity delivered</strong></td>
  17. <td><strong>Declare</strong></td>
  18. <td><strong>PRINT</strong></td>
  19. </tr>";
  20.  
  21. $k = 0; //Licznik kolorów na 0
  22. $i = 0; //ustawienie licznika na 0
  23.  
  24. $_SESSION['url'] = array();
  25. while($r = mssql_fetch_assoc($result)) {
  26. include('kolor.php');
  27.  
  28. echo "<tr bgcolor='$kolor'>
  29. <td>".$_SESSION['url'][$i] = $r['ID']; $idec=$r['ID']; $r['ID']."</td>
  30. <td>".$nrdet[] = $r['NR_DET']; $r['NR_DET']."</td>
  31. <td>".$r['ILOSC']."</td>
  32. <td>".$r['PLAN_DATA_DOST']."</td>
  33. <td>".$r['KOD_DOSTAWCY']."</td>
  34. <td>".$r['NAZ_DOSTAWCY']."</td>
  35. <td>".$nrzam[] = $r['NR_ZAMOWIENIA']; $r['NR_ZAMOWIENIA']."</td>
  36. <td>".$nrlin[] = $r['NR_LINII']; $r['NR_LINII']."</td>
  37. <td>".$r['DATA_DOST']."</td>
  38. <td>".$r['ILOSC_DOSTAWY']."</td>";
  39.  
  40. if($r['DADI']<=14){
  41.  
  42. echo '<td class="backwhitetable"><input type="submit" value="Declare" name="Declare" onclick="window.open(\'declare.php?idec='.$idec.'\', \'Declare\', \'height=350,width=500\');"></td>
  43. <td class="backwhitetable"><input type="submit" value="SHIP" name="PRINT" onclick="window.open(\'printstick.php?id='.$i.'\', \'Drukuj\', \'height=350,width=500\');"></td>';
  44.  
  45. }
  46. echo "</tr>";
  47. $i++; //licznik + 1
  48. }
  49. echo "</form>
  50. </table>";
  51. $count=mssql_num_rows($result);
  52.  
  53. mssql_close($dbhandle);
  54. ?>


  1. $gt = $_SESSION['url'][$_GET['id']];


Usuń session_start($_GET['id']);
qubec26
Działa.
Tylko link wygląda:
http://localhost/printstick.php?id=5

więc jak zmienię sobie id to mogę wejść do któregokolwiek rekordu - jest jawnie.
piotr94
a nie możesz zapisywać tego ID w tablicy $_SESSION w pliku głównym i potem w pliku printstick.php odczytywać z tablicy $_SESSION to id??
qubec26
Mogę - tylko jest problem, że zawsze ta zmienna nadpisuje się aż do ostatniego wiersza.

Jak ją zapisać aby miała wartość wiersza, w którym kliknę print?
piotr94
racja, mój błąd...
moja propozycja jest taka:
1. tworzysz tablicę: $_SESSION['ids'][(tu wstawiasz losowy klucz, np. md5(microtime().rand(0,999999))]='id_w_bazie_danych';
2. w linku jako id podajesz wcześniej wstawiony losowy klucz
3. potem w oczywisty sposób odczytujesz biggrin.gif
ja bym tak zrobił jeśli chcesz to realizować tą metodą.
ew. przekazuj jawnie id, a potem sprawdzaj, czy danemu userowi można pokazać tę zawartość (czy jest jej autorem/czy ma do niej przyznany dostęp)
thek
A to wywołując print.php nie możesz sprawdzić uprawnień? To mus gdy przekazujesz dane poprzez POST lub GET. Jeśli to zrobisz to koleś może wpisywać cuda i modyfikować jak chce GET i POST a i tak serwer sprawdzi, czy daną rzecz może ów user zrobić. Podajesz jawnie parametry, a czy jest to możliwe dla danego usera serwer już sam zbada winksmiley.jpg
piotr94
thek, piszę o tym post wyżej w ostatniej linijce ;-)
qubec26
Zrobiłem cos taiego - według wskazań Piotra.
  1. <?php
  2.  
  3. echo "<form name='form1' method='post' action=''>";
  4. echo "<strong>".$_SESSION['nazwa1']."</strong>";
  5. echo "<tr>";
  6. echo "<td><strong>ID</strong></td>";
  7. echo "<td><strong>Part number</strong></td>";
  8. echo "<td><strong>Quantity</strong></td>";
  9. echo "<td><strong>Planned date of delivery</strong></td>";
  10. echo "<td><strong>Supplier code</strong></td>";
  11. echo "<td><strong>Supplier name</strong></td>";
  12. echo "<td><strong>Order number</strong></td>";
  13. echo "<td><strong>Line number</strong></td>";
  14. echo "<td><strong>Date of delivery</strong></td>";
  15. echo "<td><strong>Quantity delivered</strong></td>";
  16. echo "<td><strong>Declare</strong></td>";
  17. echo "<td><strong>PRINT</strong></td>";
  18. echo "</tr>";
  19.  
  20. $k = 0; //Licznik kolorów na 0
  21. $i = 0; //ustawienie licznika na 0
  22. $_SESSION['url'] = array();
  23. while($r = mssql_fetch_assoc($result)) {
  24. include('kolor.php');
  25. echo "<tr bgcolor='$kolor'>";
  26. $i=md5(microtime().rand(0,999999));
  27. echo "<td>". $_SESSION['url'][$i] = $r['ID']; $idec=$r['ID']; $r['ID']."</td>";
  28. echo "<td>".$nrdet[] = $r['NR_DET']; $r['NR_DET']."</td>";
  29. echo "<td>".$r['ILOSC']."</td>";
  30. echo "<td>".$r['PLAN_DATA_DOST']."</td>";
  31. echo "<td>".$r['KOD_DOSTAWCY']."</td>";
  32. echo "<td>".$r['NAZ_DOSTAWCY']."</td>";
  33. echo "<td>".$nrzam[] = $r['NR_ZAMOWIENIA']; $r['NR_ZAMOWIENIA']."</td>";
  34. echo "<td>".$nrlin[] = $r['NR_LINII']; $r['NR_LINII']."</td>";
  35. echo "<td>".$r['DATA_DOST']."</td>";
  36. echo "<td>".$r['ILOSC_DOSTAWY']."</td>";
  37.  
  38. if($r['DADI']<=14){
  39.  
  40. echo '<td class="backwhitetable"><input type="submit" value="Declare" name="Declare" onclick="window.open(\'declare.php?idec='.$idec.'\', \'Declare\', \'height=350,width=500\');"></td>';
  41. echo '<td class="backwhitetable"><input type="submit" value="SHIP" name="PRINT" onclick="window.open(\'printstick.php?id='.$i.'\', \'Drukuj\', \'height=500,width=700\');"></td>';
  42.  
  43. }
  44. echo "</tr>";
  45. $i++; //licznik + 1
  46. }
  47. echo "</form>";
  48. echo "</table>";
  49. $count=mssql_num_rows($result);
  50.  
  51. mssql_close($dbhandle);
  52. ?>

  1. <?php
  2. require ('sess.php');
  3. require('fpdf.php');
  4. $gt = $_SESSION['ids'][$_GET['id']];
  5. include ('connect.php');
  6. include ('query.php');
  7.  
  8. $pdf=new FPDF();
  9. $pdf->AddPage();
  10. $pdf->SetFont('Arial','B',10);
  11. $pdf->AddFont('code39','','code39.php');
  12.  
  13.  
  14. $result17 = mssql_query($query17);
  15. $result16 = mssql_query($query16);
  16. $r = mssql_fetch_assoc($result16);
  17. $pdf->Cell(50,8,'Zmienna gt: '.$gt,1);
  18. $pdf->Ln(8);
  19. $pdf->Cell(40,10,''.$_SESSION['nazwa1']);
  20. $pdf->Ln(8);
  21. $pdf->Cell(80,10,'Part number: '.$r['NR_DET'],1);
  22. $pdf->Cell(80,10,'Quantity: '.$r['ILOSC'],1);
  23. $pdf->Ln(10);
  24. $pdf->Cell(80,10,'Planned date of delivery: '.$r['PLAN_DATA_DOST'],1);
  25. $pdf->Cell(80,10,'Supplier code: '.$r['KOD_DOSTAWCY'],1);
  26. $pdf->Ln(10);
  27. $pdf->Cell(80,10,'Order number: '.$r['NR_ZAMOWIENIA'],1);
  28. $pdf->Cell(80,10,'Line number: '.$r['NR_LINII'],1);
  29. $pdf->Ln(10);
  30. $pdf->Cell(80,10,'Date of delivery: '.$r['DATA_DOST'],1);
  31. $pdf->Cell(80,10,'Quantity delivered: '.$r['DATA_DOST'],1);
  32. $pdf->Ln(10);
  33. $pdf->SetFont('code39','',40);
  34. $pdf->Cell(160,22,'*'.$r['CODE'].'*',1,0,'C');
  35. $pdf->Ln(20);
  36. $pdf->SetFont('Arial','',8);
  37. $pdf->Cell(80,10,'These messages are extremely important for our company.');
  38. $pdf->Ln(6);
  39. $pdf->Cell(80,10,'Print this email and publish on the shipment. This will help us work faster.');
  40. $pdf->Output();
  41.  
  42.  
  43. include('footer.php');
  44. ?>


Ale coś nie działa to tak jakbym chciał. ID jest źle przekazywane. I fatal error memory size mam często.
piotr94
po linijce 26 dodaj:
$_SESSION['url'][$i] = $r['ID'];
i uporządkuj echo w linijce 27 (nie wpisuj przypisań w echo, błagam...)
linijka 40 - wpisuj odpowiedni parametr $i, a nie $id
nie widzę zapytania do mysql - więc nie powiem Ci czy tam nie ma błędów
dalej
co do generowania pdf-ów to czasem niestety podczas ich tworzenia jest potrzebna większa pamięć ram (jeśli masz serwer wirtualny to to jest problem)
jeśli dalej coś nie działa to po prostu dawaj print_r($_SESSION); i sprawdzaj gdzie giną wartości.
i powtarzam jeszcze raz - lepszym sposobem jest przekazywanie id wprost, a potem kontrola, czy user ma prawa do oglądania tego rekordu
qubec26
Cytat
i powtarzam jeszcze raz - lepszym sposobem jest przekazywanie id wprost, a potem kontrola, czy user ma prawa do oglądania tego rekordu


A jak zrealizować coś takiego?

Chyba mam.

Zrobiłem sobie warunek w tym drugim pliku.
  1. <?php
  2. require ('sess.php');
  3. require('fpdf.php');
  4. $gt = $_SESSION['url'][$_GET['id']];
  5. include ('connect.php');
  6. include ('query.php');
  7.  
  8. $pdf=new FPDF();
  9. $pdf->AddPage();
  10. $pdf->SetFont('Arial','B',10);
  11. $pdf->AddFont('code39','','code39.php');
  12.  
  13.  
  14. $result17 = mssql_query($query17);
  15. $result16 = mssql_query($query16);
  16. $r = mssql_fetch_assoc($result16);
  17. if($r['DADI']<=14){
  18. // $pdf->Cell(40,8,'Zmienna i: '.$i,1);
  19. $pdf->Cell(50,8,'Zmienna gt: '.$gt,1);
  20. $pdf->Ln(8);
  21. $pdf->Cell(40,10,''.$_SESSION['nazwa1']);
  22. $pdf->Ln(8);
  23. $pdf->Cell(80,10,'Part number: '.$r['NR_DET'],1);
  24. $pdf->Cell(80,10,'Quantity: '.$r['ILOSC'],1);
  25. $pdf->Ln(10);
  26. $pdf->Cell(80,10,'Planned date of delivery: '.$r['PLAN_DATA_DOST'],1);
  27. $pdf->Cell(80,10,'Supplier code: '.$r['KOD_DOSTAWCY'],1);
  28. $pdf->Ln(10);
  29. $pdf->Cell(80,10,'Order number: '.$r['NR_ZAMOWIENIA'],1);
  30. $pdf->Cell(80,10,'Line number: '.$r['NR_LINII'],1);
  31. $pdf->Ln(10);
  32. $pdf->Cell(80,10,'Date of delivery: '.$r['DATA_DOST'],1);
  33. $pdf->Cell(80,10,'Quantity delivered: '.$r['DATA_DOST'],1);
  34. $pdf->Ln(10);
  35. // $pdf->Cell(160,10,'NP CODE: '.$r['CODE'],1,0,'C');
  36. $pdf->SetFont('code39','',40);
  37. $pdf->Cell(160,22,'*'.$r['CODE'].'*',1,0,'C');
  38. $pdf->Ln(20);
  39. $pdf->SetFont('Arial','',8);
  40. $pdf->Cell(80,10,'These messages are extremely important for our company.');
  41. $pdf->Ln(6);
  42. $pdf->Cell(80,10,'Print this email and publish on the shipment. This will help us work faster.');
  43. $pdf->Output();
  44. }
  45. else
  46. {
  47. $pdf->Cell(50,8,'You cannot yet deliver this item!');
  48. $pdf->Output();
  49. }
  50. include('footer.php');
  51. ?>


Działa.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.