Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
117
rated 0 times [  124] [ 7]  / answers: 1 / hits: 21411  / 10 Years ago, thu, november 6, 2014, 12:00:00

I wrote this little piece of code for viewing the profile pictures that are set as private. But every time I have to access it, I have to turn Apache on on XAMPP. Also, it is pretty much useless on a computer that doesn't have Apache installed. So I wanted to write it in JavaScript but couldn't find an equivalent for strstr() function.



Could someone please let me know if there's an equivalent or alternative?



The code:



<?php
//haystack
$_POST['theaddress'] ='160x160/photo.jpg';

//return all after the needle '160x160/', inclusive
$varA = strstr($_POST['theaddress'], '160x160/');

//build new URL
$varA = https://fbcdn-sphotos-g-a.akamaihd.net/hphotos-ak-ash3/t1.0-9.$varA;

header(Location: $varA);
?>

More From » php

 Answers
24

JavaScript String's indexOf() function should meet all your requests



Next example does in JavaScript almost same what you wrote in PHP. Keep in mind that you need to be sure that you have a way to pass $_POST['theaddress'] to your this function. (for example use PHP setcookie() function and then read value in JavaScript code



function reload(fileName) {
// define server address variable
var serverAddress = https://fbcdn-sphotos-g-a.akamaihd.net/hphotos-ak-ash3/t1.0-9;

// get the filename
var fileName = fileName.indexOf(160x160/);

// set new location based on server address and filename
location.href = serverAddress + fileName;
}

[#68894] Tuesday, November 4, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
daja

Total Points: 407
Total Questions: 103
Total Answers: 103

Location: Ghana
Member since Sun, Mar 27, 2022
2 Years ago
daja questions
Tue, Dec 21, 21, 00:00, 2 Years ago
Thu, Apr 23, 20, 00:00, 4 Years ago
Fri, Sep 6, 19, 00:00, 5 Years ago
Tue, Jul 23, 19, 00:00, 5 Years ago
;