Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Proste pytanie - zatrzymanie skryptu +include
grezliq
post
Post #1





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 7.08.2011

Ostrzeżenie: (0%)
-----


Witam,
skrypt wyglada nastepujaco:

  1. <?
  2. include("config.php");
  3. if (strstr($_SERVER['HTTP_REFERER'], $root));
  4. else { header ("Location: $rooturl"); }
  5.  
  6. $ip = $_SERVER['REMOTE_ADDR'];
  7. $url = mysql_real_escape_string($_POST['url']);
  8.  
  9. if(preg_match('|^http(s)?://[a-z0-9-]+(\.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url)) {
  10. if (empty($_POST['tag'])) {
  11. $query = mysql_query("INSERT INTO $table (ip,url) VALUES ('$ip','$url')") or die('MySQL error: '.mysql_error());
  12. $qs = mysql_insert_id();
  13. } else {
  14. if (ereg('^[a-zA-Z0-9]+[a-zA-Z0-9]+$', $_POST['tag'])) {
  15. $tag = mysql_real_escape_string($_POST['tag']);
  16. $query = mysql_query("select * from $table where `tag` = '$tag';") or die('MySQL error: '.mysql_error());
  17. if (mysql_num_rows($query) != 0)
  18. die("This tag has already been used! Please press back button on your browser and choose another tag!");
  19. else {
  20. $query = mysql_query("insert $table (ip,url,tag) VALUES ('$ip','$url','$tag')") or die('MySQL error: '.mysql_error());
  21. $qs = $tag;
  22. }
  23. } else
  24. die('Your tag contains invalid characters! Only alphabets and numbers allowed! Please press back button on your browser and choose another tag!');
  25. }
  26. $link = $destination . $qs;
  27. require 'create_template.php';
  28. } else
  29. echo 'URL is invalid';
  30.  
  31. ?>



Kiedy zamiast
  1. die("This tag has already been used! Please press back button on your browser and choose another tag!");
wpisuję
  1. include("index3.php"); (tutaj jest strona z błędem)


skrypt sie nie zatrzymuje (no bo nie ma 'die'), i pod index3 pokazuje sie i tak strona z wygenerowanym linkiem, tzn nie jest on wygenerowany bo tag jest zajety ale pokazuje sie create_template.php

jak połączyc die i include zeby skrypt sie zatrzymał i wyswietlil mi index3.php z błedem?

i jak zrobić aby gdy jedno z dwóch pól pozostanie puste, skrypt sie zatrzyma i pokaze np. index2.php?
bo na chwilę obecna, kiedy uzupelnie pierwsze pole, a drugie zostanie puste, skrypt sam je dopisze.

Wiem, że to pewnie podstawy, szukałem ale nie znalazlem, prosze o pomoc (IMG:style_emoticons/default/smile.gif)


Go to the top of the page
+Quote Post
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 561
Pomógł: 6315
Dołączył: 27.12.2004




Problem z mysql ma średni związek by nie powiedzieć że żaden.

Przenoszę na przedszkole.
Go to the top of the page
+Quote Post
Daiquiri
post
Post #3





Grupa: Administratorzy
Postów: 1 552
Pomógł: 211
Dołączył: 7.07.2009
Skąd: NJ




Nie wiem czy dobrze Cię rozumiem... ale możesz przecież die() dać w index3. Albo dodać klamry w warunku (bo z tego co widzę - nie masz) i po include() dać die();
Go to the top of the page
+Quote Post
grezliq
post
Post #4





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 7.08.2011

Ostrzeżenie: (0%)
-----


a mógłbym Ciebie prosić zebyś mi to wrzucił w kod?
Go to the top of the page
+Quote Post
foxbond
post
Post #5





Grupa: Zarejestrowani
Postów: 162
Pomógł: 12
Dołączył: 20.12.2009
Skąd: Siedlce

Ostrzeżenie: (0%)
-----


Jeśli dobrze rozumiem to daj exit; za tym include


  1. <?
  2. include("config.php");
  3. if (strstr($_SERVER['HTTP_REFERER'], $root));
  4. else { header ("Location: $rooturl"); }
  5.  
  6. $ip = $_SERVER['REMOTE_ADDR'];
  7. $url = mysql_real_escape_string($_POST['url']);
  8.  
  9. if(preg_match('|^http(s)?://[a-z0-9-]+(\.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url)) {
  10. if (empty($_POST['tag'])) {
  11. $query = mysql_query("INSERT INTO $table (ip,url) VALUES ('$ip','$url')") or die('MySQL error: '.mysql_error());
  12. $qs = mysql_insert_id();
  13. } else {
  14. if (ereg('^[a-zA-Z0-9]+[a-zA-Z0-9]+$', $_POST['tag'])) {
  15. $tag = mysql_real_escape_string($_POST['tag']);
  16. $query = mysql_query("select * from $table where `tag` = '$tag';") or die('MySQL error: '.mysql_error());
  17. if (mysql_num_rows($query) != 0)
  18. include("index3.php"); exit;
  19. else {
  20. $query = mysql_query("insert $table (ip,url,tag) VALUES ('$ip','$url','$tag')") or die('MySQL error: '.mysql_error());
  21. $qs = $tag;
  22. }
  23. } else
  24. die('Your tag contains invalid characters! Only alphabets and numbers allowed! Please press back button on your browser and choose another tag!');
  25. }
  26. $link = $destination . $qs;
  27. require 'create_template.php';
  28. } else
  29. echo 'URL is invalid';
  30.  
  31. ?>


Ten post edytował foxbond 1.09.2011, 12:54:42
Go to the top of the page
+Quote Post
grezliq
post
Post #6





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 7.08.2011

Ostrzeżenie: (0%)
-----


Parse error: syntax error, unexpected T_ELSE on line 19

ok panowie, problem rozwiazany w ten sposób:

na koncu index3.php:

Kod
<?php

die()

?>


i gra (IMG:style_emoticons/default/smile.gif)
dzieki i pozdrawiam

Ten post edytował grezliq 1.09.2011, 13:27:18
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 23.12.2025 - 11:10