-
Notifications
You must be signed in to change notification settings - Fork 0
/
url-validate.php
150 lines (120 loc) · 3.35 KB
/
url-validate.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
define("ROOT", __DIR__);
$url = $_SERVER['REQUEST_URI'];
//path to directory to scan
$directory = "xml/";
//get all image files with a .txt extension.
$dir = ROOT."\*.xml";
//print_r($file = glob($dir));
$file = glob($dir);
//var_dump($file);
// get isbn
$isbn=$_POST['isbn'];
$url = "http://".$isbn;
/*
if (!filter_var($isbn, FILTER_VALIDATE_URL) === false)
{
echo("$isbn is a valid URL");
return false;
}
else
{
echo("$isbn is not a valid URL");
return false;
}
*/
//$length=strlen($fullfilename); //gets the length of the full filename so you can tell substr when to stop
//$filewithoutextension = substr($isbn,0,$isbn-4);
$frontWords = substr($isbn,0,$isbn+3); // get the end three words only that is com only.
//echo $frontWords;
$endWords = substr($isbn,-3,$isbn+3);
$twoEndWords = substr($isbn,-2,$isbn+2);
//echo $endWords;
if($frontWords == "" && $endWords == "" && $twoEndWords == "")
{
echo "<div class='alert alert-warning'><strong>The url must not empty.</strong></div>";
}
elseif($frontWords == "www" && $endWords == "com" || $twoEndWords == "cz" || $twoEndWords == "uk" || $twoEndWords == "in")
{
echo "<div class='alert alert-primary'><strong>Website $url is validated.</strong></div>";
//echo $url;
//header("location: $url");
//header("location: http://".$isbn);
//die();
//echo $isbn;
}
else
{
echo "<div class='alert alert-danger'><strong>Website $url is NOT validated.</strong></div>";
}
/*
//print each file name
foreach($file as $filew)
{
$response=simplexml_load_file($filew);
$data = $response->BookList->BookData;
//var_dump($data);
$isbn10 = $data['isbn'];
$isbn13 = $data['isbn13'];
$bookTitle = $data->Title;
$bookLong = $data->TitleLong;
$bookAuthor = $data->AuthorsText;
$bookPublisher = $data->PublisherText;
$bookEdition = $data->Details['edition_info'];
$bookLanguage = $data->Details['language'];
$bookPhysicalDesc = $data->Details['physical_description_text'];
// check if we got at least one result
if($isbn == $isbn10 || $isbn == $isbn13 && $isbn != "")
{
echo
"<table class='table table-striped table-bordered'>
<tr>
<th>Short Title: </th>
<td>{$bookTitle}</td>
</tr>
<tr>
<th>Long Title: </th>
<td>{$bookLong} </td>
</tr>
<tr>
<th>Author(s): </th>
<td>{$bookAuthor}</td>
</tr>
<tr>
<th>Publisher: </th>
<td>{$bookPublisher}</td>
</tr>
<tr>
<th>ISBN10: </th>
<td>{$isbn10}</td>
</tr>
<tr>
<th>ISBN13: </th>
<td>$isbn13</td>
</tr>
<tr>
<th>Edition Information: </th>
<td>{$bookEdition}</td>
</tr>
<tr>
<th>Language: </th>
<td>{$bookLanguage}</td>
</tr>
<tr>
<th>Physical Description: </th>
<td>{$bookPhysicalDesc}</td>
</tr>
</table>";
return false;
}
}
if($isbn == "")
{
echo '<div class="alert alert-danger"><strong>Please ISBN no must not Empty</strong></div>';
}
elseif($isbn !== $isbn10 || $isbn !== $isbn13 && $isbn !== "")
{
echo '<div class="alert alert-warning"><strong>No book was found with ISBN: '.$isbn. '</strong></div>';
}
*/
?>