Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

PHP few questions


ghost's Avatar
0 0

i have few questions to php: first of all, i have a website powered by php. i'm using a file header.php, which contains the html header, title etc. also i have file index.php, which contains a basic content of page. i simply use markupinclude("include/header.php"); to include header.php into index.php but my problem is that as some people here know, i am from czech republic. we are using in our language some special characters as "é,í…" etc. when i had this characters in index.php, everything was ok. but when i'll try to include that header, these chars in that header are replaced with "?", so i have for example in title replaced this characters with "?" i think i have to change charset, but how? and where? in index.php is everything ok, it doesnt work only in includes. default charset is i think utf-8, czech charset is cp-1250, how can i change it? second question, how can i use php to read some specific text on the page? i dont need all the page, i need only a specific text on it, and save it to a variable. how can i do this? thanks in advance for any help.


ghost's Avatar
0 0

at the top of every page, before any output: header("Content-Type: text/html; charset=<charset here>");


ghost's Avatar
0 0

thanks both of you, one problem is solved. as for your question, FireSaleHaxor, yes i've already looked at www.php.net


ghost's Avatar
0 0

dancuc wrote: thanks both of you, one problem is solved. as for your question, FireSaleHaxor, yes i've already looked at www.php.net

dancuc, i really like ur avatar. mind if i steal it? :D

(see im nice, im asking first)

:P


ghost's Avatar
0 0

you can select certain text from a page using file_get_contents() or a fsockopen HTTP request, then with the page contents do a preg_match() with regexp


ghost's Avatar
0 0

yes, do it SilverHacker :p its not work of mine, so i cant say anything to you :D anyway thanks all for help ;) btw… i like my avatar too


ghost's Avatar
0 0

oh, theres a slight problem, after adding: markupheader(&quot;Content-Type: text/html; charset=cp1250&quot;); at the top of every page, header is now readable, but content of index.php remains with "?"


ghost's Avatar
0 0

solved ;) but i have last question for this thread: i'm using if/else statements, like this example:

if(empty($id) || $id == &quot;main&quot;)
{```
but i have it on index. when i load page, index will be loaded. but when the index is loaded, there is no index.php?id=, there is ony index.php, and i am getting error Notice: Undefined index: id in *** index.php on line 1027
how can i solve thisQ? 

ghost's Avatar
0 0

try isset instead of empty. also, SANITIZE YOUR VARIABLES!!!!


ghost's Avatar
0 0

biggnick wrote: try isset instead of empty. doesn't working. now i am getting only that error, with empty i've got error, then rest of page, now with isset only error, menu and header, which aren't in a condition.


ghost's Avatar
0 0

Try the isset() on the GET variable instead of the variable you're assigning the GET value to. Also, being able to see more of the source wouldn't hurt.


ghost's Avatar
0 0

ok here i am sending shorter source:

include(&quot;/include/header.php&quot;);
echo&quot;&lt;div id=&#92;&quot;menu&#92;&quot;&gt;
&lt;ul id=&#92;&quot;mainMenu&#92;&quot;&gt;//short version of menu
&lt;li&gt;&lt;a href=&#92;&quot;index.php?id=vysledky_07-08&#92;&quot;&gt;some content&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;&#92;n&quot;;
$id = $_GET[&#39;id&#39;];
if(empty($id) || $id == &quot;uvod&quot;)
{
echo&quot;&lt;div id=&#92;&quot;content&#92;&quot;&gt;//short version of content
&lt;h1 class=&#92;&quot;class1&#92;&quot;&gt;some content&lt;/h1&gt;
&lt;img class=&#92;&quot;class2&#92;&quot; src=&#92;&quot;images/value.jpg&#92;&quot; alt=&#92;&quot;&#92;&quot; /&gt;
&lt;h2 class=&#92;&quot;class3&#92;&quot;&gt;some content&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;some content&lt;/li&gt;
&lt;li&gt;some content&lt;/li&gt;
&lt;/ul&gt;
&lt;div id=&#92;&quot;footer&#92;&quot;&gt;
&lt;p&gt;Copyright © 2007 dancuc&lt;/p&gt;
&lt;/div&gt;

&lt;/div&gt;&#92;n&quot;;
}

echo&quot;&lt;/body&gt;
&lt;/html&gt;&#92;n&quot;;
?&gt;```
i have included header, menu i have in index.php, then is checked status of &quot;id&quot; and depending on this is showed main content

ghost's Avatar
0 0

Did you even try my suggestion yet?


spyware's Avatar
Banned
0 0

Zephyr_Pure wrote: Did you even try my suggestion yet?

You mean you don't know yet? It's "Give great advice to people who cannot solve their own easy problem and they won't even use your suggestions"-day.

Thought everyone knew.


ghost's Avatar
0 0

spyware wrote: You mean you don't know yet? It's "Give great advice to people who cannot solve their own easy problem and they won't even use your suggestions"-day.

Thought everyone knew.

Oh, that's right… that is today, isn't it? So, where's my present? :happy:


ghost's Avatar
0 0

Zephyr_Pure wrote: Did you even try my suggestion yet? yes i do


ghost's Avatar
0 0

Zephyr_Pure wrote: Did you even try my suggestion yet? dancuc wrote: yes i do

The source you posted doesn't reflect that. :)


ghost's Avatar
0 0

it's old version of source. i returned to old version because it not worked.


ghost's Avatar
0 0

dancuc wrote: it's old version of source. i returned to old version because it not worked.

Well, post the relevant part of your source after the change I suggested, and include the error that you get when you use that change.


ghost's Avatar
0 0

i am posting only critical part of source:

{
if(empty($id) || $id == &quot;uvod&quot;)
{
***```
to the error, nothing. it wont show anything, instead of menu and header, which aren&#39;t in condition.

spyware's Avatar
Banned
0 0

The error lies not within the code but within the logic applied in the coder. Your code has a flaw, not an error. Rethink what you are doing/trying to do.


ghost's Avatar
0 0

i've tryed lots of things before i posted here. i've tryed relocating the variables and condition, but nothing worked.


spyware's Avatar
Banned
0 0

dancuc wrote: i've tryed lots of things before i posted here. i've tryed relocating the variables and condition, but nothing worked.

I can only fix your script if you display the full source. Save it as phps and show me.


ghost's Avatar
0 0

dancuc wrote:

{
if(empty($id) || $id == &quot;uvod&quot;)
{
***```


Well, it looks as if you&#39;ve broken your code again by trying my **change**.  Re-read my previous post suggesting the **change**, and you should see the paramount mistake you **added**.

> **dancuc wrote:**
i&#39;ve tryed lots of things before i posted here. i&#39;ve tryed relocating the variables and condition, but nothing worked. 

You&#39;re not thinking about how your conditional is supposed to be working.  Write it down on paper in pseudocode before you toss it into a file.

ghost's Avatar
0 0

Zephyr_Pure: sorry, i didnt comprehended you correctly spyware: will i have to send it here? or where?


spyware's Avatar
Banned
0 0

Just post it here. (disable smilies or burn in eternal flames)


ghost's Avatar
0 0

here you have, its in czech so sorry if some characters are unreadable

echo&quot;***&#92;n&quot;;
	$id = $_GET[&#39;id&#39;];
	if(empty($id) || $id == &quot;uvod&quot;)
	{
	echo&quot;***&#92;n&quot;;
}

echo&quot;***&#92;n&quot;;
?&gt;```

spyware's Avatar
Banned
0 0

Okay. Remove_your_freaking_html_NOW!


ghost's Avatar
0 0

eh? i'm not sure if i understand you. what you mean?


spyware's Avatar
Banned
0 0

You showed us html. I don't care about the html. Show me the PHP. Why do you even echo your html? You can use inline html/php.


ghost's Avatar
0 0

ok, sorry. i edited my post. it should be fine now


spyware's Avatar
Banned
0 0

dancuc wrote: here you have, its in czech so sorry if some characters are unreadable

echo&quot;***&#92;n&quot;;
	$id = $_GET[&#39;id&#39;];
	if(empty($id) || $id == &quot;uvod&quot;)
	{
	echo&quot;***&#92;n&quot;;
}

echo&quot;***&#92;n&quot;;
?&gt;```

Dude..

Seriously, read that IF statement and scratch the back of your head. That will never ever work. 

EDIT: Just read through the whole thread again, noticed someone already gave you the answer. 

ghost's Avatar
0 0

ok, i probably know who it is. but it didnt worked… maybe i writed it wrong. so in this way, what's the right syntax?


ghost's Avatar
0 0

ok, i've got it, i feel little stupid… thanks all for their help


ghost's Avatar
0 0

dancuc wrote: ok, i've got it, i feel little stupid… thanks all for their help

Since you discovered the answer, why not post what the solution was (with the abbreviated source) so that others can have the answer available in the forum? :)


ghost's Avatar
0 0

yes, you are right Zephyr, i'm posting a fully commented source:

if(!isset($_GET[&#39;id&#39;]) || empty($_GET[&#39;id&#39;])){ //i&#39;ve decided to not copy $_GET[&#39;id&#39;] into a variable id, and work only with $_GET[&#39;id&#39;]
$_GET[&#39;id&#39;] = &#39;uvod&#39;;
}
echo&quot;***&#92;n&quot;; //some echoed html...
if(empty($_GET[&#39;id&#39;]) || $_GET[&#39;id&#39;] == &quot;uvod&quot;) //if the id is empty, or if id equals to &quot;uvod&quot;
{
echo&quot;***&#92;n&quot;; //some text
}
else if($_GET[&#39;id&#39;] == &quot;blahblah&quot;) //can be used for other conditions
{}
?&gt;```
i hope this will help to the others, which are having problems with this. its not that hard, as it look
anyway, again thanks to all for help

ghost's Avatar
0 0

Good job. As a slightly more efficient way to do it, you could do this:

&lt;?php
$id = &#39;&#39;;

if (isset($_GET[&#39;id&#39;]))
{
    $id = $_GET[&#39;id&#39;];
}

if ($id == &quot;&quot;) || ($id == &quot;uvod&quot;)
{
//do stuff
}
?&gt;

Basically, you can give $id the default value of ''. Then, if the GET variable is set, it will update $id with the value. Finally, you'll test for an empty string or the actual string you're looking for, then go for it.

Oh, and as mentioned earlier… don't forget to sanitize your GET variables. Also, you don't have to echo all of your HTML like that… just use PHP tags in between the standard HTML on your page.

Edit: I still, and always will, hate smilies. Thanks, Spy. lol

:);):|:(:o:pB):D:@:angry::happy::ninja::xx::radio::whoa::wow::vamp::right::love::matey::evil: - Spy


ghost's Avatar
0 0

yes, thanks, this is more efficient way, i rewrited it :) btw… must be .htaccess enabled in apache? since i need to deny access to some folders, so i've added line deny from all, but i still can see the content of a directory. password protection via .htaccess isn't working