Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #5355 > unrolled thread

variable path lose slashs when used in an alert

Started bynawfer <novalidsforspam@alt.al>
First post2012-04-06 17:10 +0200
Last post2012-04-06 17:19 -0400
Articles 3 — 3 participants

Back to article view | Back to comp.lang.php


Contents

  variable path lose slashs when used in an alert nawfer <novalidsforspam@alt.al> - 2012-04-06 17:10 +0200
    Re: variable path lose slashs when used in an alert "Peter H. Coffin" <hellsop@ninehells.com> - 2012-04-06 10:42 -0500
    Re: variable path lose slashs when used in an alert Richard Damon <news.x.richarddamon@xoxy.net> - 2012-04-06 17:19 -0400

#5355 — variable path lose slashs when used in an alert

Fromnawfer <novalidsforspam@alt.al>
Date2012-04-06 17:10 +0200
Subjectvariable path lose slashs when used in an alert
Message-ID<13h77x0s1h9s8$.1u35g6a12svpi.dlg@40tude.net>
variable $temp is a path
C:\www\site\test\folder\img.jpg

if I write 
echo $temp;
ok I have all the path
---------

but if I use same variable in an alert I haven't more the correct path;
haven't the \ slashs

echo"<script type='text/javascript'>";
echo "alert('$temp')";
echo "</script>"; 

I tested also string but is equal
$temp=(string)$temp;


is there a solution?

[toc] | [next] | [standalone]


#5358

From"Peter H. Coffin" <hellsop@ninehells.com>
Date2012-04-06 10:42 -0500
Message-ID<slrnjnu3ng.4ci.hellsop@nibelheim.ninehells.com>
In reply to#5355
On Fri, 6 Apr 2012 17:10:18 +0200, nawfer wrote:
> variable $temp is a path
> C:\www\site\test\folder\img.jpg
>
> if I write 
> echo $temp;
> ok I have all the path
> ---------
>
> but if I use same variable in an alert I haven't more the correct path;
> haven't the \ slashs
>
> echo"<script type='text/javascript'>";
> echo "alert('$temp')";
> echo "</script>"; 
>
> I tested also string but is equal
> $temp=(string)$temp;
>
>
> is there a solution?

read and understand http://php.net/manual/en/language.types.string.php
especially the part where different quotes make interpretation
different.

-- 
It's not hard, it's just asking for a visit by the fuckup fairy.
              -- Peter da Silva

[toc] | [prev] | [next] | [standalone]


#5361

FromRichard Damon <news.x.richarddamon@xoxy.net>
Date2012-04-06 17:19 -0400
Message-ID<jlnmk9$j1d$1@dont-email.me>
In reply to#5355
On 4/6/12 11:10 AM, nawfer wrote:
> variable $temp is a path
> C:\www\site\test\folder\img.jpg
> 
> if I write 
> echo $temp;
> ok I have all the path
> ---------
> 
> but if I use same variable in an alert I haven't more the correct path;
> haven't the \ slashs
> 
> echo"<script type='text/javascript'>";
> echo "alert('$temp')";
> echo "</script>"; 
> 
> I tested also string but is equal
> $temp=(string)$temp;
> 
> 
> is there a solution?

If you look at the source of the page, you should see the slashes. The
problem is that with

alert('C:\www\site\test\folder\img.jpg')

the javascript interpreter will see each of the slashes in it as an
escape sequence with the following character. You therefore need to
"escape" your string so as to pass properly through the javascript
processor. This would need things like \ going to \\ and ' to \'

Anytime you send a variable out to something that will interpret it, you
need to think about the need to run the data through and escape
processor, be it sql query, javascript code, or even just out as a web
page. (For instance

$foo = "John & Mary";
or
$for = "1 < 2";

echo $foo;

will generate an incorrect page, as & and < have special meaning in HTML.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web