Viewed   61 times

Here is the PHP documentation

Here is how I would use it in an Ajax call, if I don't find a pure client way to do this.

$homepage = file_get_contents('');
echo $homepage;

Is there way to do this client side instead so I don't have to ajax the string over?



you could do

JS code:

$.post('phppage.php', { url: url }, function(data) {
    document.getElementById('somediv').innerHTML = data;        

PHP code:

$url = $_POST['url'];
echo file_get_contents($url);

That would get you the contents of the url.

Tuesday, October 25, 2022

You can use the PHP imagestring() function to create an image.

// Create a 100*30 image
$im = imagecreate(120, 30);

// White background and blue text
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 255);

// Write the email address at the top left
imagestring($im, 5, 0, 0, '', $textcolor);

// Output the image
header('Content-type: image/png');

Monday, September 12, 2022

If you don't want to use javascript, you can handle it via php. Take a look at this lib: And then you could do something like:

include 'Mobile_Detect.php';
$detect = new Mobile_Detect();

if ($detect->isMobile()) {
    header('Location: yourpage.php');
Friday, October 21, 2022

Cookies are not the way to transfer variables between client and server. you should append key/variables pairs to your request URL using either a get (querystring) or post method.

jQuery ajax example;

$.get('' + NewCookieValue);
Monday, October 31, 2022

There's no definitive right way, because so many people are doing so many different things.. There are many useful patterns.

Crockford suggests that you "go with the grain", or write javascript in a way that corresponds to javascript's prototypal nature.

Of course, he goes on to show that the original model that Netscape suggested is actually broken. He labels it "pseudoclassical", and points out a lot of the misdirection and unnecessary complexity that is involved in following that model.

He wrote the "object" function as a remedy (now known as Object.create() ). It allows for some very powerful prototypal patterns.

It's not always easy to do develop a clean interface when you have to work with legacy javascript, especially not when you're dealing with large systems, usually including multiple libraries, and each implementing a unique style and different inheritance pattern. In general, I'd say that the "right way" to do inheritance is the one which allows you to write a clean interface which behaves well in the context of your legacy code, but also allows you to refactor and eliminate old dependencies over time.

Considering the differences between the major library patterns, I've found that the most successful route to take in my own work is to keep my interfaces independent of the library interfaces entirely. I'll use a library or module if it's helpful, but won't be bound to it. This has allowed me to refactor a lot of code, phase out some libraries, and use libraries as scaffolding which can be optimized later.

Along these lines, I've written interfaces that were inspired by Crockford's parasitic inheritance pattern. It's really a win for simplicity.

On the other side of the coin, I'm sure you could argue for picking a library, enforcing it across your team, and conforming to both its inheritance patterns and its interface conventions.

Sunday, September 25, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :